-
Notifications
You must be signed in to change notification settings - Fork 2
219 lines (196 loc) · 8.21 KB
/
Copy pathhelm-diff.yaml
File metadata and controls
219 lines (196 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Helm Render Diff
# Informational: renders every test-values scenario on both the PR base and head,
# diffs the resulting Kubernetes manifests, and posts a sticky PR comment so
# reviewers can see exactly what a change does to the rendered output.
#
# This ports the diff/report logic from comet-ml/gha-tools helm/helm-diff, but
# runs self-contained on GitHub-hosted runners with public actions — that private
# action runs on the self-hosted `helm` runner and can't be used from a public
# repo (fork PRs can't pull a private action, and self-hosted runners must not run
# fork code). Never fails the PR (the hard gate is lint-render.yaml).
on:
pull_request:
branches:
- main
permissions:
contents: read
pull-requests: write
issues: write
env:
KUBE_VERSION: "1.29.0"
CHART_PATH: charts/s3proxy
# Match gha-tools helm-diff defaults so output is consistent with our other charts.
RELEASE_NAME: release
NAMESPACE: default
jobs:
render-diff:
runs-on: ubuntu-latest
steps:
- name: Checkout PR head
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha }}
path: pr-repo
- name: Checkout base
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base-repo
- name: Set up Helm
uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1
with:
version: v3.19.2
- name: Render and diff
run: |
set -uo pipefail
# render <repo-dir> <values-relpath> <out-file>
# Renders the chart if both the chart dir and the values file exist on
# that side; otherwise writes an empty baseline (mirrors gha-tools, so a
# values file that only exists on the PR shows up as fully added).
render() {
local dir="$1" vals="$2" out="$3"
if [ -f "${dir}/${vals}" ] && [ -d "${dir}/${CHART_PATH}" ]
then
if ! helm template "${RELEASE_NAME}" "${dir}/${CHART_PATH}" \
--namespace "${NAMESPACE}" \
--values "${dir}/${vals}" \
--kube-version "${KUBE_VERSION}" > "$out" 2>"${out}.err"
then
echo "⚠️ render error for ${dir}/${vals}:"
cat "${out}.err"
: > "$out"
fi
else
: > "$out"
fi
}
RUN_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
COMMENT_LIMIT=60000
# Union of scenario files across base and head, so a scenario removed in
# the PR (present on base, absent on head) still shows up as a deletion.
names="$(
{ ls -1 pr-repo/test-values/*.yaml base-repo/test-values/*.yaml 2>/dev/null || true; } \
| xargs -r -n1 basename | sort -u
)"
# Two parts: a summary table (always small) and the detailed diffs.
table=/tmp/table.md
details=/tmp/details.md
{
echo "<!-- helm-render-diff -->"
echo "## 📊 Helm Render Diff Summary"
echo ""
echo "Chart \`${CHART_PATH}\` rendered with Kubernetes \`${KUBE_VERSION}\`. Informational only — this check never fails the PR."
echo ""
echo "| Values File | Chart Path | Changes | Status |"
echo "|-------------|------------|---------|--------|"
} > "$table"
echo "## 🔍 Detailed Changes" > "$details"
any_changes=0
while IFS= read -r name
do
[ -n "$name" ] || continue
render pr-repo "test-values/${name}" "/tmp/after-${name}"
render base-repo "test-values/${name}" "/tmp/before-${name}"
diff -u "/tmp/before-${name}" "/tmp/after-${name}" > "/tmp/diff-${name}" || true
if [ -s "/tmp/diff-${name}" ]
then
any_changes=1
# Additions/deletions, excluding the +++/--- file headers (as gha-tools does).
additions=$(grep '^+' "/tmp/diff-${name}" | grep -vc '^+++' || true)
deletions=$(grep '^-' "/tmp/diff-${name}" | grep -vc '^---' || true)
echo "| \`test-values/${name}\` | \`${CHART_PATH}\` | +${additions} -${deletions} | 🔄 **Changes Detected** ([summary](${RUN_URL})) |" >> "$table"
{
echo ""
echo "### 📝 Changes in \`${CHART_PATH}\` with \`test-values/${name}\`"
echo ""
echo "<details><summary>🔍 Click to view complete diff</summary>"
echo ""
echo '```diff'
cat "/tmp/diff-${name}"
echo '```'
echo ""
echo "</details>"
} >> "$details"
else
echo "| \`test-values/${name}\` | \`${CHART_PATH}\` | - | ✅ No Changes |" >> "$table"
fi
done <<< "$names"
if [ "$any_changes" -eq 0 ]
then
{
echo ""
echo "### 🎉 No changes detected in any of the tested configurations!"
} >> "$table"
fi
# Full report (table + detailed diffs) always goes to the job summary.
cat "$table" >> "$GITHUB_STEP_SUMMARY"
if [ "$any_changes" -eq 1 ]
then
{
echo ""
echo "---"
echo ""
cat "$details"
} >> "$GITHUB_STEP_SUMMARY"
fi
# PR comment: table + inline diffs when it fits, otherwise a slimmed
# table-only comment linking to the full diffs in the job summary
# (mirrors the self-hosted chart's behaviour on large diffs).
{
cat "$table"
if [ "$any_changes" -eq 1 ]
then
echo ""
echo "---"
echo ""
cat "$details"
fi
} > /tmp/comment-full.md
if [ "$(wc -c < /tmp/comment-full.md)" -le "$COMMENT_LIMIT" ]
then
cp /tmp/comment-full.md diff-comment.md
else
{
cat "$table"
echo ""
echo "---"
echo ""
echo "> ℹ️ Per-scenario diffs are omitted from this comment because the full render diff exceeds GitHub's comment size limit. See the complete diffs in the [workflow job summary](${RUN_URL})."
} > diff-comment.md
fi
# Match the repo's preview-readme.yaml convention: minimize (collapse) any
# previous render-diff comments as OUTDATED, then post a fresh one. Uses
# first-party actions/github-script (no third-party comment action).
# continue-on-error: fork PRs get a read-only token and cannot comment; the
# full diff is still available in the job summary.
- name: Minimize outdated diff comments and post the latest
continue-on-error: true
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const fs = require('fs');
const marker = '<!-- helm-render-diff -->';
const body = fs.readFileSync('diff-comment.md', 'utf8');
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
for (const comment of comments) {
if (comment.user.type === 'Bot' && comment.body.includes(marker)) {
await github.graphql(
`mutation($id: ID!) {
minimizeComment(input: { subjectId: $id, classifier: OUTDATED }) {
clientMutationId
}
}`,
{ id: comment.node_id },
);
}
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});