-
Notifications
You must be signed in to change notification settings - Fork 1
363 lines (316 loc) · 11.9 KB
/
cicd-app.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
name: CI/CD Back & Front
on:
push:
paths:
- ".github/workflows/cicd-database.yml"
- ".github/workflows/cicd-app.yml"
- "infra/**"
- "backend/**"
- "frontend/**"
- "Makefile"
- ".env*"
- "docker-compose.yml"
schedule:
- cron: "38 11 */3 * *"
jobs:
version:
name: Set application version and env profile
runs-on: ubuntu-22.04
outputs:
ENV_PROFILE: ${{ steps.env_profile.outputs.ENV_PROFILE }}
VERSION: ${{ steps.version.outputs.VERSION }}
steps:
- name: Get last release version
id: lastrelease
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: mtes-mct/monitorenv
- id: step1
name: Set ENV profile as dev by default
run: echo "ENV_PROFILE=dev" >> $GITHUB_ENV
- name: Set ENV profile as PROD when it is a release
if: startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/heads/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/heads/v2')
run: echo "ENV_PROFILE=prod" >> $GITHUB_ENV
- id: env_profile
name: Set ENV profile output
run: ENV_PROFILE=${{ env.ENV_PROFILE }} && echo "ENV_PROFILE=$ENV_PROFILE" >> $GITHUB_OUTPUT
- id: version
name: Set VERSION env
run: |
if [ "${ENV_PROFILE}" != "prod" ]; then\
if [ "${{github.ref}}" == "refs/heads/main" ]; then\
export VERSION=${{ steps.lastrelease.outputs.release }}_snapshot
else\
export REF_NAME=${{ github.ref_name }}
export VERSION=${REF_NAME//\//_}
fi
else\
export VERSION=${{ steps.lastrelease.outputs.release }}
fi
echo $VERSION
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
unit_test_backend:
name: Run backend unit tests
needs: version
runs-on: ubuntu-22.04
env:
ENV_PROFILE: ${{needs.version.outputs.ENV_PROFILE}}
VERSION: ${{needs.version.outputs.VERSION}}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Show version
run: echo "VERSION:${{ env.VERSION }} ENV_PROFILE:${{ env.ENV_PROFILE }}"
- name: Setup Java JDK
uses: actions/setup-java@v4.4.0
with:
# https://github.com/actions/setup-java/blob/main/README.md#Supported-distributions
distribution: zulu
java-version: 17
- name: Checkout
uses: actions/checkout@v4
- name: Unit test
run: make test-back
unit_test_frontend:
name: Run frontend unit tests
needs: version
runs-on: ubuntu-22.04
env:
PUPPETEER_SKIP_DOWNLOAD: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: npm
cache-dependency-path: ./frontend/package-lock.json
node-version: 20
- name: Install Node.js dependencies
run: npm ci
working-directory: ./frontend
- name: Lint Frontend
run: npm run test:lint
working-directory: ./frontend
- name: Check Frontend types
run: npm run test:type
working-directory: ./frontend
- name: Unit test
run: npm run test:unit --coverage
working-directory: ./frontend
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
working-directory: ./frontend
build:
name: Build and package
needs: version
runs-on: ubuntu-22.04
env:
ENV_PROFILE: ${{needs.version.outputs.ENV_PROFILE}}
VERSION: ${{needs.version.outputs.VERSION}}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Show version
run: echo "VERSION:${{ env.VERSION }} ENV_PROFILE:${{ env.ENV_PROFILE }}"
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache-app
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
load: true
builder: ${{ steps.buildx.outputs.name }}
file: infra/docker/app/Dockerfile
push: false
tags: monitorenv-app:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache-app
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-app-new
build-args: |
VERSION=${{ env.VERSION }}
ENV_PROFILE=${{ env.ENV_PROFILE }}
GITHUB_SHA=${{ github.sha }}
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache-app
mv /tmp/.buildx-cache-app-new /tmp/.buildx-cache-app
- name: Upload image to artifacts
uses: ishworkh/container-image-artifact-upload@v2.0.0
with:
image: monitorenv-app:${{ env.VERSION }}
e2e_test:
name: Run E2E tests
needs: [ version, build ]
runs-on: ubuntu-22.04
strategy:
# when one test fails, DO NOT cancel the other
# containers, because this will kill Cypress processes
# leaving the Dashboard hanging ...
# https://github.com/cypress-io/github-action/issues/48
fail-fast: false
matrix:
containers: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
ENV_PROFILE: ${{needs.version.outputs.ENV_PROFILE}}
FRONTEND_GOOGLEMAPS_API_KEY: ${{ secrets.FRONTEND_GOOGLEMAPS_API_KEY }}
FRONTEND_SHOM_KEY: ${{ secrets.FRONTEND_SHOM_KEY }}
FRONTEND_MAPBOX_KEY: ${{ secrets.FRONTEND_MAPBOX_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MONITORENV_VERSION: ${{ needs.version.outputs.VERSION }}
VERSION: ${{needs.version.outputs.VERSION}}
PUPPETEER_SKIP_DOWNLOAD: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download image
uses: ishworkh/container-image-artifact-download@v2.0.0
with:
image: monitorenv-app:${{ env.VERSION }}
- name: Run docker images
run: |
make test-init-infra-env
make test-run-infra-for-frontend
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: npm
cache-dependency-path: ./frontend/package-lock.json
node-version: 20
- name: Setup Firefox
uses: browser-actions/setup-firefox@latest
with:
firefox-version: 119.0.1
- name: Curl stubbed geoserver check
run: until $(curl --output /dev/null --silent --fail "http://localhost:8081/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=monitorenv:regulations&outputFormat=application/json&CQL_FILTER=topic=%27Ouest%20Cotentin%20Bivalves%27%20AND%20zone=%27Praires%20Ouest%20cotentin%27"); do printf '.'; sleep 5; done;
- uses: cypress-io/github-action@v6
with:
browser: firefox
cache-key: cypress-${{ hashFiles('package-lock.json') }}
config-file: config/cypress.config.ts
env: PORT=8880
install: true
install-command: npm ci
parallel: true
record: true
wait-on: "http://localhost:8880"
working-directory: ./frontend
- name: Display Docker container logs for debugging
if: failure()
run: docker logs monitorenv_backend
e2e_multi_windows_test:
name: Run E2E multi windows tests
needs: [ version, build ]
runs-on: ubuntu-22.04
if: false
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
ENV_PROFILE: ${{needs.version.outputs.ENV_PROFILE}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MONITORENV_VERSION: ${{ needs.version.outputs.VERSION }}
VERSION: ${{needs.version.outputs.VERSION}}
PUPPETEER_SKIP_DOWNLOAD: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: browser-actions/setup-chrome@v1
with:
chrome-version: 120
- name: Download image
uses: ishworkh/container-image-artifact-download@v2.0.0
with:
image: monitorenv-app:${{ env.VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: npm
cache-dependency-path: ./frontend/package-lock.json
node-version: 20
- name: Install Node.js dependencies
run: npm ci
working-directory: ./frontend
- name: Install Firefox
run: npx puppeteer browsers install firefox
- name: Run docker images
run: |
make test-init-infra-env
make test-run-infra-for-frontend
until $(curl --output /dev/null --silent --fail "http://localhost:8081/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typename=monitorenv:regulations&outputFormat=application/json&CQL_FILTER=topic=%27Ouest%20Cotentin%20Bivalves%27%20AND%20zone=%27Praires%20Ouest%20cotentin%27"); do printf '.'; sleep 5; done;
- name: Run multi-windows tests
run: npm run test:multi-windows:run
working-directory: ./frontend
generate_and_upload_source_maps:
name: Generate and upload source maps to Sentry
needs: [ version, build, unit_test_backend, unit_test_frontend, e2e_test ]
runs-on: ubuntu-22.04
env:
VERSION: ${{ needs.version.outputs.VERSION }}
SENTRY_URL: ${{ secrets.SENTRY_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 100
- name: Download image
uses: ishworkh/container-image-artifact-download@v2.0.0
with:
image: monitorenv-app:${{ env.VERSION }}
- name: Extract frontend build files
run: |
docker create --name monitorenv-temp monitorenv-app:${{ env.VERSION }}
docker cp monitorenv-temp:/home/monitorenv/public/assets ./frontend_build
docker rm monitorenv-temp
- name: Generate and upload source maps to Sentry
uses: getsentry/action-release@v1
with:
environment: ${{ needs.version.outputs.ENV_PROFILE }}
version: ${{ env.VERSION }}
sourcemaps: ./frontend_build
ignore_missing: true
ignore_empty: true
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_URL: ${{ secrets.SENTRY_URL }}
push_to_registry:
name: Push to registry
needs: [ version, unit_test_backend, unit_test_frontend, e2e_test, generate_and_upload_source_maps ]
# needs: [version, e2e_test, e2e_multi_windows_test, unit_test_frontend, e2e_test]
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/heads/dependabot') == false
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
ENV_PROFILE: ${{needs.version.outputs.ENV_PROFILE}}
VERSION: ${{needs.version.outputs.VERSION}}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download image
uses: ishworkh/container-image-artifact-download@v2.0.0
with:
image: monitorenv-app:${{ env.VERSION }}
- name: Push docker image to registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin
make docker-tag-app
make docker-push-app