Skip to content

Commit 73250c1

Browse files
authored
Make tests use a dynamic / non-hardcoded (outdated) version(s) of Node (#1534)
[The build fails on Node 10](https://github.com/hazelcast/hazelcast-nodejs-client/actions/runs/14506740078/job/40704372723): ``` /home/runner/work/hazelcast-nodejs-client/hazelcast-nodejs-client/node_modules/nise/node_modules/@sinonjs/fake-timers/src/fake-timers-src.js:2059 if (options.signal?.aborted && !hasThrown) { ``` In #1321 the tests were updated to: > Run nightlies in Node 10 and 18 which are the oldest supported and newest Node versions _(except for `code_quality.yml`, which was left on 12)_ However, the version of `sinonjs/fake-timers` we use (dependency of `nise` which is a dependency of `sinon`) uses optional chaining syntax, requiring Node >=14. Instead of hardcoding Node version(s), we can take the original logic (newest/oldest supported versions) and compute that dynamically instead [based on the NodeJS release metadata](https://raw.githubusercontent.com/nodejs/Release/main/schedule.json). The net result of this change is that (today), tests that run on a range of versions will run on `18` & `22`, with tests on a specific version using `22`. [Example execution showing it now successfully compiles with the dynamic versions](https://github.com/hazelcast/hazelcast-nodejs-client/actions/runs/14512391261) (other test failures out of scope).
1 parent 6d90bea commit 73250c1

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

.github/workflows/code_quality.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ on:
88
pull_request:
99

1010
jobs:
11+
node-versions:
12+
uses: ./.github/workflows/get-supported-node-versions.yml
13+
1114
check-code-quality:
1215
name: Check code quality
1316
runs-on: ubuntu-latest
17+
needs: node-versions
1418

1519
steps:
1620
- name: Setup Node.js
1721
uses: actions/setup-node@v4
1822
with:
19-
node-version: 12
23+
node-version: ${{ needs.node-versions.outputs.default-version }}
2024
- name: Checkout code
2125
uses: actions/checkout@v4
2226
- name: Install dependencies

.github/workflows/code_sample_checker.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: Code sample checker
22
on: pull_request
33

44
jobs:
5+
node-versions:
6+
uses: ./.github/workflows/get-supported-node-versions.yml
7+
58
test-code-samples:
69
name: Check code samples
710
runs-on: ${{matrix.os}}
11+
needs: node-versions
812

913
strategy:
1014
matrix:
@@ -24,7 +28,7 @@ jobs:
2428
- name: Setup Node.js
2529
uses: actions/setup-node@v4
2630
with:
27-
node-version: 10
31+
node-version: ${{ needs.node-versions.outputs.default-version }}
2832
- name: Install dependencies and compile client
2933
run: |
3034
npm install

.github/workflows/coverage_runner.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ jobs:
2828
member-name: ${{ github.actor }}
2929
token: ${{ secrets.PAT }}
3030

31+
node-versions:
32+
uses: ./.github/workflows/get-supported-node-versions.yml
33+
3134
run-tests:
3235
name: Run Tests on (${{ matrix.os }})
33-
needs: [check_for_membership]
36+
needs:
37+
- check_for_membership
38+
- node-versions
3439
if: github.event_name == 'push' || needs.check_for_membership.outputs.check-result == 'true' || github.event_name == 'workflow_dispatch'
3540
runs-on: ${{ matrix.os }}
3641
strategy:
@@ -65,7 +70,7 @@ jobs:
6570
- name: Setup Node.js
6671
uses: actions/setup-node@v4
6772
with:
68-
node-version: 10
73+
node-version: ${{ needs.node-versions.outputs.default-version }}
6974

7075
- name: Checkout to test artifacts
7176
uses: actions/checkout@v4
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Get supported Node.js versions
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
node-versions:
7+
value: ${{ jobs.get-supported-node-versions.outputs.node-versions }}
8+
default-version:
9+
value: ${{ jobs.get-supported-node-versions.outputs.default-version }}
10+
11+
jobs:
12+
get-supported-node-versions:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
node-versions: ${{ steps.get_versions.outputs.node-versions }}
16+
default-version: ${{ steps.get_versions.outputs.default-version }}
17+
steps:
18+
- name: Get supported Node.js versions
19+
id: get_versions
20+
run: |
21+
# Look for versions that are:
22+
# - Currently supported
23+
# - That are LTS
24+
# - Within LTS date range (i.e. not future LTS)
25+
NODE_VERSIONS=$(curl --silent https://raw.githubusercontent.com/nodejs/Release/main/schedule.json | jq --compact-output '
26+
def today: now | strftime("%Y-%m-%d");
27+
to_entries
28+
| map(select(.value.end > today and .value.lts != null and .value.lts < today))
29+
| [.[0].key, .[-1].key]
30+
| unique
31+
')
32+
33+
echo "node-versions=${NODE_VERSIONS}" >> ${GITHUB_OUTPUT}
34+
# Default to using the newest version
35+
echo "default-version=$(jq -r '.[1]' <<< ${NODE_VERSIONS})" >> ${GITHUB_OUTPUT}

.github/workflows/nightly_runner_maintenance.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ on:
44
schedule:
55
- cron: '0 2 */2 * *'
66
jobs:
7+
node-versions:
8+
uses: ./.github/workflows/get-supported-node-versions.yml
9+
710
run-tests:
811
runs-on: ${{ matrix.os }}
12+
needs: node-versions
913
name: Run tests of branch ${{ matrix.branch }} on ${{ matrix.os }} with Node ${{ matrix.nodejs_version }}
1014
strategy:
1115
matrix:
1216
branch: [ 5.0.x, 4.2.x, 4.1.x, 4.0.x ]
1317
os: [ ubuntu-latest, windows-latest ]
14-
nodejs_version: [ 10, 18 ]
18+
nodejs_version: ${{ fromJSON(needs.node-versions.outputs.node-versions) }}
1519
fail-fast: false
1620
steps:
1721
- name: Setup Java

.github/workflows/nightly_runner_master.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ on:
44
schedule:
55
- cron: '0 2 * * *'
66
jobs:
7+
node-versions:
8+
uses: ./.github/workflows/get-supported-node-versions.yml
9+
710
run-tests:
811
runs-on: ${{ matrix.os }}
12+
needs: node-versions
913
name: Run tests of master on ${{ matrix.os }} with Node ${{ matrix.nodejs_version }}
1014
strategy:
1115
matrix:
1216
os: [ ubuntu-latest, windows-latest ]
13-
nodejs_version: [ 10, 18 ]
17+
nodejs_version: ${{ fromJSON(needs.node-versions.outputs.node-versions) }}
1418
fail-fast: false
1519
steps:
1620
- name: Checkout code

0 commit comments

Comments
 (0)