-
Notifications
You must be signed in to change notification settings - Fork 26
570 lines (500 loc) · 18 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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
name: Run CI
# Run this workflow every time a new commit pushed to your repository
on:
push:
branches:
- master
- stable/*
tags:
- '*'
pull_request:
workflow_dispatch:
schedule:
- cron: '30 7 * * *'
env:
IMAGE_NAME: openformulieren/open-forms
DJANGO_SETTINGS_MODULE: openforms.conf.ci
HYPOTHESIS_PROFILE: ci
CAMUNDA_API_BASE_URL: http://localhost:8080/engine-rest/
CAMUNDA_USER: demo
CAMUNDA_PASSWORD: demo
jobs:
tests:
name: Run the Django test suite
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# Needed because the postgres container does not provide a healthcheck
options:
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
--name postgres
redis:
image: redis:6
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
apt-packages: 'libxml2-dev libxmlsec1-dev libxmlsec1-openssl gettext postgresql-client gdal-bin'
python-version: '3.10'
optimize-postgres: 'yes'
pg-service: 'postgres'
setup-node: 'yes'
npm-ci-flags: '--legacy-peer-deps'
- name: Start CI docker services
run: |
docker compose -f docker-compose.ci.yml up -d
docker compose -f docker-compose.camunda.yml up -d
working-directory: docker
- name: Wait for Camunda to be up
run: |
endpoint="${CAMUNDA_API_BASE_URL}version"
version=""
until [ $version ]; do
echo "Checking if Camunda at ${CAMUNDA_API_BASE_URL} is up..."
version=$(curl -u ${CAMUNDA_USER}:${CAMUNDA_PASSWORD} "$endpoint" -s | jq -r ".version")
sleep 2
done
echo "Running Camunda $version"
- name: Run tests
run: |
echo "# Profiling stats" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_OUTPUT
python src/manage.py compilemessages
python src/manage.py collectstatic --noinput --link
coverage run \
--concurrency=multiprocessing \
--parallel-mode \
src/manage.py test src \
--parallel 4 \
--exclude-tag=e2e \
--verbosity 2
coverage combine
env:
DJANGO_SETTINGS_MODULE: openforms.conf.ci
SECRET_KEY: dummy
DB_USER: postgres
DB_PASSWORD: ''
DEBUG: 'true'
- name: Run JS tests
run: npm test
- name: Publish coverage report
uses: codecov/codecov-action@v3
- name: Generate OAS
run: ./bin/generate_oas.sh openapi.yaml
- name: Store generated OAS
uses: actions/upload-artifact@v4
with:
name: open-forms-oas
path: openapi.yaml
retention-days: 1
tests-reverse:
name: Run the Django test suite in reverse
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# Needed because the postgres container does not provide a healthcheck
options:
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
--name postgres
redis:
image: redis:6
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
apt-packages: 'libxml2-dev libxmlsec1-dev libxmlsec1-openssl gettext postgresql-client gdal-bin'
python-version: '3.10'
optimize-postgres: 'yes'
pg-service: 'postgres'
setup-node: 'yes'
npm-ci-flags: '--legacy-peer-deps'
- name: Start CI docker services
run: |
docker compose -f docker-compose.ci.yml up -d
docker compose -f docker-compose.camunda.yml up -d
working-directory: docker
- name: Wait for Camunda to be up
run: |
endpoint="${CAMUNDA_API_BASE_URL}version"
version=""
until [ $version ]; do
echo "Checking if Camunda at ${CAMUNDA_API_BASE_URL} is up..."
version=$(curl -u ${CAMUNDA_USER}:${CAMUNDA_PASSWORD} "$endpoint" -s | jq -r ".version")
sleep 2
done
echo "Running Camunda $version"
- name: Run tests
run: |
python src/manage.py compilemessages
python src/manage.py collectstatic --noinput --link
src/manage.py test src \
--parallel 4 \
--exclude-tag=e2e \
--reverse
env:
DJANGO_SETTINGS_MODULE: openforms.conf.ci
SECRET_KEY: dummy
DB_USER: postgres
DB_PASSWORD: ''
DEBUG: 'true'
e2etests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
browser:
- chromium
- firefox
- webkit
name: End-to-end tests, ${{ matrix.browser }}
services:
postgres:
image: postgres:14
env:
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
# Needed because the postgres container does not provide a healthcheck
options:
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
--name postgres
redis:
image: redis:6
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
apt-packages: 'libxml2-dev libxmlsec1-dev libxmlsec1-openssl gettext postgresql-client gdal-bin'
python-version: '3.10'
optimize-postgres: 'yes'
pg-service: 'postgres'
setup-node: 'yes'
npm-ci-flags: '--legacy-peer-deps'
# See https://playwright.dev/python/docs/ci#caching-browsers
- name: Cache Playwright browser
id: cache-browser
uses: actions/cache@v4
with:
path: /home/runner/.cache/ms-playwright
key:
${{ runner.os }}-${{ matrix.browser }}-playwright-${{ hashFiles('requirements/ci.txt') }}
- name: Install playwright deps
run: playwright install --with-deps ${{ matrix.browser }}
- name: Determine which SDK image to use to extract the JS/CSS files
id: sdk-tag
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name (if present at all)
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# default to version in .sdk-release file
SDK_TAG=$(cat .sdk-release | tr -d '[:space:]')
case $VERSION in
# if building master -> include latest image of SDK
master) SDK_TAG=latest;;
# PRs result in version 'merge' that'll go to master -> include latest image of SDK
merge) SDK_TAG=latest;;
esac
echo "sdk_tag=${SDK_TAG}" >> $GITHUB_OUTPUT
- name: Extract SDK files from SDK docker image
run: |
container_id=$(docker create openformulieren/open-forms-sdk:${{ steps.sdk-tag.outputs.sdk_tag }})
docker cp $container_id:/sdk ./src/openforms/static/
docker rm -v $container_id
- name: Run testsuite
run: |
python src/manage.py compilemessages
python src/manage.py collectstatic --noinput --link
src/manage.py test src --tag=e2e
env:
DJANGO_SETTINGS_MODULE: openforms.conf.ci
SECRET_KEY: dummy
DB_USER: postgres
DB_PASSWORD: ''
E2E_DRIVER: ${{ matrix.browser }}
SDK_RELEASE: ${{ steps.sdk-tag.outputs.sdk_tag }}
docs:
name: Build and check documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: open-forms
- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
apt-packages: 'libxml2-dev libxmlsec1-dev libxmlsec1-openssl gdal-bin'
python-version: '3.10'
setup-node: 'no'
working-directory: 'open-forms'
- name: Determine SDK version to checkout
id: sdk-ref
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name (if present at all)
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# default to version in .sdk-release file
SDK_REF=$(cat .sdk-release | tr -d '[:space:]')
case $VERSION in
# if building master -> include main of SDK
master) SDK_REF=main;;
# PRs result in version 'merge' that'll go to master -> include main of SDK
merge) SDK_REF=main;;
esac
echo "sdk_ref=${SDK_REF}" >> $GITHUB_OUTPUT
working-directory: open-forms
- name: Checkout SDK repository
uses: actions/checkout@v4
with:
repository: 'open-formulieren/open-forms-sdk'
ref: ${{ steps.sdk-ref.outputs.sdk_ref }}
path: open-forms-sdk
- name: Setup symlinks
run: |
ln -s $(pwd)/open-forms-sdk/CHANGELOG.rst open-forms/docs/changelog-sdk.rst
- name: Build and test docs
run: |
export OPENSSL_CONF=$(pwd)/openssl.conf
pytest check_sphinx.py -v --tb=auto
working-directory: open-forms/docs
# see https://github.com/orgs/community/discussions/26671
docker_build_setup:
name: Set up docker build 'dynamic' env variables
runs-on: ubuntu-latest
outputs:
image-name: ${{ steps.set-output-defaults.outputs.image-name }}
steps:
- name: Set output with default values
id: set-output-defaults
run: |
echo "image-name=${{ env.IMAGE_NAME }}" >> $GITHUB_OUTPUT
docker_build:
needs: docker_build_setup
strategy:
matrix:
# KEEP IN SYNC WITH docker_push JOB
target:
- env: production
extensions: ''
image_tag_prefix: ''
- env: extensions
extensions: 'token_exchange,prefill_haalcentraalhr'
image_tag_prefix: 'all-extensions-'
uses: ./.github/workflows/build-image.yml
with:
image_name: ${{ needs.docker_build_setup.outputs.image-name }}
image_tag_prefix: ${{ matrix.target.image_tag_prefix }}
target_env: ${{ matrix.target.env }}
extensions: ${{ matrix.target.extensions }}
image_scan:
runs-on: ubuntu-latest
name: Scan docker image
needs:
- docker_build
steps:
# So the scanner gets commit meta-information
- name: Checkout code
uses: actions/checkout@v4
- name: Derive version
id: vars
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name (if present at all)
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
# PRs result in version 'merge' -> transform that into 'latest'
[ "$VERSION" == "merge" ] && VERSION=latest
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Download built image
uses: actions/download-artifact@v4
with:
name: docker-image-all-extensions-${{ steps.vars.outputs.version }}
- name: Scan image with Trivy
uses: aquasecurity/trivy-action@master
with:
input: /github/workspace/image.tar # from download-artifact
format: 'sarif'
output: 'trivy-results-docker.sarif'
ignore-unfixed: true
- name: Upload results to GH Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results-docker.sarif'
oas-up-to-date:
needs: tests
name: Check for unexepected OAS changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open-forms-oas
- name: Check for OAS changes
run: |
diff openapi.yaml src/openapi.yaml
- name: Write failure markdown
if: ${{ failure() }}
run: |
echo 'Run the following command locally and commit the changes' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo './bin/generate_oas.sh' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
oas-lint:
needs: oas-up-to-date
name: Validate OAS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open-forms-oas
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install spectral
run: npm install -g @stoplight/[email protected]
- name: Run OAS linter
run: spectral lint ./openapi.yaml
oas-postman:
needs: oas-up-to-date
name: Generate Postman collection from OAS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open-forms-oas
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm install -g openapi-to-postmanv2
- name: Create tests folder
run: mkdir -p ./tests/postman
- name: Generate Postman collection
run: openapi2postmanv2 -s ./openapi.yaml -o ./tests/postman/collection.json --pretty
oas-generate-sdks:
needs: oas-up-to-date
name: Generate SDKs from OAS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open-forms-oas
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm install -g @openapitools/[email protected]
- name: Validate schema
run: openapi-generator-cli validate -i ./openapi.yaml
- name: Set the version of openapi-generator which gets used
run: |
openapi-generator-cli version-manager set 7.0.0
- name: Generate Java client
run:
openapi-generator-cli generate -i ./openapi.yaml
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -o
./sdks/java -g java
--additional-properties=dateLibrary=java8,java8=true,optionalProjectFile=false,optionalAssemblyInfo=false
- name: Generate .NET Full Framework client
run:
openapi-generator-cli generate -i ./openapi.yaml
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -o
./sdks/net -g csharp
--additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false
- name: Generate Python client
run:
openapi-generator-cli generate -i ./openapi.yaml
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -o
./sdks/python -g python
--additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false+
docker_push:
needs:
- tests
- e2etests
- docker_build
- oas-lint
- oas-postman
- oas-generate-sdks
name: Push Docker image
runs-on: ubuntu-latest
if: github.event_name == 'push' # Exclude PRs
strategy:
matrix:
# KEEP IN SYNC WITH docker_build JOB
target:
- env: production
image_tag_prefix: ''
- env: extensions
image_tag_prefix: 'all-extensions-'
steps:
- uses: actions/checkout@v4
- name: Derive version
id: vars
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name (if present at all)
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
# PRs result in version 'merge' -> transform that into 'latest'
[ "$VERSION" == "merge" ] && VERSION=latest
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Download built image
uses: actions/download-artifact@v4
with:
name: docker-image-${{ matrix.target.image_tag_prefix }}${{ steps.vars.outputs.version }}
- name: Load image
run: |
docker image load -i image.tar
- name: Log into registry
run:
echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }}
--password-stdin
- name: Push the Docker image (production)
run: docker push $IMAGE_NAME:$TAG
env:
TAG: ${{ matrix.target.image_tag_prefix }}${{ steps.vars.outputs.version }}
update-docker-readme:
needs:
- docker_build_setup
- docker_push
uses: ./.github/workflows/dockerhub-description.yml
with:
image_name: ${{ needs.docker_build_setup.outputs.image-name }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}