@@ -15,13 +15,39 @@ jobs:
1515 runs-on : ubuntu-latest
1616 timeout-minutes : 45
1717
18+ strategy :
19+ matrix :
20+ node-types-version : [16.11, current] # run tests on 16.11 while CodeQL Action v2 is still supported
21+
1822 steps :
1923 - name : Checkout
2024 uses : actions/checkout@v4
2125
2226 - name : Lint
2327 run : npm run-script lint
2428
29+ - name : Update version of @types/node
30+ if : matrix.node-types-version != 'current'
31+ env :
32+ NODE_TYPES_VERSION : ${{ matrix.node-types-version }}
33+ run : |
34+ # Export `NODE_TYPES_VERSION` so it's available to jq
35+ export NODE_TYPES_VERSION="${NODE_TYPES_VERSION}"
36+ contents=$(jq '.devDependencies."@types/node" = env.NODE_TYPES_VERSION' package.json)
37+ echo "${contents}" > package.json
38+ # Usually we run `npm install` on macOS to ensure that we pick up macOS-only dependencies.
39+ # However we're not checking in the updated lockfile here, so it's fine to run
40+ # `npm install` on Linux.
41+ npm install
42+
43+ if [ ! -z "$(git status --porcelain)" ]; then
44+ git config --global user.email "github-actions@github.com"
45+ git config --global user.name "github-actions[bot]"
46+ # The period in `git add --all .` ensures that we stage deleted files too.
47+ git add --all .
48+ git commit -m "Use @types/node=${NODE_TYPES_VERSION}"
49+ fi
50+
2551 - name : Check generated JS
2652 run : .github/workflows/script/check-js.sh
2753
4571 uses : actions/checkout@v4
4672
4773 - name : Set up Python
48- uses : actions/setup-python@v4
74+ uses : actions/setup-python@v5
4975 with :
5076 python-version : 3.11
5177
7096
7197 steps :
7298 - name : Setup Python on MacOS
73- uses : actions/setup-python@v4
99+ uses : actions/setup-python@v5
74100 if : |
75101 matrix.os == 'macos-latest' && (
76102 matrix.version == 'stable-20220908' ||
@@ -88,3 +114,44 @@ jobs:
88114 # we won't be able to find them on Windows.
89115 npm config set script-shell bash
90116 npm test
117+
118+ check-node-version :
119+ if : ${{ github.event.pull_request }}
120+ name : Check Action Node versions
121+ runs-on : ubuntu-latest
122+ timeout-minutes : 45
123+ env :
124+ BASE_REF : ${{ github.base_ref }}
125+
126+ steps :
127+ - uses : actions/checkout@v4
128+ - id : head-version
129+ name : Verify all Actions use the same Node version
130+ run : |
131+ NODE_VERSION=$(find . -name "action.yml" -exec yq -e '.runs.using' {} \; | grep node | sort | uniq)
132+ echo "NODE_VERSION: ${NODE_VERSION}"
133+ if [[ $(echo "$NODE_VERSION" | wc -l) -gt 1 ]]; then
134+ echo "::error::More than one node version used in 'action.yml' files."
135+ exit 1
136+ fi
137+ echo "node_version=${NODE_VERSION}" >> $GITHUB_OUTPUT
138+
139+ - id : checkout-base
140+ name : ' Backport: Check out base ref'
141+ if : ${{ startsWith(github.head_ref, 'backport-') }}
142+ uses : actions/checkout@v4
143+ with :
144+ ref : ${{ env.BASE_REF }}
145+
146+ - name : ' Backport: Verify Node versions unchanged'
147+ if : steps.checkout-base.outcome == 'success'
148+ env :
149+ HEAD_VERSION : ${{ steps.head-version.outputs.node_version }}
150+ run : |
151+ BASE_VERSION=$(find . -name "action.yml" -exec yq -e '.runs.using' {} \; | grep node | sort | uniq)
152+ echo "HEAD_VERSION: ${HEAD_VERSION}"
153+ echo "BASE_VERSION: ${BASE_VERSION}"
154+ if [[ "$BASE_VERSION" != "$HEAD_VERSION" ]]; then
155+ echo "::error::Cannot change the Node version of an Action in a backport PR."
156+ exit 1
157+ fi
0 commit comments