-
Notifications
You must be signed in to change notification settings - Fork 20
429 lines (363 loc) · 13 KB
/
node.js.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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ master ]
paths-ignore:
# Can we use '**.md' ?
- 'README.md'
- 'SECURITY.md'
- 'CONTRIBUTING.md'
- 'CODE_OF_CONDUCT.md'
- 'app/README.md'
- 'LICENSE'
- '.gitignore'
pull_request:
branches: [ master ]
jobs:
check-secrets:
runs-on: ubuntu-latest
outputs:
github-token: ${{ steps.github-token.outputs.defined }}
deepsource-token: ${{ steps.github-token.outputs.defined }}
steps:
- id: github-token
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: "${{ env.GITHUB_TOKEN != '' }}"
run: echo "::set-output name=defined::true"
- id: deepsource-token
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
if: "${{ env.DEEPSOURCE_DSN != '' }}"
run: echo "::set-output name=defined::true"
pre_ci:
name: Prepare CI environment
runs-on: ubuntu-latest
outputs:
commit_message: ${{ steps.get_commit_message.outputs.commit_message }}
branch: ${{ steps.extract_branch.outputs.branch }}
steps:
- name: Checkout Project
uses: actions/checkout@v3
with:
# We need to fetch with a depth of 2 for pull_request so we can do HEAD^2
fetch-depth: 2
- name: "Get commit message"
id: get_commit_message
env:
COMMIT_PUSH: ${{ github.event.head_commit.message }}
run: |
COMMIT_MESSAGE="${COMMIT_PUSH:-$(git log --format=%B -n 1 HEAD^2)}"
echo "::set-output name=commit_message::${COMMIT_MESSAGE}"
- name: Extract branch name
id: extract_branch
run: |
TMP_PULL_HEAD_REF="${{ github.head_ref }}"
TMP_GITHUB_REF="${GITHUB_REF#refs/heads/}"
EXPORT_VALUE=""
if [ "${TMP_PULL_HEAD_REF}" != "" ]
then
EXPORT_VALUE="${TMP_PULL_HEAD_REF}"
else
EXPORT_VALUE="${TMP_GITHUB_REF}"
fi
echo "##[set-output name=branch;]${EXPORT_VALUE}"
pre-tests:
name: Install dependencies (if needed)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 12.x
uses: actions/setup-node@v3.6.0
with:
node-version: 12.x
- name: Manage cache
uses: actions/cache@v3
with:
path: |
app/node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn install
working-directory: ./app
run: yarn --color --immutable
test-build:
needs: [pre-tests]
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node-version }}
- name: Manage cache
uses: actions/cache@v3
with:
path: |
app/node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn build
working-directory: ./app
run: yarn build
- uses: actions/upload-artifact@v3
# Same condition as `publish`job
if: ${{ !contains(github.event.head_commit.message, '#no-publish') && (( github.event_name == 'pull_request' && github.event.pull_request.merged == true ) || github.ref == 'refs/heads/master' ) }}
with:
name: built-app
path: docs
if-no-files-found: error
retention-days: 5
test-code:
needs: [check-secrets, pre-tests]
name: Test code and generate test coverage value
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
# Map a step output to a job output
outputs:
coverage: ${{ steps.coverage.outputs.coverage }}
coverage-rounded-display: ${{ steps.coverage.outputs.coverage-rounded-display }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node-version }}
- name: Manage cache
uses: actions/cache@v3
with:
path: |
app/node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn test
working-directory: ./app
run: yarn test:coverage:color
# Coverage badges will be updated on any branch
# and saved into a dedicated one
- name: Check test coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
id: coverage
with:
percentage: 50
exit: 0
rounded-precision: 2
filename: "app/coverage/clover.xml"
test-lint:
needs: [pre-tests]
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node-version }}
- name: Manage cache
uses: actions/cache@v3
with:
path: |
app/node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: Get test coverage for DeepSource
working-directory: ./app
run: yarn lint
test-code-deepsource:
needs: [check-secrets, pre-tests]
if: ${{ needs.check-secrets.outputs.deepsource-token == 'true' }}
name: Get test coverage for DeepSource and report it
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node-version }}
- name: Manage cache
uses: actions/cache@v3
with:
path: |
app/node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: Get test coverage for DeepSource
working-directory: ./app
run: yarn test:coverage:cobertura
- name: Report test coverage to DeepSource
uses: deepsourcelabs/test-coverage-action@master
with:
key: javascript
coverage-file: app/coverage/cobertura-coverage.xml
dsn: ${{ secrets.DEEPSOURCE_DSN }}
test:
name: Tests waiter
# No need to wait for deepsource test and report
needs: [test-code, test-build, test-lint]
runs-on: ubuntu-latest
outputs:
coverage: ${{ needs.test-code.outputs.coverage }}
coverage-rounded-display: ${{ needs.test-code.outputs.coverage-rounded-display }}
steps:
- name: Check test coverage
env:
COVERAGE: ${{ needs.test-code.outputs.coverage }}
COVERAGE_ROUNDED: ${{ needs.test-code.outputs.coverage-rounded-display }}
run: |
echo "Coverage: ${COVERAGE}"
echo "Coverage Rounded: ${COVERAGE_ROUNDED}"
comment_pr:
name: Comment on PR with test coverage value
needs: [test, pre_ci]
if: ${{ github.event_name == 'pull_request' && github.actor == github.repository_owner && !contains(needs.pre_ci.outputs.commit_message, '#comment-badge') }}
runs-on: ubuntu-latest
steps:
- name: Generate comment file with test coverage
env:
COVERAGE: ${{ needs.test.outputs.coverage-rounded-display }}
run: |
echo "**Test coverage: ${COVERAGE}**" > output.md
- name: Comment PR with test coverage
uses: machine-learning-apps/pr-comment@1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: output.md
badge:
# Only generate and publish if these conditions are met:
# - The test step ended successfully
# - One of these is met:
# - This is a pull request event and the pull actor is the same as the repo owner
# - This is a push event and the push event is on branch 'master'
name: Generate badge image with test coverage value
needs: [test, pre_ci]
if: ${{ ( github.event_name == 'pull_request' && github.actor == github.repository_owner ) || github.ref == 'refs/heads/master' }}
outputs:
url: ${{ steps.url.outputs.url }}
markdown: ${{ steps.url.outputs.markdown }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: badges
path: badges
# Use the output from the `coverage` step
- name: Generate the badge SVG image
uses: emibcn/badge-action@v2.0.2
id: badge
with:
label: 'Coverage'
status: ${{ needs.test.outputs.coverage-rounded-display }}
color: ${{
needs.test.outputs.coverage > 90 && 'green' ||
needs.test.outputs.coverage > 80 && 'yellow,green' ||
needs.test.outputs.coverage > 70 && 'yellow' ||
needs.test.outputs.coverage > 60 && 'orange,yellow' ||
needs.test.outputs.coverage > 50 && 'orange' ||
needs.test.outputs.coverage > 40 && 'red,orange' ||
needs.test.outputs.coverage > 30 && 'red,red,orange' ||
needs.test.outputs.coverage > 20 && 'red,red,red,orange' ||
'red' }}
path: badges/test-coverage.svg
- name: Commit badge
env:
BRANCH: ${{ needs.pre_ci.outputs.branch }}
FILE: 'test-coverage.svg'
working-directory: ./badges
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
mkdir -p "${BRANCH}"
mv "${FILE}" "${BRANCH}"
git add "${BRANCH}/${FILE}"
# Will give error if badge did not changed
git commit -m "Add/Update badge" || true
- name: Push badge commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: badges
directory: badges
- name: Badge image URL
id: url
env:
BRANCH: ${{ needs.pre_ci.outputs.branch }}
FILE: 'test-coverage.svg'
COVERAGE: ${{ needs.test.outputs.coverage-rounded-display }}
run: |
URL="https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/badges/${BRANCH}/${FILE}"
MARKDOWN="![Coverage ${COVERAGE}](${URL})"
echo "Badge URL: ${URL}"
echo "Badge image for Markdown: ${MARKDOWN}"
echo "##[set-output name=url;]${URL}"
echo "##[set-output name=markdown;]${MARKDOWN}"
comment_pr_badge:
name: Comment on PR with generated badge
needs: [pre_ci, badge]
if: ${{ github.event_name == 'pull_request' && github.actor == github.repository_owner && contains(needs.pre_ci.outputs.commit_message, '#comment-badge') }}
runs-on: ubuntu-latest
steps:
- name: Generate comment file with test coverage badge
env:
BADGE: ${{ needs.badge.outputs.markdown }}
run: |
echo "Badge: ${BADGE}"
echo "${BADGE}" > output.md
- name: Comment PR with test coverage badge
uses: machine-learning-apps/pr-comment@1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: output.md
publish:
# Only generate and publish if these conditions are met:
# - Commit message does not contains #no-publish
# - The test step ended successfully
# - One of these is met:
# - This is a pull request event and the pull has been merged
# - This is a push event and the push event is on branch 'master'
name: Publish code to GitHub Pages
needs: [pre_ci, test]
if: ${{ !contains(github.event.head_commit.message, '#no-publish') && (( github.event_name == 'pull_request' && github.event.pull_request.merged == true ) || github.ref == 'refs/heads/master' ) }}
runs-on: ubuntu-latest
steps:
- name: Download built app from artifact
uses: actions/download-artifact@v3
with:
name: built-app
path: docs
- name: Deploy to GitHub Pages
uses: crazy-max/ghaction-github-pages@v3
with:
target_branch: gh-pages
build_dir: docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Delete the built app artifact: it's no needed anymore
- uses: geekyeggo/delete-artifact@v2
with:
name: built-app