-
Notifications
You must be signed in to change notification settings - Fork 50
402 lines (342 loc) · 12.3 KB
/
continuous-integration.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
name: CI (mandatory checks)
on:
push:
branches-ignore:
- staging
- prod
- devel
tags-ignore:
- staging
- prod
pull_request:
merge_group:
workflow_dispatch:
workflow_call:
env:
USER_ID: 1001
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
jobs:
api-cs-check:
name: 'Lint: API (php-cs-fixer)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2.8'
tools: composer:2.5.0
coverage: xdebug
- name: Get Composer Cache Directory
id: composer-cache
run: 'echo "dir=$(composer config cache-files-dir)" | tr -d "\n" >> $GITHUB_OUTPUT'
working-directory: api
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- run: composer install --no-interaction --no-plugins --no-scripts --prefer-dist
working-directory: api
- run: php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php -v --dry-run --diff
working-directory: api
frontend-eslint:
name: 'Lint: Frontend (ESLint)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- uses: actions/setup-node@v3
with:
node-version: '20.5.0'
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci --no-audit
working-directory: frontend
- run: |
npm run lint:check:eslint
result=$(npm run lint:check:prettier)
echo $result
if echo $result | grep -E "Code style issues found"; then
exit 1
fi
working-directory: frontend
print-eslint:
name: 'Lint: Print (ESLint)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- uses: actions/setup-node@v3
with:
node-version: '20.5.0'
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci --no-audit
working-directory: print
- run: |
npm run lint:check:eslint
result=$(npm run lint:check:prettier)
echo $result
if echo $result | grep -E "Code style issues found"; then
exit 1
fi
working-directory: print
api-tests:
name: 'Tests: API'
runs-on: ubuntu-latest
env:
TEST_DATABASE_URL: postgresql://ecamp3:ecamp3@localhost:5432/ecamp3test?serverVersion=15&charset=utf8
services:
postgres:
image: 'postgres:15-alpine'
env:
POSTGRES_DB: 'ecamp3test'
POSTGRES_PASSWORD: 'ecamp3'
POSTGRES_USER: 'ecamp3'
ports:
- '5432:5432'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2.8'
extensions: intl-73.1
tools: composer:2.5.0
coverage: xdebug
- name: Get Composer Cache Directory
id: composer-cache
run: 'echo "dir=$(composer config cache-files-dir)" | tr -d "\n" >> $GITHUB_OUTPUT'
working-directory: api
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- run: composer install --prefer-dist --no-progress --no-interaction
working-directory: api
- run: |
mkdir -p var/cache var/log
jwt_passphrase=${JWT_PASSPHRASE:-$(grep ''^JWT_PASSPHRASE='' .env | cut -f 2 -d ''='')}
echo "Generating public / private keys for JWT"
mkdir -p config/jwt
echo "$jwt_passphrase" | openssl genpkey -out config/jwt/private.pem -pass stdin -aes256 -algorithm rsa -pkeyopt rsa_keygen_bits:4096
echo "$jwt_passphrase" | openssl pkey -in config/jwt/private.pem -passin stdin -out config/jwt/public.pem -pubout
setfacl -R -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
setfacl -dR -m u:www-data:rX -m u:"$(whoami)":rwX config/jwt
working-directory: api
- run: php bin/console doctrine:migrations:migrate --no-interaction -e test
working-directory: api
- run: composer test
working-directory: api
- name: send coveralls report
run: |
sed -i "s|$(pwd)/api/|api/|g" api/build/logs/clover.xml
api/vendor/bin/php-coveralls -v \
--coverage_clover api/build/logs/clover.xml \
--json_path api/build/logs/coveralls-upload.json
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: api
frontend-tests:
name: 'Tests: Frontend'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- uses: actions/setup-node@v3
with:
node-version: '20.5.0'
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci --no-audit
working-directory: frontend
- run: npm run build
working-directory: frontend
- run: npm run test:unit
working-directory: frontend
- name: send coverage info
run: |
sed -i "s|src/|frontend/src/|g" frontend/data/coverage/lcov.info
cat frontend/data/coverage/lcov.info | npx coveralls .
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
COVERALLS_SERVICE_NUMBER: ${{ github.run_id }}
CI_PULL_REQUEST: ${{ github.event.number }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: frontend
print-tests:
name: 'Tests: Print'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- uses: actions/setup-node@v3
with:
node-version: '20.5.0'
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci --no-audit
working-directory: print
- run: npm run build
working-directory: print
env:
NODE_OPTIONS: --openssl-legacy-provider
- run: npm run test
working-directory: print
- name: send coverage info
run: |
sed -i "s|SF:|SF:print/|g" print/coverage/lcov.info
cat print/coverage/lcov.info | npx coveralls .
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
COVERALLS_SERVICE_NUMBER: ${{ github.run_id }}
CI_PULL_REQUEST: ${{ github.event.number }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: print
e2e-tests-build:
name: 'Tests: End-to-end (build job)'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# build API (using cache; provide image to docker compose)
- name: Build docker image (API/PHP)
uses: docker/build-push-action@v4
with:
file: api/Dockerfile
context: './api'
push: false
load: true
target: api_platform_php_dev
builder: ${{ steps.buildx.outputs.name }}
tags: ecamp/ecamp3-dev-api-php
cache-from: type=gha,scope=api
cache-to: type=gha,scope=api,mode=max
outputs: type=docker,dest=/tmp/ecamp3-dev-api-php.tar
# build caddy (using cache; provide image to docker compose)
- name: Build docker image (Caddy)
uses: docker/build-push-action@v4
with:
file: api/Dockerfile
context: './api'
push: false
load: true
target: api_platform_caddy
builder: ${{ steps.buildx.outputs.name }}
tags: ecamp/ecamp3-dev-api-caddy
cache-from: type=gha,scope=caddy
cache-to: type=gha,scope=caddy,mode=max
outputs: type=docker,dest=/tmp/ecamp3-dev-api-caddy.tar
- uses: actions/upload-artifact@v3
with:
name: e2e-tests-images
path: /tmp/ecamp3-dev-*.tar
e2e-tests-run:
name: 'Tests: End-to-end'
runs-on: ubuntu-latest
needs: e2e-tests-build
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
browser:
- electron
- chrome
- firefox
- edge
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- run: cp .env.ci .env
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Restore tmp folder
uses: actions/download-artifact@v3
with:
name: e2e-tests-images
path: /tmp
- name: Load images
run: |
docker load --input /tmp/ecamp3-dev-api-php.tar
docker load --input /tmp/ecamp3-dev-api-caddy.tar
docker image ls -a --digests
- name: Restore cache volumes (npm, composer)
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3
with:
path: .cache
key: docker-compose-${{ hashFiles('frontend/package-lock.json', 'print/package-lock.json', 'api/composer.lock') }}-${{ matrix.browser }}
restore-keys: |
docker-compose-
# start necessary containers
- run: docker compose up -d php caddy frontend print browserless database docker-host
- uses: cypress-io/github-action@v5
with:
working-directory: e2e
browser: ${{ matrix.browser }}
wait-on: 'http://localhost:3000, http://localhost:3000/api, http://localhost:3000/print/health'
wait-on-timeout: 300
# store screenshots and videos on GitHub as artifacts, for downloading and debugging in case of problems
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-output-${{ matrix.browser }}
path: |
e2e/data/**/*
# print docker container logs (good for debugging; can be disabled again later on)
- run: docker compose logs --tail="all"
if: always()
coveralls-finished:
name: 'Finish coveralls report'
needs:
- api-tests
- frontend-tests
- print-tests
runs-on: ubuntu-latest
steps:
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
ci-passed-event:
name: 'Send out CI success event'
if: github.event_name == 'push' && (github.event.pull_request && github.event.pull_request.number)
needs:
- api-cs-check
- frontend-eslint
- print-eslint
- api-tests
- frontend-tests
- print-tests
- e2e-tests-run
runs-on: ubuntu-latest
steps:
- uses: peter-evans/repository-dispatch@26b39ed245ab8f31526069329e112ab2fb224588 # v2
with:
event-type: ci-passed
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'