From ba7f720eaaeaae46b8fb070a4abd60eb40aa1b01 Mon Sep 17 00:00:00 2001 From: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com> Date: Fri, 7 Feb 2025 14:54:26 -0500 Subject: [PATCH] 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 (or 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). --- .../restore_or_install_byond/action.yml | 2 +- .github/actions/setup_node/action.yml | 26 +++++++++++++++++ .github/workflows/ci_suite.yml | 28 ++++++------------- .github/workflows/run_integration_tests.yml | 2 ++ tools/ci/install_node.sh | 10 ------- 5 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 .github/actions/setup_node/action.yml delete mode 100644 tools/ci/install_node.sh diff --git a/.github/actions/restore_or_install_byond/action.yml b/.github/actions/restore_or_install_byond/action.yml index a4b9ce9da6d..4b07a612558 100644 --- a/.github/actions/restore_or_install_byond/action.yml +++ b/.github/actions/restore_or_install_byond/action.yml @@ -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. diff --git a/.github/actions/setup_node/action.yml b/.github/actions/setup_node/action.yml new file mode 100644 index 00000000000..120dbf4639b --- /dev/null +++ b/.github/actions/setup_node/action.yml @@ -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' || '' }} diff --git a/.github/workflows/ci_suite.yml b/.github/workflows/ci_suite.yml index 708f0fda602..16b2864b749 100644 --- a/.github/workflows/ci_suite.yml +++ b/.github/workflows/ci_suite.yml @@ -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: diff --git a/.github/workflows/run_integration_tests.yml b/.github/workflows/run_integration_tests.yml index 6afc99b7261..c2dcc421a91 100644 --- a/.github/workflows/run_integration_tests.yml +++ b/.github/workflows/run_integration_tests.yml @@ -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 diff --git a/tools/ci/install_node.sh b/tools/ci/install_node.sh deleted file mode 100644 index f18fb49865e..00000000000 --- a/tools/ci/install_node.sh +++ /dev/null @@ -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