-
Notifications
You must be signed in to change notification settings - Fork 7
109 lines (106 loc) · 4.66 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
# 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:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
name: lint
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.11.1
uses: actions/setup-node@v4
with:
node-version: 20.11.1
- run: | # retry since mongo memory server fails to download sometimes
yarn install || yarn install
- run: npm run build --if-present
- name: lint
run: |
npm run lint
build:
runs-on: ubuntu-latest
name: test (chunk ${{ matrix.chunk }})
strategy:
matrix:
shard: [ 1, 2, 3, 4, 5, 6, 7, 8 ]
fail-fast: false
outputs:
jest_outcome: ${{ steps.output_variables.outputs.jest_outcome }}
coverage_line: ${{ steps.output_variables.outputs.coverage_line }}
coverage_statement: ${{ steps.output_variables.outputs.coverage_statement }}
coverage_branch: ${{ steps.output_variables.outputs.coverage_branch }}
coverage_function: ${{ steps.output_variables.outputs.coverage_function }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.11.1
uses: actions/setup-node@v4
with:
node-version: 20.11.1
- run: | # retry since mongo memory server fails to download sometimes
yarn install || yarn install
- run: npm run build --if-present
- name: show memory
run: |
export NODE_OPTIONS="--max-old-space-size=8192"
NODE_OPTIONS=--max-old-space-size=8192 node --max-old-space-size=8192 ./src/utils/showMemory.js
env:
NODE_OPTIONS: "--max-old-space-size=10240"
- name: jest
id: jest
run: |
export NODE_OPTIONS="--max-old-space-size=8192"
NODE_OPTIONS=--max-old-space-size=8192 node --max-old-space-size=8192 ./node_modules/.bin/jest --no-watchman --silent --logHeapUsage --bail --runInBand --forceExit --shard=${{ matrix.shard }}/${{ strategy.job-total }} --coverage
env:
NODE_OPTIONS: "--max-old-space-size=10240"
- name: Set output variables for badges
id: output_variables
run: |
jest_outcome=${{ steps.jest.outcome }}
echo "jest_outcome=$jest_outcome" >> $GITHUB_OUTPUT
echo "Output of my_step: ${{ steps.jest.outcome }}"
coverage_line=$(jq -r '.total.lines.pct' coverage/coverage-summary.json)
coverage_statement=$(jq -r '.total.statements.pct' coverage/coverage-summary.json)
coverage_branch=$(jq -r '.total.branches.pct' coverage/coverage-summary.json)
coverage_function=$(jq -r '.total.functions.pct' coverage/coverage-summary.json)
echo "coverage_line=$coverage_line" >> $GITHUB_OUTPUT
echo "coverage_statement=$coverage_statement" >> $GITHUB_OUTPUT
echo "coverage_branch=$coverage_branch" >> $GITHUB_OUTPUT
echo "coverage_function=$coverage_function" >> $GITHUB_OUTPUT
- name: Rename coverage file name
if: github.ref == 'refs/heads/main'
run: mv coverage/coverage-final.json coverage/${{matrix.shard}}.json
- name: Upload coverage file
uses: actions/upload-artifact@v3
if: github.ref == 'refs/heads/main'
with:
name: coverage-artifacts
path: coverage/
create-badges:
runs-on: ubuntu-latest
if: ${{ always() }}
needs: build
steps:
- name: Create Test Cases Status Badges
uses: peterrhodesdev/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
filename: testcases_status
label: Test cases status
message: ${{ needs.build.outputs.jest_outcome }}
color: ${{ needs.build.outputs.jest_outcome == 'success' && '009900' || 'FF0000' }}
- name: Create Test Cases Coverage Badges
uses: peterrhodesdev/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
filename: ("testcases_coverage_line" "testcases_coverage_statement" "testcases_coverage_branch" "testcases_coverage_function")
label: ("Test cases coverage [Line]" "Test cases coverage [Statement]" "Test cases coverage [Branch]" "Test cases coverage [Function]")
message: (${{ needs.build.outputs.coverage_line }} ${{ needs.build.outputs.coverage_statement }} ${{ needs.build.outputs.coverage_branch }} ${{ needs.build.outputs.coverage_function }})
color: 993366