Repository navigation
289 lines (276 loc) · 12.6 KB
/
Copy pathcli-minimum-node.yml
File metadata and controls
289 lines (276 loc) · 12.6 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
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
# Copyright (c) Meta Platforms, Inc. and affiliates.
# The CLI on its declared minimum Node. Once a day, and when started by hand,
# on main only: runs the CLI's tests and the global-mode smoke on the lowest
# version packages/cli's `engines.node` allows (not .nvmrc, which names the
# version the rest of CI uses). A failure opens, or comments on, one issue; a
# later passing run closes it (.github/scripts/cli-minimum-node.mjs). It never
# runs on pull requests.
name: CLI on minimum Node
on:
schedule:
- cron: '23 7 * * *'
workflow_dispatch:
permissions: {}
concurrency:
group: cli-minimum-node
cancel-in-progress: false
jobs:
version:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
outputs:
node: ${{ steps.minimum.outputs.node }}
legs: ${{ steps.legs.outputs.legs }}
shards: ${{ steps.legs.outputs.shards }}
steps:
- uses: actions/checkout@v7
with:
# The script and every module it imports.
sparse-checkout: |
.github/scripts/cli-minimum-node.mjs
.github/scripts/node-time-drift.mjs
.github/scripts/lib/a11y-spec-files.mjs
scripts/lib/duration-split.mjs
scripts/vitest-node-legs.mjs
scripts/vitest-node-files.mjs
scripts/vitest-node-durations.json
scripts/vitest-node-durations.min-node.json
packages/cli/package.json
packages/cli/api/theme-edit/*.test.mjs
sparse-checkout-cone-mode: false
persist-credentials: false
# As many legs as keep the slowest near 20 minutes on this Node, by its
# own record (scripts/vitest-node-legs.mjs). When the plan cannot run,
# the legs read their fallback count.
- name: Plan the CLI's legs on the minimum Node
id: legs
continue-on-error: true
run: node scripts/vitest-node-legs.mjs plan --min-node --github-output
- name: Read the CLI's minimum Node
id: minimum
run: |
node=$(node .github/scripts/cli-minimum-node.mjs minimum --package packages/cli/package.json)
echo "The CLI declares Node $node as its minimum."
echo "node=$node" >> "$GITHUB_OUTPUT"
# The CLI's tests, in the legs the version job plans, split by this Node's
# own recorded times (scripts/vitest-node-durations.min-node.json, read by
# scripts/vitest-shard-sequencer.mjs): in one job they outgrew its time
# limit on the minimum Node, where every gather is fresh.
cli-tests:
needs: version
name: cli-tests (${{ matrix.shard }}/${{ needs.version.outputs.legs || 6 }})
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
strategy:
fail-fast: false
matrix:
shard: ${{ fromJSON(needs.version.outputs.shards || '[1, 2, 3, 4, 5, 6]') }}
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
# Installs with .nvmrc's Node, then switches to the minimum for the run.
- uses: ./.github/actions/setup
- uses: actions/setup-node@v7
with:
node-version: ${{ needs.version.outputs.node }}
package-manager-cache: false
# The shard watchdog stops the leg before the job limit and names the
# file still running (scripts/vitest-shard-watchdog.mjs).
- name: Run this leg of the CLI's tests on Node ${{ needs.version.outputs.node }}
id: tests
env:
SHARD: ${{ matrix.shard }}
LEGS: ${{ needs.version.outputs.legs || 6 }}
# The legs pack by this Node's own times, not the main Node legs'.
VITEST_DURATIONS_FILE: scripts/vitest-node-durations.min-node.json
VITEST_SHARD_TIMES_FILE: ${{ runner.temp }}/min-node-times.json
run: |
node --version
started=$(ps -o etimes= -C Runner.Worker 2>/dev/null | sort -n | tail -1 | tr -d ' ')
VITEST_SHARD_WATCHDOG_SECONDS=$(( 28 * 60 - ${started:-180} ))
export VITEST_SHARD_WATCHDOG_SECONDS
set -o pipefail
pnpm -F @astryxdesign/cli test --shard="$SHARD/$LEGS" \
--reporter=default --reporter=github-actions \
--reporter=./scripts/vitest-shard-watchdog.mjs 2>&1 | tee "$RUNNER_TEMP/cli-tests.log"
# pass, fail, or none. A failed test is fail even when the watchdog then
# stopped the leg; a leg the watchdog stopped with no failure judged
# nothing (none). A leg the job limit cancels uploads no verdict, which
# also means none.
- name: Record this leg's verdict
if: always() && steps.tests.outcome != 'skipped'
env:
OUTCOME: ${{ steps.tests.outcome }}
SHARD: ${{ matrix.shard }}
LEGS: ${{ needs.version.outputs.legs || 6 }}
run: |
# Vitest colours its lines on CI: read the log without the colour codes.
log="$RUNNER_TEMP/cli-tests.plain.log"
sed $'s/\x1b\\[[0-9;]*m//g' "$RUNNER_TEMP/cli-tests.log" > "$log" 2>/dev/null || : > "$log"
if [ "$OUTCOME" = success ]; then verdict=pass
# A failed test (×), a failed file that ran no test or whose hook threw
# (❯), or the summary (FAIL): only a failure prints any of them.
elif grep -qE '^ *(FAIL |×|❯ )' "$log" 2>/dev/null; then verdict=fail
elif grep -q 'Node shard stuck' "$log" 2>/dev/null; then verdict=none
elif [ "$OUTCOME" = failure ]; then verdict=fail
else verdict=none
fi
echo "Leg $SHARD/$LEGS: $verdict"
mkdir -p verdict
printf '{"shard": %s, "verdict": "%s"}\n' "$SHARD" "$verdict" > "verdict/leg-$SHARD.json"
- name: Keep this leg's verdict
if: always() && steps.tests.outcome != 'skipped'
uses: actions/upload-artifact@v7
with:
name: cli-tests-verdict-${{ matrix.shard }}
path: verdict/leg-${{ matrix.shard }}.json
retention-days: 7
# A warning, never a failure: a scheduled run has no change to fix.
- name: Name the files past their minimum-Node time
if: always() && steps.tests.outcome != 'skipped'
run: node .github/scripts/cli-minimum-node.mjs slow --times "$RUNNER_TEMP/min-node-times.json" --record scripts/vitest-node-durations.min-node.json
- name: Keep this leg's times
if: always() && steps.tests.outcome != 'skipped'
uses: actions/upload-artifact@v7
with:
name: min-node-times-${{ matrix.shard }}
path: ${{ runner.temp }}/min-node-times.json
if-no-files-found: ignore
retention-days: 7
pack:
needs: version
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: ./.github/actions/setup
- name: Pack CLI and Core
run: |
mkdir -p "$RUNNER_TEMP/packs"
pnpm -F @astryxdesign/build build
pnpm -F @astryxdesign/core pack --pack-destination "$RUNNER_TEMP/packs"
pnpm -F @astryxdesign/cli pack --pack-destination "$RUNNER_TEMP/packs"
- uses: actions/upload-artifact@v7
with:
name: minimum-node-packs
path: ${{ runner.temp }}/packs/*.tgz
if-no-files-found: error
smoke:
needs: [version, pack]
runs-on: ubuntu-latest
timeout-minutes: 45
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
sparse-checkout: .github/scripts/cli-global-mode-smoke.mjs
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: ${{ needs.version.outputs.node }}
package-manager-cache: false
- uses: actions/download-artifact@v8
with:
name: minimum-node-packs
path: packs
- name: Global-mode smoke on Node ${{ needs.version.outputs.node }}
run: |
node --version
node .github/scripts/cli-global-mode-smoke.mjs --packs packs --out results.json
- uses: actions/upload-artifact@v7
if: always()
with:
name: minimum-node-smoke-results
path: results.json
report:
needs: [version, cli-tests, pack, smoke]
# Runs after every outcome but a cancel, so a failure is always reported.
if: always() && !cancelled() && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@v7
with:
# The CLI's test files too, so the refreshed record drops a deleted one.
sparse-checkout: |
.github/scripts/cli-minimum-node.mjs
.github/scripts/node-time-drift.mjs
scripts/lib/duration-split.mjs
scripts/vitest-node-durations.min-node.json
packages/cli/**/*.test.*
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Read the legs' times
uses: actions/download-artifact@v8
continue-on-error: true
with:
pattern: min-node-times-*
path: times
- name: Read the legs' verdicts
uses: actions/download-artifact@v8
continue-on-error: true
with:
pattern: cli-tests-verdict-*
path: verdicts
merge-multiple: true
# A failed test fails the run; a leg with no verdict (stopped or cancelled
# at its time limit) makes the run's verdict none, which never closes the
# issue or calls the CLI failed.
- name: Open, update or close the minimum-Node issue
uses: actions/github-script@v9
env:
VERSION_RESULT: ${{ needs.version.result }}
PACK_RESULT: ${{ needs.pack.result }}
SMOKE_RESULT: ${{ needs.smoke.result }}
NODE_VERSION: ${{ needs.version.outputs.node || 'unknown' }}
LEGS: ${{ needs.version.outputs.legs || 6 }}
VERDICTS: ${{ github.workspace }}/verdicts
TIMES: ${{ github.workspace }}/times
with:
script: |
const {reportIssue, runVerdict, readLegVerdicts, readLegTimes, slowFiles, refreshRecord} = await import(`${process.env.GITHUB_WORKSPACE}/.github/scripts/cli-minimum-node.mjs`);
const fs = require('node:fs');
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
// This run's times: the refreshed record, and the files past theirs.
const recordFile = `${process.env.GITHUB_WORKSPACE}/scripts/vitest-node-durations.min-node.json`;
const record = JSON.parse(fs.readFileSync(recordFile, 'utf8'));
const times = readLegTimes(process.env.TIMES);
fs.mkdirSync(`${process.env.GITHUB_WORKSPACE}/refreshed`, {recursive: true});
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/refreshed/vitest-node-durations.min-node.json`, `${JSON.stringify(refreshRecord(record, times, {source: `CLI on minimum Node run ${context.runId} (Node ${process.env.NODE_VERSION})`, exists: file => fs.existsSync(`${process.env.GITHUB_WORKSPACE}/${file}`)}), null, 2)}\n`);
const slow = slowFiles(times, record.seconds ?? {});
core.summary.addHeading('Files past their minimum-Node time', 3);
core.summary.addRaw(slow.length ? slow.map(({file, recorded, measured}) => `- \`${file}\`: ${measured} s (recorded ${recorded} s)`).join('\n') : `None of the ${Object.keys(times).length} timed files.`, true);
await core.summary.write();
const verdict = runVerdict({
version: process.env.VERSION_RESULT,
legs: readLegVerdicts(process.env.VERDICTS, Number(process.env.LEGS)),
pack: process.env.PACK_RESULT,
smoke: process.env.SMOKE_RESULT,
});
const done = await reportIssue({github, context, verdict, version: process.env.NODE_VERSION, runUrl});
core.info(`minimum-Node verdict: ${verdict}; issue: ${done}`);
if (verdict === 'fail') core.setFailed(`The CLI failed on Node ${process.env.NODE_VERSION}.`);
if (verdict === 'none') core.setFailed(`No verdict on Node ${process.env.NODE_VERSION}: a part of the run stopped or was cancelled before it judged anything.`);
- name: Keep the refreshed minimum-Node record
if: always()
uses: actions/upload-artifact@v7
with:
name: min-node-record
path: refreshed/vitest-node-durations.min-node.json
if-no-files-found: ignore
retention-days: 14