-
Notifications
You must be signed in to change notification settings - Fork 33
477 lines (475 loc) · 16.7 KB
/
ci.yml
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
name: "Continuous Integration"
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
env:
OPENFISCA_BIND_HOST: 127.0.0.1:2000
LC_ALL: C.UTF-8
LANG: C.UTF-8
PYTHON_VERSION: 3.11.4
SENTRY_URL: ${{ secrets.SENTRY_URL }}
MATTERMOST_ALERTING_URL: ${{ secrets.MATTERMOST_ALERTING_URL }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
health-check:
runs-on: ubuntu-latest
steps:
- name: Check Sentry Status
id: sentry-check
run: |
SENTRY_STATUS=$(curl -s -o /dev/null -w "%{http_code}" ${{ secrets.SENTRY_URL }})
echo "status=$SENTRY_STATUS" >> $GITHUB_OUTPUT
if [ "$SENTRY_STATUS" != "200" ]; then
curl -i -X POST -H 'Content-Type: application/json' -d '{"text": ":icon-warning: [équipe-tech] Sentry semble ne plus fonctionner ([lien](https://github.com/betagouv/aides-jeunes/actions/workflows/ci.yml?query=branch%3Amain+is%3Afailure))"}' ${{ secrets.MATTERMOST_ALERTING_URL }}
exit 1
fi
install:
name: Install
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache NPM install files
uses: actions/cache@v4
id: restore-npm-install-packages
with:
path: ~/.npm
key: ${{ runner.os }}-cache-npm-${{ hashFiles('**/package-lock.json') }}
- name: Cache node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Check tool versions
run: npm --version && node --version
- name: Install dependencies
if: steps.restore-dependencies.outputs.cache-hit != 'true'
run: npm ci --prefer-offline --no-audit
install_openfisca:
name: Install OpenFisca
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Virtual Environment
uses: actions/cache@v4
id: python-dependencies
with:
path: .venv
key: ${{ runner.os }}-cache-python-dependencies-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/openfisca/requirements.txt') }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup VirtualEnv
run: |
python -m venv .venv
- name: Install dependencies
shell: bash
run: |
source .venv/bin/activate
pip3 install -r openfisca/requirements.txt 2> ci-err.log
test -n ci-err.log && grep incompatible ci-err.log && cat ci-err.log && exit 1
rm ci-err.log
deactivate
lint:
name: Lint
needs: [install]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Run ESLint
run: npm run lint
- name: Run Prettier
run: npm run prettier:check
check_data_file_consistency:
name: Check data file consistency
needs: [install]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Run schema-validation-config.spec.ts
run: npm run test -- tests/integration/schema-validation-config.spec.ts
unit_tests:
name: Unit tests
needs: [install, check_data_file_consistency, install_openfisca]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Cache Virtual Environment
uses: actions/cache@v4
id: python-dependencies
with:
path: .venv
key: ${{ runner.os }}-cache-python-dependencies-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/openfisca/requirements.txt') }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup VirtualEnv
run: |
python -m venv .venv
- name: Run OpenFisca
shell: bash
run: |
source .venv/bin/activate
nohup gunicorn api --chdir openfisca/ --config openfisca/config.py --preload --log-level debug --log-file=- &
deactivate
- name: Wait for OpenFisca to be ready
shell: bash
run: |
for i in {1..30}; do
if wget --retry-connrefused --waitretry=2 --spider http://localhost:2000/parameter/prestations_sociales; then
echo "OpenFisca is ready"
break
fi
echo "Waiting for OpenFisca to be ready..."
sleep 2
done
- name: Jest
run: npm run test
build:
name: Build
needs: [install]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Cache build output
uses: actions/cache@v4
id: restore-build
with:
path: dist
key: ${{ runner.os }}-cache-build-${{ github.sha }}
- name: Cache server build output
uses: actions/cache@v4
id: restore-server-build
with:
path: dist-server
key: ${{ runner.os }}-cache-server-build-${{ github.sha }}
- name: Build assets
run: |
npm run build
build_contribuer:
name: Build contribuer/ static site
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore contribuer/node_modules
uses: actions/cache@v4
id: restore-contribuer-dependencies
with:
path: contribuer/node_modules
key: ${{ runner.os }}-cache-contribuer-node-modules-${{ hashFiles('contribuer/package-lock.json') }}
- name: Install dependencies
if: steps.restore-contribuer-dependencies.outputs.cache-hit != 'true'
run: cd contribuer && npm ci --prefer-offline --no-audit
- name: Restore contribuer/.next/cache
uses: actions/cache@v4
with:
path: |
~/.npm
${{ github.workspace }}/contribuer/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('contribuer/package-lock.json') }}-${{ hashFiles('contribuer/**.[jt]s', 'contribuer/**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('contribuer/package-lock.json') }}-
- name: Build static site
run: cd contribuer && npm run build
openfisca_test_generation:
name: OpenFisca test generation
needs: [install, install_openfisca, check_data_file_consistency]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Cache Virtual Environment
uses: actions/cache@v4
id: python-dependencies
with:
path: .venv
key: ${{ runner.os }}-cache-python-dependencies-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/openfisca/requirements.txt') }}
- name: Validate OpenFisca test generation
shell: bash
run: |
source .venv/bin/activate
npm run test tests/unit/openfisca/test.spec.ts
iframe_build_control:
name: Iframe build control
needs: [install]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Build assets
run: |
cp .env.iframe_build_control .env
npm run build:iframes
- name: Validate Iframe build
shell: bash
run: "npm run tools:test-iframe-generation"
test_e2e:
name: End-to-End Tests
needs: [build, install_openfisca]
runs-on: ubuntu-20.04
timeout-minutes: 15
services:
mongodb:
image: mongo:6.0.8
ports:
- 27017:27017
strategy:
matrix:
test: [base, family, handicap, patrimoine, student]
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Cache Cypress installation
uses: actions/cache@v4
id: restore-cypress
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cache-cypress-${{ hashFiles('**/package-lock.json') }}
- name: Cache Virtual Environment
uses: actions/cache@v4
id: python-dependencies
with:
path: .venv
key: ${{ runner.os }}-cache-python-dependencies-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/openfisca/requirements.txt') }}
- name: Cache build output
uses: actions/cache@v4
id: restore-build
with:
path: dist
key: ${{ runner.os }}-cache-build-${{ github.sha }}
- name: Cache server build output
uses: actions/cache@v4
id: restore-server-build
with:
path: dist-server
key: ${{ runner.os }}-cache-server-build-${{ github.sha }}
- name: Start OpenFisca
shell: bash
run: |
source .venv/bin/activate
nohup gunicorn api --chdir openfisca/ --config openfisca/config.py --preload --log-level debug --log-file=- &
deactivate
- name: Cypress install
uses: cypress-io/github-action@v6
if: steps.restore-cypress.outputs.cache-hit != 'true'
with:
browser: chrome
config-file: cypress.config.ts
runTests: false
- name: Copy cypress env file
run: cp .env.e2e .env
- name: Cypress run
uses: cypress-io/github-action@v6
with:
browser: chrome
config-file: cypress.config.ts
start: npm run ci
wait-on: "http://127.0.0.1:8080, http://127.0.0.1:2000/variable/parisien, http://127.0.0.1:27017"
install: false
spec: cypress/e2e/${{matrix.test}}.cy.js
- name: Upload cypress videos
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-video-${{matrix.test}}
path: |
cypress/videos
cypress/screenshots
retention-days: 10
- name: Upload cypress payloads
uses: actions/upload-artifact@v4
with:
name: cypress-json-${{matrix.test}}
path: cypress/payloads
check-for-openfisca-requirements-changes:
name: Check openfisca requirement changes
runs-on: ubuntu-20.04
timeout-minutes: 15
outputs:
status: ${{ steps.stop-early.outputs.status }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: stop-early
run: if "${GITHUB_WORKSPACE}/.github/has-file-changes.sh" "${GITHUB_WORKSPACE}/openfisca/requirements.txt" ; then echo "status=success" >> $GITHUB_OUTPUT ; fi
test_definition_periods:
name: Openfisca definition periods tests
needs:
[
check-for-openfisca-requirements-changes,
install,
install_openfisca,
build,
]
if: needs.check-for-openfisca-requirements-changes.outputs.status == 'success'
runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "18.18.2"
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Cache Virtual Environment
uses: actions/cache@v4
id: python-dependencies
with:
path: .venv
key: ${{ runner.os }}-cache-python-dependencies-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/openfisca/requirements.txt') }}
- name: Cache server build output
uses: actions/cache@v4
id: restore-server-build
with:
path: dist-server
key: ${{ runner.os }}-cache-server-build-${{ github.sha }}
- name: Start OpenFisca
shell: bash
run: |
source .venv/bin/activate
nohup gunicorn api --chdir openfisca/ --config openfisca/config.py --preload --log-level debug --log-file=- &
deactivate
- name: Wait openfisca
shell: bash
run: wget --retry-connrefused --waitretry=2 --output-document=/dev/null http://localhost:2000/variable/parisien
- name: Test definition periods
shell: bash
run: npm run tools:test-definition-periods
test_benefit_file_changes:
name: Test benefit file changes
needs: [install]
runs-on: ubuntu-20.04
outputs:
status: ${{ steps.has-changes.outputs.status }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- id: has-changes
run: |
if "${GITHUB_WORKSPACE}/.github/has-file-changes.sh" "${GITHUB_WORKSPACE}/data/benefits" ; then
echo "status=success" >> $GITHUB_OUTPUT
fi
check_benefit_link_improvements:
name: Check benefit link improvements and update link table if necessary
needs: [test_benefit_file_changes]
if: needs.test_benefit_file_changes.outputs.status == 'success'
runs-on: ubuntu-20.04
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "18.18.2"
- name: Restore node modules
uses: actions/cache@v4
id: restore-dependencies
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Test
shell: bash
run: npm run tools:check-links-validity -- --no-priority
env:
GRIST_DOC_ID: ${{ secrets.GRIST_DOC_ID }}
GRIST_API_KEY: ${{ secrets.GRIST_API_KEY }}
ci_failed:
name: Detect failure
runs-on: ubuntu-20.04
needs:
[
install,
install_openfisca,
lint,
unit_tests,
build,
build_contribuer,
openfisca_test_generation,
iframe_build_control,
test_e2e,
]
if: always() && github.ref == 'refs/heads/main' && (needs.install.result == 'failure' || needs.install_openfisca.result == 'failure' || needs.lint.result == 'failure' || needs.unit_tests.result == 'failure' || needs.build.result == 'failure' || needs.build_contribuer.result == 'failure' || needs.openfisca_test_generation.result == 'failure' || needs.iframe_build_control.result == 'failure' || needs.test_e2e.result == 'failure')
steps:
- name: Send CI failed message
shell: bash
run: |
curl -i -X POST -H 'Content-Type: application/json' -d '{"text": ":icon-danger: [équipe-tech] La CI a rencontré un problème sur la branche main ([lien](https://github.com/betagouv/aides-jeunes/actions/workflows/ci.yml?query=branch%3Amain+is%3Afailure))"}' ${{ secrets.MATTERMOST_ALERTING_URL }}