Skip to content

Commit f730099

Browse files
committed
Implement simultaneous PR checks for Node.js v20, v24.
Copied from #2006.
1 parent 2e5f63f commit f730099

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

.github/workflows/pr-checks.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
os: [ubuntu-latest, macos-latest, windows-latest]
23+
node-version: [20, 24]
2324
permissions:
2425
contents: read
2526
security-events: write # needed to upload ESLint results
@@ -36,7 +37,7 @@ jobs:
3637
- name: Set up Node.js
3738
uses: actions/setup-node@v5
3839
with:
39-
node-version: 24
40+
node-version: ${{ matrix.node-version }}
4041
cache: 'npm'
4142

4243
- name: Set up Python
@@ -51,7 +52,12 @@ jobs:
5152
npm config set script-shell bash
5253
npm ci
5354
54-
- name: Verify compiled JS up to date
55+
- name: Verify compiled JS up to date (Node.js 20)
56+
if: matrix.node-version == 20
57+
run: .github/workflows/script/check-js-20.sh
58+
59+
- name: Verify compiled JS up to date (Node.js 24)
60+
if: matrix.node-version == 24
5561
run: .github/workflows/script/check-js.sh
5662

5763
- name: Verify PR checks up to date
@@ -70,7 +76,7 @@ jobs:
7076

7177
- name: Upload sarif
7278
uses: github/codeql-action/upload-sarif@v3
73-
if: matrix.os == 'ubuntu-latest'
79+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 24
7480
with:
7581
sarif_file: eslint.sarif
7682
category: eslint
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
# Change @types/node to v20 temporarily to check that the generated JS files are correct.
5+
contents=$(jq '.devDependencies."@types/node" = "^20.0.0"' package.json)
6+
echo "${contents}" > package.json
7+
8+
npm install
9+
10+
if [ ! -z "$(git status --porcelain)" ]; then
11+
git config --global user.email "[email protected]"
12+
git config --global user.name "github-actions[bot]"
13+
# The period in `git add --all .` ensures that we stage deleted files too.
14+
git add --all .
15+
git commit -m "Use @types/node v20"
16+
fi
17+
18+
# Wipe the lib directory in case there are extra unnecessary files in there
19+
rm -rf lib
20+
21+
# Generate the JavaScript files
22+
npm run-script build
23+
24+
# Check that repo is still clean.
25+
# The downgrade of @types/node means that we expect certain changes to the generated JS files.
26+
# Therefore, we should ignore these changes to @types/node and check for outstanding changes.
27+
if [[ $(git diff | grep --perl-regexp '^-(?!--)' | grep --count --invert-match --perl-regexp '"@types/node": "\^24') -gt 0 || \
28+
$(git diff | grep --perl-regexp '^\+(?!\+\+)' | grep --count --invert-match --perl-regexp '"@types/node": "\^20') -gt 0 ]]
29+
then
30+
>&2 echo "Failed: JavaScript files are not up to date. Run 'rm -rf lib && npm run-script build' to update"
31+
git diff
32+
exit 1
33+
fi
34+
echo "Success: JavaScript files are up to date"
35+
36+
# Clean up changes to package.json, package-lock.json, and lib/*.js.
37+
git reset --hard HEAD~1

0 commit comments

Comments
 (0)