Skip to content

Commit 58811ba

Browse files
committed
fix: test all supported node versions
1 parent c7e9d40 commit 58811ba

13 files changed

Lines changed: 27926 additions & 81 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Determine Node Versions Action
2+
3+
This action will fetch the Node.js Release Schedule JSON and find all versions that are "open". The action sets the `nodeVersions` output with an array of Node versions. These versions will be used to run tests against. Example in `.github/workflows/unitTestsLinux.yml`
4+
5+
### Installing and building
6+
7+
This packages uses `ncc` to create a single javascript file for execution. Running the following will bundle a new `dist/index.js` file that needs to be committed to the repo.
8+
9+
```shell
10+
cd .github/actions/determineNodeVersions
11+
yarn install
12+
yarn build
13+
```
14+
15+
### Disabling specific versions
16+
17+
You can disabled Node versions at the Org or Repo level by setting an environment variable for the version you wish to disable. For example:
18+
19+
```shell
20+
NODE_DISABLE_VERSION_18='true'
21+
NODE_DISABLE_VERSION_23='true'
22+
```
23+
Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,23 @@
1-
name: determine-node-versions
2-
description: Calculate Node and Node-1 versions for unit tests
3-
1+
name: Determine node versions
2+
description: "Get all the supported node versions"
43
inputs:
54
nodeVersionOverride:
65
description: Semver version to set version and version-1
6+
default: 'lts/*'
77
required: false
8-
nodeDisableCurrent:
9-
description: Disable testing on Node "current"
10-
required: false
11-
nodeDisablePrevious:
12-
description: Disable testing on Node "-1"
13-
required: false
14-
158
outputs:
169
nodeVersions:
1710
description: Node versions to be consumed by a workflow matrix
1811
value: ${{ steps.node-versions.outputs.nodeVersions }}
19-
20-
# Sample output looks like this:
21-
#
22-
# nodeVersions<<EOF
23-
# [
24-
# "current",
25-
# "lts/*",
26-
# "lts/-1",
27-
# ]
28-
# EOF
29-
#
30-
# OR...
31-
#
32-
# nodeVersions<<EOF
33-
# [
34-
# "18.15.0",
35-
# "16"
36-
# ]
37-
# EOF
38-
3912
runs:
40-
using: composite
13+
using: 'composite'
4114
steps:
42-
- name: Determine node versions
15+
- name: Set up Node
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: ${{ inputs.nodeVersionOverride }}
19+
- name: Run main script
4320
shell: bash
4421
id: node-versions
45-
run: |
46-
# Current can be disabled by setting the "nodeDisableCurrent" input to "true"
47-
# Previous LTS can be disabled by setting the "nodeDisablePrevious" input to "true"
48-
# IF "NODE_VERSION" is overridden, "NODE_VERSION_CURRENT" will also be disabled
49-
50-
NODE_VERSION_CURRENT="current"
51-
if [ "$INPUTS_NODE_DISABLE_CURRENT" = "true" ] || [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ]; then
52-
NODE_VERSION_CURRENT=""
53-
fi
54-
55-
NODE_VERSION="lts/*"
56-
if [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ]; then
57-
NODE_VERSION="$INPUTS_NODE_VERSION_OVERRIDE"
58-
fi
59-
60-
NODE_PREVIOUS_LTS="lts/-1"
61-
if [ "$INPUTS_NODE_DISABLE_PREVIOUS" = "true" ]; then
62-
NODE_PREVIOUS_LTS=""
63-
fi
64-
65-
if [ -n "$INPUTS_NODE_VERSION_OVERRIDE" ] && [ "$INPUTS_NODE_DISABLE_PREVIOUS" != "true" ] ; then
66-
NODE_VERSION_MAJOR=$(echo "$INPUTS_NODE_VERSION_OVERRIDE" | cut -d '.' -f 1)
67-
68-
# LTS-1 will always be the previous LTS, which is always even. Here we calculate the nearest LTS
69-
if [ $((NODE_VERSION_MAJOR % 2)) = 0 ]; then
70-
NODE_PREVIOUS_LTS="$((NODE_VERSION_MAJOR - 2))"
71-
else
72-
NODE_PREVIOUS_LTS="$((NODE_VERSION_MAJOR - 1))"
73-
fi
74-
fi
22+
run: node dist/index.js
7523

76-
{
77-
echo "nodeVersions<<EOF"
78-
jq -n --arg v1 "$NODE_VERSION_CURRENT" --arg v2 "$NODE_VERSION" --arg v3 "$NODE_PREVIOUS_LTS" '[$v1, $v2, $v3] | map(select(. != ""))'
79-
echo "EOF"
80-
} >> "$GITHUB_OUTPUT"
81-
env:
82-
INPUTS_NODE_VERSION_OVERRIDE: ${{ inputs.nodeVersionOverride }}
83-
INPUTS_NODE_DISABLE_CURRENT: ${{ inputs.nodeDisableCurrent }}
84-
INPUTS_NODE_DISABLE_PREVIOUS: ${{ inputs.nodeDisablePrevious }}

0 commit comments

Comments
 (0)