-
Notifications
You must be signed in to change notification settings - Fork 0
/
_node.yml
182 lines (164 loc) · 5.5 KB
/
_node.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
name: Reusable node tests workflow
on:
workflow_call:
inputs:
node_versions:
description: Node versions to use
type: string
required: true
working_directory:
description: Path to the package.json file
type: string
required: true
check_packages_licenses:
description: Check if npm packages have a valid license.
type: boolean
required: false
default: true
use_jest:
description: Use jest suite
default: false
type: boolean
required: false
use_react:
description: Use react library
default: false
type: boolean
required: false
use_eslint:
description: Use eslint formatter
default: true
type: boolean
required: false
use_prettier:
description: Use prettier formatter
default: true
type: boolean
required: false
use_stylelint:
description: Use stylelint formatter
default: true
type: boolean
required: false
use_coverage:
description: Output coverage. Require jest to be set.
default: false
type: boolean
required: false
upload_coverage:
description: Upload coverage report to GitHub
default: false
type: boolean
required: false
run_codeql:
description: Run codeql
default: false
type: boolean
required: false
custom_command:
description: String of custom command to run
type: string
required: false
max_timeout:
description: Max time that the CI can be run
type: number
required: false
default: 30
ubuntu_version:
description: Ubuntu version to use
type: string
default: latest
required: false
jobs:
node:
name: Run node.js tests
runs-on: ubuntu-${{ inputs.ubuntu_version }}
timeout-minutes: ${{ inputs.max_timeout }}
strategy:
matrix:
node_version: ${{ fromJson(inputs.node_versions) }}
language: ['javascript']
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
cache: 'npm'
cache-dependency-path: ${{ inputs.working_directory }}/package-lock.json
- name: Add dependencies
run: |
if [[ '${{ inputs.use_jest }}' != 'false' ]]; then
npm i -D --package-lock-only jest @testing-library/jest-dom babel-jest @babel/core @babel/preset-env
if [[ '${{ inputs.use_react }}' != 'false' ]]; then
npm i -D --package-lock-only @testing-library/react @testing-library/jest-dom
fi
fi
if [[ '${{ inputs.use_eslint }}' != 'false' ]]; then
npm i -D --package-lock-only eslint
fi
if [[ '${{ inputs.use_prettier }}' != 'false' ]]; then
npm i -D --package-lock-only prettier
fi
if [[ '${{ inputs.use_stylelint }}' != 'false' ]]; then
npm i -D --package-lock-only stylelint
fi
working-directory: ${{ inputs.working_directory }}
- name: Install packages
run: npm ci
working-directory: ${{ inputs.working_directory }}
- name: Run linters
uses: ./.github/actions/node_linter
with:
working_directory: ${{ inputs.working_directory }}
use_eslint: ${{ inputs.use_eslint == true }}
use_prettier: ${{ inputs.use_prettier == true }}
use_stylelint: ${{ inputs.use_stylelint == true }}
check_packages_licenses: ${{ inputs.check_packages_licenses == true }}
- name: Check packages licenses
if: ${{ inputs.check_packages_licenses }}
id: license_check_report
continue-on-error: true
uses: pilosus/action-pip-license-checker@v2
with:
requirements: ${{ inputs.requirements_path }}
external: ${{ inputs.working_directory }}/licenses.csv
external-format: csv
table-headers: true
fail: 'StrongCopyleft,NetworkCopyleft,Error'
fails-only: true
- name: Run CodeQL
if: inputs.run_codeql
uses: ./.github/actions/codeql
with:
language: javascript
working_directory: ${{ inputs.working_directory }}
- name: Run custom command
if: inputs.custom_command
run: |
COMMAND='${{ inputs.custom_command }}'
echo "Running command: $COMMAND"
eval $COMMAND
working-directory: ${{ inputs.working_directory }}
shell: bash
- name: Run jest tests
if: ${{ inputs.use_jest }}
id: jest-tests
run: |
if [[ '${{ inputs.use_coverage }}' != 'false' ]]; then
CMD="npm test -- --silent --coverage"
else
CMD="npm test"
fi
echo "Running command: ${CMD}"
if [[ '${{ inputs.use_coverage }}' != 'false' ]] && [[ '${{ inputs.upload_coverage }}' != 'false' ]]; then
echo "Uploading jest coverage report"
echo "## Jest coverage report" >> $GITHUB_STEP_SUMMARY
echo "$($CMD | grep -Ev "^(>|$)")" > jest-coverage.txt
head -n -1 jest-coverage.txt | tail -n +2 >> $GITHUB_STEP_SUMMARY
rm jest-coverage.txt
else
$CMD
fi
working-directory: ${{ inputs.working_directory }}
shell: bash