-
-
Notifications
You must be signed in to change notification settings - Fork 74
360 lines (345 loc) Β· 12 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
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
CI: true
FORCE_COLOR: '3' # asks Chalk to use colors in logs of Yarn, Jest, ESLint and many others
jobs:
dependencies:
name: Check dependencies (with audit)
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
decommission:
name: Decommission of user cache
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --prefer-offline --no-audit
- name: count references to usernames cache
shell: bash
run: ./scripts/legacy-refs/check-refs.sh
code-checks:
name: Code checks
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --prefer-offline --no-audit
- name: make build
run: |
make build
echo 'βΉοΈ If this test fails, run `$ npm run build` and commit the changes.'
exit $(git diff | wc -l)
- name: make lint
run: |
make lint
echo 'βΉοΈ If this test fails, run `$ make lint` and commit the changes.'
exit $(git diff | wc -l)
approval-tests:
name: Approval tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.6
ports:
- 27117:27017
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --prefer-offline --no-audit
- name: Approval tests on Hot Tracks
run: npm run test:approval:hot-tracks:start
- name: Approval tests on posting tracks
run: npm run test:approval:posting:start
- name: Approval tests on main routes
run: npm run test:approval:routes:start
unit-tests:
name: Unit tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --prefer-offline --no-audit
- name: Unit tests
run: npm run test:unit:coverage
- name: Get coverage data
run: npm run coverage:report
- name: Save code coverage results
uses: actions/upload-artifact@v3
with:
name: unit-tests-code-coverage-report
path: |
.nyc_output
coverage
functional-tests:
name: Functional tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --prefer-offline --no-audit
- name: Functional tests
run: npm run test:functional:coverage
- name: Get coverage data
run: npm run coverage:report
- name: Save code coverage results
uses: actions/upload-artifact@v3
with:
name: functional-tests-code-coverage-report
path: |
.nyc_output
coverage
integration-tests:
name: Integration tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.6@sha256:146c1fd999a660e697aac40bc6da842b005c7868232eb0b7d8996c8f3545b05d
ports:
- 27117:27017
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --prefer-offline --no-audit
- run: npm run test:api:coverage
- run: npm run test:integration:coverage
- name: Get coverage data
run: npm run coverage:report
- name: Save code coverage results
uses: actions/upload-artifact@v3
with:
name: integration-tests-code-coverage-report
path: |
.nyc_output
coverage
third-party-tests:
name: 3rd-party tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci --prefer-offline --no-audit
- env:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_TEST_APP_ID }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_TEST_API_KEY }}
run: npm run test:3rd-party
cypress-tests:
name: Cypress E2E tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 8
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.6
ports:
- 27117:27017
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:
# run 3 copies of the current job in parallel
containers: [1, 2, 3]
steps:
# to avoid browserVersion mismatch, cf https://github.com/cypress-io/github-action/issues/518#issuecomment-1210979047
- uses: browser-actions/setup-chrome@latest
- run: |
echo "Chrome version: $(chrome --version)"
echo "BROWSER_PATH=$(which chrome)" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvmrc.outputs.node_version }}'
cache: 'npm'
- uses: c-py/action-dotenv-to-setenv@v4
with:
env-file: env-vars-testing.conf
- run: npm ci --prefer-offline --no-audit
- name: Run Cypress tests against Openwhyd server
uses: cypress-io/github-action@v6.5.0
with:
start: npm run start:coverage --mongoDbDatabase openwhyd_test
wait-on: 'http://localhost:8080'
config-file: cypress.config.ts
browser: '${{ env.BROWSER_PATH }}' # chromium/chrome is required to include browser console in cypress logs
install: false
record: true
parallel: true
env:
APPLITOOLS_API_KEY: ${{ secrets.APPLITOOLS_API_KEY }}
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# Recommended: pass the GitHub token lets this action correctly
# determine the unique run id necessary to re-run the checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# DEBUG: 'cypress:server:socket-base'
# ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_TEST_APP_ID }}
# ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_TEST_API_KEY }}
- name: Get coverage data
run: npm run coverage:report # stores the coverage report in coverage/lcov.info
- name: Save code coverage results
uses: actions/upload-artifact@v3
with:
name: cypress-code-coverage-report
path: |
.nyc_output
coverage
# NOTE: screenshots will be generated only if E2E test failed
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: cypress/videos
coverage:
name: Send coverage reports to Codacy
needs:
- cypress-tests
- approval-tests
- unit-tests
- functional-tests
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: cypress-code-coverage-report
path: coverage-cypress/
- uses: actions/download-artifact@v3
with:
name: unit-tests-code-coverage-report
path: coverage-unit-tests/
- uses: actions/download-artifact@v3
with:
name: functional-tests-code-coverage-report
path: coverage-functional-tests/
- uses: actions/download-artifact@v3
with:
name: integration-tests-code-coverage-report
path: coverage-integration-tests/
- name: Merge coverage reports
run: |
mkdir .nyc_output
mkdir coverage-reports
cp coverage-cypress/.nyc_output/*.json coverage-reports
cp coverage-unit-tests/.nyc_output/*.json coverage-reports
cp coverage-functional-tests/.nyc_output/*.json coverage-reports
cp coverage-integration-tests/.nyc_output/*.json coverage-reports
npx --yes nyc merge coverage-reports .nyc_output/merged-coverage.json
npm run coverage:report # stores the coverage report in coverage/lcov.info
- uses: codacy/codacy-coverage-reporter-action@master
with:
project-token: ${{ secrets.CODACY_REPOSITORY_TOKEN_FOR_COVERAGE }}
coverage-reports: coverage/lcov.info
release:
name: Release
needs:
- unit-tests
- integration-tests
- cypress-tests
- third-party-tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
# to prevent "You're not authorized to push to this branch"
persist-credentials: false
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: make release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Create Docker tags
id: create_docker_tags
run: |
echo "tags=latest,$(git tag -l --sort=-v:refname | head -1 | cut -c 2-)" >> $GITHUB_OUTPUT
# from https://github.com/jerray/publish-docker-action/issues/11#issuecomment-607077257
- name: Publish to Docker Hub registry
if: github.event_name == 'push'
uses: jerray/publish-docker-action@v1.0.5
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
tags: ${{ steps.create_docker_tags.outputs.tags }}
docker:
# To publish the Docker image from here, see https://github.com/openwhyd/openwhyd/pull/308/commits/1eacaa98885789642ba0073c9bb4d822021f0d95#diff-12a86cef0c4707531fdbabac3e38cb2aR36
name: Docker tests
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Build and start services
run: docker-compose up --build --detach
# env:
# ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_TEST_APP_ID }}
# ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_TEST_API_KEY }}
- name: Init database for tests
run: make docker-seed
- name: Run integration tests
run: docker-compose exec -T --env MONGODB_URL web npm run test:integration
env:
MONGODB_URL: 'mongodb://mongo:27017/openwhyd_test' # needed by mongodb integration tests (user.repository.tests.js)
- name: Run API tests
run: docker-compose exec -T --env MONGODB_URL web npm run test:api:raw
env:
MONGODB_URL: 'mongodb://mongo:27017/openwhyd_test'
- name: Logs from docker-compose
if: ${{ always() }} # this step is useful to troubleshoot the execution of openwhyd when tests fail
run: docker-compose logs