-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (165 loc) · 7.26 KB
/
Copy pathhelm-render-diff.yaml
File metadata and controls
180 lines (165 loc) · 7.26 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
name: Compare Helm Rendering
on:
workflow_call: {}
env:
dyff_ver: "1.7.1"
helm_ver: "3.11.1"
permissions: {}
jobs:
# This job is for checking for the `/no_diffs_printing` comment in the PR. When it is found,
# the `get-rendering-values` job is skipped, what makes `cmp-helm-rendering` skipped as well.
check-cmp-state:
runs-on: ubuntu-24.04
permissions:
pull-requests: read
if: github.event_name == 'pull_request'
steps:
- name: Find suspend comment
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0
continue-on-error: true
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
body-regex: '^\s*/no_diffs_printing' # on a separate line, not as Markdown `<!-- /no_diffs_printing -->` comment
- name: Find suspend comment in PR body # PR body isn't a comment, so the above step won't find it
id: pr_body
run: |
if jq -r .pull_request.body "${GITHUB_EVENT_PATH}" | grep -qE '^\s*/no_diffs_printing'; then
echo "Found /no_diffs_printing command in PR body"
echo "suspend_diffs_printing_from_pr_body=true" >> $GITHUB_OUTPUT
else
echo "Did not find /no_diffs_printing command in PR body"
echo "suspend_diffs_printing_from_pr_body=false" >> $GITHUB_OUTPUT
fi
outputs:
suspend_comment_id: ${{ steps.fc.outputs.comment-id }}
suspend_diffs_printing_from_pr_body: ${{ steps.pr_body.outputs.suspend_diffs_printing_from_pr_body }}
cmp-helm-rendering:
needs: check-cmp-state
runs-on: ubuntu-24.04
permissions:
contents: read
pull-requests: write
if: github.event_name == 'pull_request' && needs.check-cmp-state.outputs.suspend_comment_id == 0 && needs.check-cmp-state.outputs.suspend_diffs_printing_from_pr_body == 'false'
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: install helm
uses: azure/setup-helm@dda3372f752e03dde6b3237bc9431cdc2f7a02a2 # v5.0.0
with:
version: ${{ env.helm_ver }}
- run: which helm
- name: install dyff
uses: giantswarm/install-binary-action@5bef88f65012037dd836117c8d344b21bb559854 # v4.1.0
with:
binary: dyff
download_url: "https://github.com/homeport/dyff/releases/download/v${version}/dyff_${version}_linux_amd64.tar.gz"
smoke_test: "${binary} version"
tarball_binary_path: "${binary}"
version: ${{ env.dyff_ver }}
- run: which dyff
- run: ls -la /opt/hostedtoolcache
- name: render helm with current code
run: |
helm repo add cluster-catalog https://giantswarm.github.io/cluster-catalog/
# We also add cluster-test-catalog so we can more easily test dev builds of subcharts.
# Charts from cluster-test-catalog should be used only for testing purposes.
helm repo add cluster-test-catalog https://giantswarm.github.io/cluster-test-catalog/
REPO_NAME="${{ github.event.repository.name }}"
helm dependency build "helm/${REPO_NAME}"
for test_file_path in helm/${REPO_NAME}/ci/test-*-values.yaml; do
echo
echo "Rendering Helm template for ${test_file_path} on current code"
mkdir -p "/tmp/${test_file_path}"
helm template -n org-giantswarm \
-f "helm/${REPO_NAME}/ci/ci-values.yaml" \
-f "${test_file_path}" \
"helm/${REPO_NAME}" > "/tmp/${test_file_path}/render-new.yaml"
done
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: "${{ github.event.repository.default_branch }}"
path: 'old'
- name: render helm with main branch code
run: |
REPO_NAME="${{ github.event.repository.name }}"
helm dependency build "old/helm/${REPO_NAME}"
for test_file_path in helm/${REPO_NAME}/ci/test-*-values.yaml; do
echo
echo "Rendering Helm template for ${test_file_path} on old code"
if [ ! -f "old/${test_file_path}" ]; then
echo "File ${test_file_path} does not yet exist in old code, skipping"
continue
fi
helm template -n org-giantswarm \
-f "old/helm/${REPO_NAME}/ci/ci-values.yaml" \
-f "${test_file_path}" \
"old/helm/${REPO_NAME}" > "/tmp/${test_file_path}/render-old.yaml"
done
- name: get the diffs
uses: mathiasvr/command-output@34408ea3d0528273faff3d9e201761ae96106cd0 # v2.0.0
with:
run: |
marker="=== No differences at all ==="
REPO_NAME="${{ github.event.repository.name }}"
(
found_differences=
first=1
for test_file_path in helm/${REPO_NAME}/ci/test-*-values.yaml; do
if [ "${first}" = 1 ]; then
first=
else
echo
echo
fi
echo "=== Differences when rendered with values file ${test_file_path} ==="
old_file="/tmp/${test_file_path}/render-old.yaml"
new_file="/tmp/${test_file_path}/render-new.yaml"
dyff between --set-exit-code --ignore-order-changes --omit-header \
--use-go-patch-style "${old_file}" "${new_file}" \
&& echo "No difference" \
|| { res=$?; found_differences=1; if [[ $res -eq 255 ]]; then echo "Diff error"; fi; }
done
if [ -z "${found_differences}" ]; then
echo
echo
echo "${marker}"
fi
) > /tmp/diffs
(
if ! grep -qF "${marker}" /tmp/diffs ; then
echo "**There were differences in the rendered Helm template, please check! ⚠️**"
else
echo "There were no differences in the rendered Helm template."
fi
echo
echo "<details>"
echo "<summary>Output</summary>"
echo "<!-- mandatory empty line -->"
echo ""
echo '```'
cat /tmp/diffs
echo '```'
echo "</details>"
echo "<!-- mandatory empty line -->"
) > /tmp/comment-body
- name: Find diff comment
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0
continue-on-error: true
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'differences in the rendered Helm template'
- name: Delete old comment
uses: winterjung/comment@fda92dbcb5e7e79cccd55ecb107a8a3d7802a469 # v1.1.0
continue-on-error: true
if: steps.fc.outputs.comment-id != 0
with:
type: delete
comment_id: ${{ steps.fc.outputs.comment-id }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create comment
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: /tmp/comment-body