forked from MinBZK/mijn-bureau-infra
-
Notifications
You must be signed in to change notification settings - Fork 0
337 lines (276 loc) · 10.4 KB
/
ci.yaml
File metadata and controls
337 lines (276 loc) · 10.4 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
name: ci
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches:
- main
pull_request:
branches:
- "*"
jobs:
lint-commit-messages:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-python@v6
with:
python-version: "3.x"
- name: Show logs
run: git log
- name: Install gitlint
run: pip install requests gitlint
- name: Lint commit messages added to main
run: gitlint --commits origin/${{ github.event.pull_request.base.ref }}..HEAD
lint-helmfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Install helm
run: |
wget -O - https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Install helmfile
run: |
cd /tmp/
wget https://github.com/helmfile/helmfile/releases/download/v1.1.2/helmfile_1.1.2_linux_amd64.tar.gz
tar -xzf helmfile_1.1.2_linux_amd64.tar.gz
sudo mv helmfile /usr/local/bin/helmfile
- name: Initilize helmfile dependecies
run: |
helmfile init --force
- name: Lint helmfile
run: |
helmfile -e production lint
helmfile -e demo lint
helmfile lint
env:
MIJNBUREAU_MASTER_PASSWORD: ${{ secrets.MIJNBUREAU_MASTER_PASSWORD || 'dependabot' }}
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY || 'dependabot' }}
render-helmfile:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Install helm
run: |
wget -O - https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Install helmfile
run: |
cd /tmp/
wget https://github.com/helmfile/helmfile/releases/download/v1.1.2/helmfile_1.1.2_linux_amd64.tar.gz
tar -xzf helmfile_1.1.2_linux_amd64.tar.gz
sudo mv helmfile /usr/local/bin/helmfile
- name: Initilize helmfile dependecies
run: |
helmfile init --force
- name: Render helmfile for all environments
run: |
helmfile -e production template --output-dir=/tmp/manifest/production
helmfile -e demo template --output-dir=/tmp/manifest/demo
helmfile template --output-dir=/tmp/manifest/default
env:
MIJNBUREAU_MASTER_PASSWORD: ${{ secrets.MIJNBUREAU_MASTER_PASSWORD || 'dependabot' }}
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY || 'dependabot' }}
- name: Upload rendered manifests
uses: actions/upload-artifact@v4
with:
name: rendered-manifests
path: /tmp/manifest/
if-no-files-found: error
retention-days: 3
verify-policies:
runs-on: ubuntu-latest
needs: [render-helmfile]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- uses: actions/download-artifact@v5
with:
name: rendered-manifests
path: /tmp/manifest
- name: Install conftest
run: |
wget https://github.com/open-policy-agent/conftest/releases/download/v0.61.2/conftest_0.61.2_linux_amd64.deb
sudo dpkg -i conftest_0.61.2_linux_amd64.deb
- name: Run conftest against rendered manifests
run: |
conftest test /tmp/manifest/production --output=github --parser yaml --quiet
conftest test /tmp/manifest/demo --output=github --parser yaml --quiet
conftest test /tmp/manifest/default --output=github --parser yaml --quiet
test-values:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Install helm
run: |
wget -O - https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Install helmfile
run: |
cd /tmp/
wget https://github.com/helmfile/helmfile/releases/download/v1.1.2/helmfile_1.1.2_linux_amd64.tar.gz
tar -xzf helmfile_1.1.2_linux_amd64.tar.gz
sudo mv helmfile /usr/local/bin/helmfile
- name: Initilize helmfile dependecies
run: |
helmfile init --force
- name: Install conftest
run: |
wget https://github.com/open-policy-agent/conftest/releases/download/v0.61.2/conftest_0.61.2_linux_amd64.deb
sudo dpkg -i conftest_0.61.2_linux_amd64.deb
- name: Run setup tests in demo environment
run: |
./scripts/test.sh -e demo
- name: Run setup tests in production environment
run: |
./scripts/test.sh -e production
check-format-rules:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: "22"
- uses: actions/setup-python@v6
with:
python-version: "3.x"
- name: Install prettier
run: npm install -g prettier
- name: Install pre-commit
run: pip install pre-commit
- name: Run formatters
run: ./scripts/format.sh
- name: Check for changes
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "Error: Detected uncommitted changes after formatting. Please run the formatter locally and commit the results."
git status
git diff
exit 1
fi
- name: run pre-commit
run: pre-commit run --all-files
check-kubernetes-conformance:
runs-on: ubuntu-latest
needs: [render-helmfile]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- uses: actions/download-artifact@v5
with:
name: rendered-manifests
path: /tmp/manifest
- name: Install kubeconform
run: |
wget https://github.com/yannh/kubeconform/releases/download/v0.7.0/kubeconform-linux-amd64.tar.gz -O /tmp/kubeconform.tar.gz
tar -xzf /tmp/kubeconform.tar.gz -C /tmp/
mv /tmp/kubeconform /usr/local/bin/kubeconform
chmod +x /usr/local/bin/kubeconform
- name: Run kubeconform against rendered manifests
run: |
kubeconform -strict -summary /tmp/manifest/production/
kubeconform -strict -summary /tmp/manifest/demo/
kubeconform -strict -summary /tmp/manifest/default/
diff:
runs-on: ubuntu-latest
needs: [render-helmfile]
if: github.event_name == 'pull_request'
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/download-artifact@v5
with:
name: rendered-manifests
path: /tmp/manifest
- uses: actions/checkout@v5
with:
ref: main
- name: Install helm
run: |
wget -O - https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: Install helmfile
run: |
cd /tmp/
wget https://github.com/helmfile/helmfile/releases/download/v1.1.2/helmfile_1.1.2_linux_amd64.tar.gz
tar -xzf helmfile_1.1.2_linux_amd64.tar.gz
sudo mv helmfile /usr/local/bin/helmfile
- name: Initilize helmfile dependecies
run: |
helmfile init --force
- name: Render helmfile for all environments
run: |
helmfile -e demo template --output-dir=/tmp/manifest/demo-main
env:
MIJNBUREAU_MASTER_PASSWORD: ${{ secrets.MIJNBUREAU_MASTER_PASSWORD || 'dependabot' }}
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY || 'dependabot' }}
- name: diff manifests
run: diff -burN /tmp/manifest/demo-main/ /tmp/manifest/demo/ > diff.txt || true
- name: get file size
run: |
file_size=$(stat -c%s diff.txt)
echo "file_size=$file_size" >> $GITHUB_OUTPUT
id: diff
- name: format diff
if: ${{ steps.diff.outputs.file_size != '0' }}
run: |
echo -e 'DIFF\n```\n' > formatted_diff.txt
cat diff.txt >> formatted_diff.txt
echo -e '\n```' >> "formatted_diff.txt"
- name: Find Comment
if: ${{ steps.diff.outputs.file_size != '0' }}
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: DIFF
# comment on pr with diff
- name: Comment on PR with diff
if: ${{ steps.diff.outputs.file_size != '0' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: formatted_diff.txt
edit-mode: replace
comment-id: ${{ steps.fc.outputs.comment-id }}
notify-mattermost:
runs-on: ubuntu-latest
needs:
[
lint-commit-messages,
check-format-rules,
render-helmfile,
verify-policies,
check-kubernetes-conformance,
lint-helmfile,
test-values,
]
if: ${{ always() && contains(needs.*.result, 'failure') }}
steps:
- uses: mattermost/action-mattermost-notify@master
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
with:
MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK }}
MATTERMOST_CHANNEL: github-actions
TEXT: |
## 🚨 CI Pipeline Failed
**Repository:** `${{ github.repository }}`
**Branch/Tag:** `${{ github.head_ref }}`
**Triggered by:** @${{ github.actor }}
**Event:** ${{ github.event_name }}
### Failed Jobs:
${{ needs.lint-commit-messages.result == 'failure' && '❌ Commit Message Linting' || '' }}
${{ needs.check-format-rules.result == 'failure' && '❌ Format & Pre-commit Checks' || '' }}
### Quick Actions:
- 🔍 [View Pipeline Details](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- 📝 [View Commit](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
${{ github.event_name == 'pull_request' && format('- 🔄 [View Pull Request]({0}/{1}/pull/{2})', github.server_url, github.repository, github.event.number) || '' }}