Skip to content

Commit

Permalink
fix: install latest node if setup-node fails (#186)
Browse files Browse the repository at this point in the history
Continues if the setup-node action fails to install, and then installs
latest node if there is no node version installed. Judging by [this
website](https://node.green/) showing note compatibilities, node is
almost entirely backwards compatible, which is why I went with the
latest version rather than e.g. node 20.

Additionally, adds a node version to the package.json so that this PR
can merge - the v1 action version still chokes when not finding the node
version.

This is tested by adding the trunk-action repo to the [repo
tests](https://github.com/trunk-io/trunk-action/actions/runs/6156480974/job/16705376207?pr=186),
which does not have a node version in main. However, the runners have
node installed, so the action doesn't attempt to install a default
version - I'm not sure if there's a better way to test that/if it's
worth it.
  • Loading branch information
puzzler7 committed Sep 13, 2023
1 parent 274902f commit 632304d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/repo_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ jobs:
post-init: |
${TRUNK_PATH} check enable eslint
- repo: prawn-test-staging-rw/setup-node-test
ref: main
post-init: |
if [ "${FAILED_NODE_INSTALL}" != "true" ]; then
echo "::error::Initial setup node didn't fail"
exit 1
fi
- repo: replayio/devtools
ref: 730a9f0ddaafefc2a1a293d6924ce3910cd156ac
description: (has trunk.yaml)
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {
"chai": "^4.3.7"
},
"engines": {
"node": "20.6.1"
}
}
22 changes: 22 additions & 0 deletions setup-env/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,32 @@ runs:
version: latest

- name: Install Node dependencies
id: setup_node
if: env.PACKAGE_MANAGER && env.NODE_VERSION_FILE
uses: actions/setup-node@v3
with:
node-version-file: ${{ env.NODE_VERSION_FILE }}
continue-on-error: true

- name: Check for node installation
if: env.PACKAGE_MANAGER && env.NODE_VERSION_FILE
shell: bash
run: |
if [ ${{ steps.setup_node.outcome }} == "success" ]; then
exit 0
fi
echo "::warning::Failed to install specified node version."
echo "FAILED_NODE_INSTALL=true" >>$GITHUB_ENV
if ! command -v node >/dev/null; then
echo "::warning::No existing node install detected - installing latest node instead."
echo "INSTALL_LATEST_NODE=true" >>$GITHUB_ENV
fi
- name: Install backup node version
if: env.PACKAGE_MANAGER && env.NODE_VERSION_FILE && env.INSTALL_LATEST_NODE == 'true'
uses: actions/setup-node@v3
with:
node-version-file: latest

- name: Cache node_modules
if: inputs.cache-key && env.PACKAGE_MANAGER
Expand Down

0 comments on commit 632304d

Please sign in to comment.