CI now uses actions/setup-node to setup Node and restore the Yarn cache (#89363)

## About The Pull Request
This PR changes CI to use `actions/setup-node` to setup Node, instead of
using `tools/ci/install_node.sh`. The version given to this action is
the same as specified in `dependencies.sh`.

This fixes the issue of CI not using the node version provided in
`dependencies.sh`. Previously, it was using the system-wide Node, which
at the time of this PR is `v20.18.2`.

This change is NOT applied across all jobs, but is applied at minimum to
any jobs where the game is compiled. For example, any integration test
jobs now use `actions/setup-node` - but the "Remove guide comments" job
is untouched.

This PR has the additional following effects:
* The node install is no longer cached - it is instead downloaded from
<https://github.com/actions/node-versions> (or
<https://nodejs.org/dist/> if that fails). Being that the CI runner
needs to contact Github anyways to obtain the cached Node install, this
should make no difference.
* We no longer have to perform Yarn caching ourselves -
`actions/setup-node` does it for us! However, a side effect of this is
that the Yarn cache uses a different cache key now. I would have set up
the action to pull from the existing cache, but unfortunately that
wasn't an option.

Speaking of caching - the new action, `.github/actions/setup_node`, will
NOT restore the Yarn cache unless the `restore-yarn-cache` input is
`true`. This saves a couple seconds where we need node, but don't need
the yarn cache (such as in integration tests).
This commit is contained in:
MichiRecRoom
2025-02-07 14:54:26 -05:00
committed by GitHub
parent 8a1c511dee
commit ba7f720eaa
5 changed files with 37 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
# This is a reusable workflow to restore BYOND from a cache, or to install it otherwise.
# This action attempts to restore BYOND from a cache, or to install it otherwise.
name: Restore or Install BYOND
description: Attempts to restore a specified BYOND version from cache; if it can't, it installs it.

26
.github/actions/setup_node/action.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
# This action is a wrapper around `actions/setup-node`, to use the version specified in
# `dependencies.sh`.
name: Setup Node
description: Install Node using the version specified in `dependencies.sh`; additionally, restores the Yarn cache if one exists
inputs:
restore-yarn-cache:
description: 'If `true`, restores the Yarn cache alongside installing node.'
required: false
type: boolean
default: false
runs:
using: composite
steps:
- name: Configure Node version
shell: bash
run: |
source dependencies.sh
echo "NODE_VERSION_REQUIRED=$NODE_VERSION_LTS" >> $GITHUB_ENV
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION_REQUIRED }}
cache: ${{ fromJSON(inputs.restore-yarn-cache) && 'yarn' || '' }}
cache-dependency-path: ${{ fromJSON(inputs.restore-yarn-cache) && 'tgui/yarn.lock' || '' }}

View File

@@ -42,20 +42,10 @@ jobs:
key: ${{ runner.os }}-spacemandmm-${{ hashFiles('dependencies.sh') }}
restore-keys: |
${{ runner.os }}-spacemandmm-
- name: Restore Yarn cache
uses: actions/cache@v4
- name: Setup Node
uses: ./.github/actions/setup_node
with:
path: tgui/.yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('tgui/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Restore Node cache
uses: actions/cache@v4
with:
path: ~/.nvm
key: ${{ runner.os }}-node-${{ hashFiles('dependencies.sh') }}
restore-keys: |
${{ runner.os }}-node-
restore-yarn-cache: true
- name: Restore Bootstrap cache
uses: actions/cache@v4
with:
@@ -89,7 +79,6 @@ jobs:
- name: Install Tools
run: |
pip3 install setuptools
bash tools/ci/install_node.sh
bash tools/ci/install_spaceman_dmm.sh dreamchecker
bash tools/ci/install_ripgrep.sh
tools/bootstrap/python -c ''
@@ -149,6 +138,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: ./.github/actions/setup_node
- name: Restore BYOND from Cache
uses: ./.github/actions/restore_or_install_byond
- name: Compile All Maps
@@ -258,13 +249,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Restore Yarn cache
uses: actions/cache@v4
- name: Setup Node
uses: ./.github/actions/setup_node
with:
path: tgui/.yarn/cache
key: ${{ runner.os }}-yarn-${{ hashFiles('tgui/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
restore-yarn-cache: true
- name: Compile
run: pwsh tools/ci/build.ps1
env:

View File

@@ -44,6 +44,8 @@ jobs:
mysql -u root -proot tg_ci < SQL/tgstation_schema.sql
mysql -u root -proot -e 'CREATE DATABASE tg_ci_prefixed;'
mysql -u root -proot tg_ci_prefixed < SQL/tgstation_schema_prefixed.sql
- name: Setup Node
uses: ./.github/actions/setup_node
- name: Install rust-g
run: |
bash tools/ci/install_rust_g.sh

View File

@@ -1,10 +0,0 @@
#!/bin/bash
set -euo pipefail
source dependencies.sh
if [[ -e ~/.nvm/nvm.sh ]]; then
source ~/.nvm/nvm.sh
nvm install $NODE_VERSION_LTS
nvm use $NODE_VERSION_LTS
fi