-
Notifications
You must be signed in to change notification settings - Fork 2
246 lines (201 loc) · 7.69 KB
/
node-test.yaml
File metadata and controls
246 lines (201 loc) · 7.69 KB
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
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
action-repository:
description: "Repository to load the actions from"
default: ${{ github.repository || 'pkgs/action' }}
required: false
type: string
action-ref:
description: "Git ref to load the actions from"
default: ${{ github.ref || 'v0.1.10' }}
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
with:
persist-credentials: false
- name: Checkout action code
uses: actions/checkout@v4
with:
repository: ${{ inputs.action-repository }}
ref: ${{ inputs.action-ref }}
path: infra-actions
persist-credentials: false
- name: Prepare the matrix
uses: ./infra-actions/.github/actions/prepare-node-test-matrix-action
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
with:
persist-credentials: false
- name: Checkout action code
uses: actions/checkout@v4
with:
repository: ${{ inputs.action-repository }}
ref: ${{ inputs.action-ref }}
path: infra-actions
persist-credentials: false
- name: Prepare post-checkout steps
if: ${{ inputs.post-checkout-steps }}
uses: ./infra-actions/.github/actions/prepare-dynamic-steps
with:
steps: ${{ inputs.post-checkout-steps }}
path: post-checkout-steps
- name: Prepare post-install steps
if: ${{ inputs.post-install-steps }}
uses: ./infra-actions/.github/actions/prepare-dynamic-steps
with:
steps: ${{ inputs.post-install-steps }}
path: post-install-steps
- name: Prepare post-test steps
if: ${{ inputs.post-test-steps }}
uses: ./infra-actions/.github/actions/prepare-dynamic-steps
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