-
Notifications
You must be signed in to change notification settings - Fork 0
299 lines (263 loc) · 11.6 KB
/
validate.yaml
File metadata and controls
299 lines (263 loc) · 11.6 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
name: Validate Helm Charts
on:
workflow_call:
inputs:
chart_dir:
description: Directory containing the charts to validate.
type: string
required: false
default: charts
excluded_charts:
description: Charts to exclude from validation.
type: string
required: false
default: ""
target_branch:
description: Target branch for charts.
type: string
required: false
default: main
helm_repos:
description: List of Helm repos to install; as a comma separated list in the format `<name>=<address>`.
type: string
required: false
default: ""
helm_docs:
description: If helm-docs should be run.
type: boolean
required: false
default: false
helm_docs_args:
description: Args for the helm-docs command.
type: string
required: false
default: ""
changelog:
description: If the CHANGELOG needs to be validated.
type: boolean
required: false
default: false
ah_lint:
description: If the Artifact Hub linter should be run.
type: boolean
required: false
default: true
kubeconform:
description: If the Kubeconform should be run.
type: boolean
required: false
default: true
kubeconform_k8s_versions:
description: List of Kubernetes versions to use for Kubeconform; as a comma separated list in the format `<major>.<minor>.<patch>`.
type: string
required: false
default: ""
kubeconform_skip:
description: List of Kubeconform schemas to skip; as a comma separated list of kinds or GVKs.
type: string
required: false
default: ""
helm_extra_args:
description: Extra arguments to pass to Helm as part of chart testing.
type: string
required: false
default: ""
jobs:
validate:
name: Validate Helm charts
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
pull-requests: write
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Install Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
token: ${{ github.token }}
python-version: "3.x"
- name: Install Helm
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
with:
version: latest
- name: Configure Helm repos
if: ${{ inputs.helm_repos }}
run: |
set -euo pipefail
repos="${{ inputs.helm_repos }}"
for repo in ${repos//,/ }
do
helm repo add "${repo%=*}" "${repo#*=}"
done
- name: Install chart-testing
uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # v2.8.0
- name: Check for changes
id: changes
run: |
set -euo pipefail
changed="$(ct list-changed --target-branch=${{ inputs.target_branch }} --chart-dirs=${{ inputs.chart_dir }} --excluded-charts=${{ inputs.excluded_charts }})"
if [[ -n "${changed}" ]]
then
echo "changed=true" >> "${GITHUB_OUTPUT}"
echo "charts=$(echo "${changed}" | tr '\n' ',' | rev | cut -c 2- | rev | jq -Rrc '[split(",") | .[] | split("/") | .[1]] | join(",")')" >> "${GITHUB_OUTPUT}"
else
echo "changed=false" >> "${GITHUB_OUTPUT}"
echo "charts=" >> "${GITHUB_OUTPUT}"
fi
- name: Install Helm Docs
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
if: ${{ inputs.helm_docs && steps.changes.outputs.changed == 'true' }}
with:
github_token: ${{ github.token }}
owner: norwoodj
repository: helm-docs
arch_amd64: x86_64
os_linux: Linux
check_command: helm-docs --version
version: latest
- name: Run Helm Docs check
if: ${{ inputs.helm_docs && steps.changes.outputs.changed == 'true' }}
run: |
set -euo pipefail
helm-docs ${{ inputs.helm_docs_args }}
if [[ -n "$(git status --porcelain --untracked-files=no)" ]]
then
echo "Documentation not up to date; please run helm-docs and commit changes!" >&2
exit 1
fi
- name: Install YQ
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
if: ${{ inputs.changelog && steps.changes.outputs.changed == 'true' }}
with:
github_token: ${{ github.token }}
owner: mikefarah
repository: yq
extract: false
filename_format: "{name}_{os}_{arch}"
check_command: yq --version
version: latest
- name: Install MDQ
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
if: ${{ inputs.changelog && steps.changes.outputs.changed == 'true' }}
with:
github_token: ${{ github.token }}
owner: yshavit
repository: mdq
arch_amd64: x64
filename_format: "{name}-{os}-{arch}.{ext}"
check_command: mdq --version
version: latest
- name: Run CHANGELOG check
if: ${{ inputs.changelog && steps.changes.outputs.changed == 'true' }}
run: |
set -euo pipefail
charts="${{ steps.changes.outputs.charts }}"
for chart in ${charts//,/ }
do
chart_file_path="./${{ inputs.chart_dir }}/${chart}/Chart.yaml"
changelog_file_path="./${{ inputs.chart_dir }}/${chart}/CHANGELOG.md"
version="$(yq eval '.version' "${chart_file_path}")"
entry="$(mdq --no-br --link-format inline "# v${version}" <"${changelog_file_path}" || true)"
if [[ -z "${entry}" ]]
then
echo "No CHANGELOG entry for ${chart} version ${version}!" >&2
exit 1
fi
added="$(mdq --output plain "# v${version} | # Added | -" <"${changelog_file_path}" || true)"
changed="$(mdq --output plain "# v${version} | # Changed | -" <"${changelog_file_path}" || true)"
deprecated="$(mdq --output plain "# v${version} | # Deprecated | -" <"${changelog_file_path}" || true)"
removed="$(mdq --output plain "# v${version} | # Removed | -" <"${changelog_file_path}" || true)"
fixed="$(mdq --output plain "# v${version} | # Fixed | -" <"${changelog_file_path}" || true)"
security="$(mdq --output plain "# v${version} | # Security | -" <"${changelog_file_path}" || true)"
changes_path="./${{ inputs.chart_dir }}/${chart}/changes.txt"
rm -f "${changes_path}"
old_ifs="${IFS}"
IFS=$'\n'
for item in ${added}; do
printf -- '- kind: added\n description: "%s"\n' "${item%.*}." >> "${changes_path}"
done
for item in ${changed}; do
printf -- '- kind: changed\n description: "%s"\n' "${item%.*}." >> "${changes_path}"
done
for item in ${deprecated}; do
printf -- '- kind: deprecated\n description: "%s"\n' "${item%.*}." >> "${changes_path}"
done
for item in ${removed}; do
printf -- '- kind: removed\n description: "%s"\n' "${item%.*}." >> "${changes_path}"
done
for item in ${fixed}; do
printf -- '- kind: fixed\n description: "%s"\n' "${item%.*}." >> "${changes_path}"
done
for item in ${security}; do
printf -- '- kind: security\n description: "%s"\n' "${item%.*}." >> "${changes_path}"
done
IFS="${old_ifs}"
if [[ -f "${changes_path}" ]]; then
echo "::group::Changes"
cat "${changes_path}"
echo "::endgroup::"
changes="$(cat "${changes_path}")" yq eval --inplace '.annotations["artifacthub.io/changes"] |= strenv(changes)' "${chart_file_path}"
rm -f "${changes_path}"
fi
done
- name: Install Artifact Hub CLI
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
if: ${{ inputs.ah_lint && steps.changes.outputs.changed == 'true' }}
with:
github_token: ${{ github.token }}
owner: artifacthub
repository: hub
name: ah
check_command: ah version
version: latest
- name: Run Artifact Hub lint
if: ${{ inputs.ah_lint && steps.changes.outputs.changed == 'true' }}
run: ah lint --kind helm || exit 1
- name: Run chart-testing lint
if: ${{ steps.changes.outputs.changed == 'true' }}
run: ct lint --target-branch=${{ inputs.target_branch }} --chart-dirs=${{ inputs.chart_dir }} --excluded-charts=${{ inputs.excluded_charts }} --check-version-increment=false --chart-repos="${{ inputs.helm_repos }}"
- name: Install Kubeconform
uses: action-stars/install-tool-from-github-release@1fa61c3bea52eca3bcdb1f5c961a3b113fe7fa54 # v0.2.6
if: ${{ inputs.kubeconform && steps.changes.outputs.changed == 'true' }}
with:
github_token: ${{ github.token }}
owner: yannh
repository: kubeconform
filename_format: "{name}-{os}-{arch}.{ext}"
check_command: kubeconform -v
version: latest
- name: Run Kubeconform
if: ${{ inputs.kubeconform && steps.changes.outputs.changed == 'true' }}
run: |
set -euo pipefail
charts="${{ steps.changes.outputs.charts }}"
for chart in ${charts//,/ }
do
values="./${{ inputs.chart_dir }}/${chart}/ci/kubeconform.yaml"
if [[ ! -f "${values}" ]]
then
values="./${{ inputs.chart_dir }}/${chart}/test-values.yaml"
touch "${values}"
fi
k8s_version_stable="$(curl -sL https://dl.k8s.io/release/stable.txt | grep -Eo '[0-9]+\.[0-9]+').0"
k8s_versions_in="${{ inputs.kubeconform_k8s_versions }}"
k8s_versions="${k8s_versions_in:-$k8s_version_stable}"
for k8s_version in ${k8s_versions//,/ }
do
echo "Chart: ${chart}, K8s: ${k8s_version}"
helm template --kube-version "${k8s_version}" "./${{ inputs.chart_dir }}/${chart}" --values "${values}" | kubeconform --kubernetes-version "${k8s_version}" --schema-location default --schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' --schema-location 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{.NormalizedKubernetesVersion}}/{{.ResourceKind}}.json' --skip "${{ inputs.kubeconform_skip }}" --strict --summary
done
done
- name: Create Kind cluster
if: ${{ steps.changes.outputs.changed == 'true' }}
uses: helm/kind-action@92086f6be054225fa813e0a4b13787fc9088faab # v1.13.0
- name: Run chart-testing install
if: ${{ steps.changes.outputs.changed == 'true' }}
run: ct install --target-branch=${{ inputs.target_branch }} --chart-dirs=${{ inputs.chart_dir }} --excluded-charts=${{ inputs.excluded_charts }} --helm-extra-args="${{ inputs.helm_extra_args }}" --chart-repos="${{ inputs.helm_repos }}"