Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: now uses actions/setup-node #246

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Toolo
Copy link
Contributor

@Toolo Toolo commented Oct 16, 2024

Description

We'd like to explore reusing actions/setup-node as our custom implementation is flaky on new node version requests.

Changes

  • feat: now uses actions/setup-node

🚀 PR created with fotingo

@Toolo Toolo force-pushed the s/replace_node_install branch 6 times, most recently from 71ad361 to c75217f Compare October 16, 2024 09:51
@open-turo open-turo deleted a comment from github-actions bot Oct 16, 2024
shell: bash
- uses: actions/setup-node@v4
id: setup-node
if: steps.get-node-version.outputs.node_version
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this POC, we only install node if it is required, otherwise we fall back to the system node. We could as easily install node 20 as the default and run the node install step every time. We can make a decision here.

echo "node_version=$NODE_VERSION" >> $GITHUB_OUTPUT
fi
shell: bash
- uses: actions/setup-node@v4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this action we get cached versions out of the box and a more reliable infrastructure that doesn't require us to rebuild runners to cache new node versions: https://github.com/actions/setup-node

id: setup-node
if: steps.get-node-version.outputs.node_version
with:
node-version: ${{ steps.get-node-version.outputs.node_version }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can optionally provide a GH token if we hit rate limits (https://github.com/actions/setup-node?tab=readme-ov-file#using-setup-node-on-ghes)

We just need to apply this diff:

diff --git a/action.yaml b/action.yaml
index 6dcc903..8a78d82 100644
--- a/action.yaml
+++ b/action.yaml
@@ -3,6 +3,11 @@ description:
   GitHub Action that installs and provisions supported tools for workflow steps
   in self-hosted runners. This relies on the agent having supported tooling
   installed.
+inputs:
+  github-token:
+    required: true
+    description: GitHub token to overcome unauthenticated rate limits when installing node, for instance 'secrets.GITHUB_TOKEN'
+    default: ${{ github.token }}
 outputs:
   go:
     description:
@@ -44,6 +49,8 @@ runs:
       if: steps.get-node-version.outputs.node_version
       with:
         node-version: ${{ steps.get-node-version.outputs.node_version }}
+        # https://github.com/actions/setup-node?tab=readme-ov-file#using-setup-node-on-ghes
+        token: ${{ inputs.github-token }}
     - name: Export installed node version
       if: steps.get-node-version.outputs.node_version
       run: |

@Toolo Toolo marked this pull request as ready for review October 16, 2024 12:19
@Toolo Toolo requested a review from a team as a code owner October 16, 2024 12:19
@Toolo Toolo force-pushed the s/replace_node_install branch from c75217f to 690ac13 Compare October 16, 2024 12:52
Copy link

Release notes preview

Below is a preview of the release notes if your PR gets merged.


2.1.0 (2024-10-16)

Features

  • now uses actions/setup-node (690ac13)

shell: bash
- name: Install Tools
id: install-tools
run: "node ${{ github.action_path }}/dist/main/index.js"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work if no node version was installed on the previous step?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work on the github runners, but on self hosted runners this would require having node installed there.

In both cases this would run using the default node verison in the runners, which could lead to failures (especially on our internal runners)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants