From d4bbcb74ca9400cb92146ef4ea5e441eafd2edce Mon Sep 17 00:00:00 2001 From: Mario Campos Date: Mon, 29 Sep 2025 11:26:46 -0500 Subject: [PATCH] Implement simultaneous PR checks for Node.js v20, v24. Copied from #2006. --- .github/workflows/pr-checks.yml | 12 ++++++-- .github/workflows/script/check-js-20.sh | 37 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100755 .github/workflows/script/check-js-20.sh diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 3a4bca4ec..4d87e15fb 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -20,6 +20,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] + node-version: [20, 24] permissions: contents: read security-events: write # needed to upload ESLint results @@ -36,7 +37,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v5 with: - node-version: 24 + node-version: ${{ matrix.node-version }} cache: 'npm' - name: Set up Python @@ -51,7 +52,12 @@ jobs: npm config set script-shell bash npm ci - - name: Verify compiled JS up to date + - name: Verify compiled JS up to date (Node.js 20) + if: matrix.node-version == 20 + run: .github/workflows/script/check-js-20.sh + + - name: Verify compiled JS up to date (Node.js 24) + if: matrix.node-version == 24 run: .github/workflows/script/check-js.sh - name: Verify PR checks up to date @@ -73,7 +79,7 @@ jobs: - name: Upload sarif uses: github/codeql-action/upload-sarif@v3 - if: matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-latest' && matrix.node-version == 24 with: sarif_file: eslint.sarif category: eslint diff --git a/.github/workflows/script/check-js-20.sh b/.github/workflows/script/check-js-20.sh new file mode 100755 index 000000000..02ed8557a --- /dev/null +++ b/.github/workflows/script/check-js-20.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -eu + +# Change @types/node to v20 temporarily to check that the generated JS files are correct. +contents=$(jq '.devDependencies."@types/node" = "^20.0.0"' package.json) +echo "${contents}" > package.json + +npm install + +if [ ! -z "$(git status --porcelain)" ]; then + git config --global user.email "github-actions@github.com" + git config --global user.name "github-actions[bot]" + # The period in `git add --all .` ensures that we stage deleted files too. + git add --all . + git commit -m "Use @types/node v20" +fi + +# Wipe the lib directory in case there are extra unnecessary files in there +rm -rf lib + +# Generate the JavaScript files +npm run-script build + +# Check that repo is still clean. +# The downgrade of @types/node means that we expect certain changes to the generated JS files. +# Therefore, we should ignore these changes to @types/node and check for outstanding changes. +if [[ $(git diff | grep --perl-regexp '^-(?!--)' | grep --count --invert-match --perl-regexp '"@types/node": "\^24') -gt 0 || \ + $(git diff | grep --perl-regexp '^\+(?!\+\+)' | grep --count --invert-match --perl-regexp '"@types/node": "\^20') -gt 0 ]] +then + >&2 echo "Failed: JavaScript files are not up to date. Run 'rm -rf lib && npm run-script build' to update" + git diff + exit 1 +fi +echo "Success: JavaScript files are up to date" + +# Clean up changes to package.json, package-lock.json, and lib/*.js. +git reset --hard HEAD~1