Skip to content

Commit 861891f

Browse files
authored
Merge pull request #129 from salesforcecli/ew/all-the-nodes
Test all supported node versions
2 parents 7fc3dd1 + 51de243 commit 861891f

15 files changed

Lines changed: 32644 additions & 77 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 versions you wish to disable. For example:
18+
19+
```shell
20+
NODE_DISABLE_VERSIONS='18'
21+
NODE_DISABLE_VERSIONS='18,23'
22+
```
23+
Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,29 @@
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:
6-
description: Semver version to set version and version-1
7-
required: false
8-
nodeDisableCurrent:
9-
description: Disable testing on Node "current"
5+
description: Set node to a specific Semver version
106
required: false
11-
nodeDisablePrevious:
12-
description: Disable testing on Node "-1"
7+
nodeDisableVersions:
8+
description: A string of major version(s) to disable (18 or 18,23)
139
required: false
14-
1510
outputs:
1611
nodeVersions:
1712
description: Node versions to be consumed by a workflow matrix
1813
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-
3914
runs:
40-
using: composite
15+
using: 'composite'
4116
steps:
42-
- name: Determine node versions
17+
# Note: this is not typically how you would run javascript in an action
18+
# This is need so that we can get the correct node version used elsewhere
19+
- name: Set up Node
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ inputs.nodeVersionOverride || 'lts/*' }}
23+
- name: Run main script
4324
shell: bash
4425
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
75-
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"
26+
run: node "$GITHUB_ACTION_PATH/dist/index.js"
8127
env:
82-
INPUTS_NODE_VERSION_OVERRIDE: ${{ inputs.nodeVersionOverride }}
83-
INPUTS_NODE_DISABLE_CURRENT: ${{ inputs.nodeDisableCurrent }}
84-
INPUTS_NODE_DISABLE_PREVIOUS: ${{ inputs.nodeDisablePrevious }}
28+
NODE_DISABLE_VERSIONS: ${{ inputs.nodeDisableVersions }}
29+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

0 commit comments

Comments
 (0)