-
Notifications
You must be signed in to change notification settings - Fork 2
214 lines (173 loc) · 6.81 KB
/
node-test.yaml
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
on:
workflow_call:
inputs:
upgrade-policy:
description: "Node.js version upgrade policy. Allowed values: `lts` (default), `lts/strict`, `all`."
default: lts
required: false
type: string
runs-on:
description: "Comma separated list (or a string with an array in YAML) of runner labels, see https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on."
default: "ubuntu-latest"
required: false
type: string
include:
description: "A string with additional matrix combinations as a YAML array of objects with the following keys: node-version, runs-on, experimental"
default: "[]"
required: false
type: string
exclude:
description: "A string with matrix combinations to be skipped as a YAML array of objects with the following keys: node-version, runs-on"
default: "[]"
required: false
type: string
post-checkout-steps:
description: "Steps to execute after checkout (i.e. before installing dependencies)"
required: false
type: string
post-install-steps:
description: "Steps to execute after installing dependencies (i.e. before running tests)"
required: false
type: string
post-test-steps:
description: "Steps to execute after the tests complete"
required: false
type: string
strategy-fail-fast:
description: "Set to true to cancel the workflow as soon as the first matrix combo fails. Note: default here is different than the Github Actions default."
default: false
required: false
type: boolean
strategy-max-parallel:
description: "The maximum number of matrix jobs that can run simultaneously."
default: 0
required: false
type: number
timeout-minutes:
description: "The maximum number of minutes to let a job run before GitHub automatically cancels it."
default: 30
required: false
type: number
test-command:
description: "Command to run instead of `npm test` (e.g. for coverage)."
default: npm test
required: false
type: string
secrets:
test-secrets:
description: "A JSON object with the secret environment variables to be set for the 'Run tests' step. Values will be masked in output."
required: false
jobs:
prepare-node-matrix:
runs-on: ubuntu-latest
outputs:
node-version: ${{ steps.set-matrix.outputs.node-version }}
runs-on: ${{ steps.set-matrix.outputs.runs-on }}
lts-latest: ${{ steps.set-matrix.outputs.lts-latest }}
include: ${{ steps.set-matrix.outputs.include }}
exclude: ${{ steps.set-matrix.outputs.exclude }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare the matrix
uses: pkgjs/action/.github/actions/prepare-node-test-matrix-action@v0.1.9
id: set-matrix
with:
upgrade-policy: ${{ inputs.upgrade-policy }}
runs-on: ${{ inputs.runs-on }}
include: ${{ inputs.include }}
exclude: ${{ inputs.exclude }}
test:
needs: prepare-node-matrix
timeout-minutes: ${{ inputs.timeout-minutes }}
strategy:
fail-fast: ${{ inputs.strategy-fail-fast }}
max-parallel: ${{ inputs.strategy-max-parallel }}
matrix:
node-version: ${{ fromJson(needs.prepare-node-matrix.outputs.node-version) }}
runs-on: ${{ fromJson(needs.prepare-node-matrix.outputs.runs-on) }}
include: ${{ fromJson(needs.prepare-node-matrix.outputs.include) }}
exclude: ${{ fromJson(needs.prepare-node-matrix.outputs.exclude) }}
experimental: [null]
runs-on: ${{ matrix.runs-on || 'ubuntu-latest' }}
continue-on-error: ${{ !!matrix.experimental }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare post-checkout steps
if: ${{ inputs.post-checkout-steps }}
uses: pkgjs/action/.github/actions/prepare-dynamic-steps@v0.1.9
with:
steps: ${{ inputs.post-checkout-steps }}
path: post-checkout-steps
- name: Prepare post-install steps
if: ${{ inputs.post-install-steps }}
uses: pkgjs/action/.github/actions/prepare-dynamic-steps@v0.1.9
with:
steps: ${{ inputs.post-install-steps }}
path: post-install-steps
- name: Prepare post-test steps
if: ${{ inputs.post-test-steps }}
uses: pkgjs/action/.github/actions/prepare-dynamic-steps@v0.1.9
with:
steps: ${{ inputs.post-test-steps }}
path: post-test-steps
- name: Setup Node.js@${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Print version information
run: |
echo OS: $(node -p "os.version()")
echo Node.js: $(node --version)
echo npm: $(npm --version)
echo git: $(git --version)
- name: Run post-checkout steps
if: ${{ inputs.post-checkout-steps }}
uses: ./.github/tmp/post-checkout-steps
- name: Prepare install script
id: prepare-install-script
shell: bash
run: |
if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ] || [ -f yarn.lock ]
then
echo "install-command=npm ci" >> $GITHUB_OUTPUT
else
echo "install-command=npm install" >> $GITHUB_OUTPUT
fi
- name: Install dependencies
run: ${{ steps.prepare-install-script.outputs.install-command }}
env:
MATRIX_NODE_VERSION: ${{ matrix.node-version }}
NODE_LTS_LATEST: ${{ needs.prepare-node-matrix.outputs.lts-latest }}
- name: Run post-install steps
if: ${{ inputs.post-install-steps }}
uses: ./.github/tmp/post-install-steps
- name: Print installed dependencies
run: npm ls --all
continue-on-error: true
- name: Set environment variables for tests
id: set-env-vars-for-tests
shell: bash
run: |
# mask all values in the input vars
echo ${INPUT_VARS} | jq -c -r '.[] | "::add-mask::" + .'
# set the matrix variables into env for tests
MERGED_VARS=$(cat <<EOF | jq -c -s '.[0] * .[1]'
${INPUT_VARS}
{
"MATRIX_NODE_VERSION":"${{ matrix.node-version }}",
"NODE_LTS_LATEST":"${{ needs.prepare-node-matrix.outputs.lts-latest }}"
}
EOF
)
# output the merged variables
echo "env-vars=${MERGED_VARS}" >> $GITHUB_OUTPUT
env:
INPUT_VARS: ${{ secrets.test-secrets || '{}' }}
- name: Run tests
run: ${{ inputs.test-command }}
env: ${{ fromJson(steps.set-env-vars-for-tests.outputs.env-vars || '{}') }}
- name: Run post-test steps
if: ${{ inputs.post-test-steps }}
uses: ./.github/tmp/post-test-steps