From feb8a7d76467a37f1a192841509b82f8732704f2 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Mon, 3 Nov 2025 14:07:00 -0500 Subject: [PATCH] chore(ci): move node setup and package install to dedicated action --- .github/actions/setup-node-deps/action.yml | 57 +++++++++++++++++++ .github/workflows/ci.yml | 22 +------ .github/workflows/conventions.yml | 24 ++------ .github/workflows/docs.yml | 26 ++------- .../workflows/nightly-throughput-stress.yml | 28 ++------- .github/workflows/release.yml | 50 +++------------- .github/workflows/stress.yml | 24 ++------ 7 files changed, 87 insertions(+), 144 deletions(-) create mode 100644 .github/actions/setup-node-deps/action.yml diff --git a/.github/actions/setup-node-deps/action.yml b/.github/actions/setup-node-deps/action.yml new file mode 100644 index 000000000..fb6740319 --- /dev/null +++ b/.github/actions/setup-node-deps/action.yml @@ -0,0 +1,57 @@ +name: 'Setup Node and Install Dependencies' +description: 'Sets up Node.js, configures NPM cache, and installs dependencies with retry logic' + +inputs: + node-version: + description: 'Version of Node.js to install' + required: false + default: '22' + platform: + description: 'Platform identifier for cache key (e.g., linux-x64, macos-arm, windows-x64)' + required: true + save-cache: + description: 'Whether to save the NPM cache at the end' + required: false + default: 'false' + +outputs: + cache-dir: + description: 'Path to the NPM cache directory' + value: ${{ steps.npm-cache-dir.outputs.dir }} + cache-hit: + description: 'Whether the cache was restored successfully' + value: ${{ steps.restore-cache.outputs.cache-hit }} + +runs: + using: 'composite' + steps: + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + + - name: Get NPM cache directory + id: npm-cache-dir + shell: bash + run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} + + - name: Restore NPM cache + id: restore-cache + uses: actions/cache/restore@v4 + with: + path: ${{ steps.npm-cache-dir.outputs.dir }} + key: npm-main-${{ inputs.platform }}-${{ hashFiles('./package-lock.json') }} + restore-keys: | + npm-main-${{ inputs.platform }}- + + - name: Download dependencies + shell: bash + run: | + npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose + + - name: Save NPM cache + if: inputs.save-cache == 'true' + uses: actions/cache/save@v4 + with: + path: ${{ steps.npm-cache-dir.outputs.dir }} + key: npm-main-${{ inputs.platform }}-${{ hashFiles('./package-lock.json') }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bf2b13aa..9659c0aae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -159,10 +159,11 @@ jobs: name: corebridge-native-debug-${{ matrix.platform }} path: ./packages/core-bridge/releases - - name: Install Node - uses: actions/setup-node@v4 + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-node-deps with: node-version: ${{ matrix.node-release-override || matrix.node }} + platform: ${{ matrix.platform }} # On Windows, the 'runner.temp' variable uses backslashes as path separators, but # that may pose problems in later steps when we try to join that with subpaths; @@ -176,23 +177,6 @@ jobs: run: echo "dir=$(pwd)" >> ${GITHUB_OUTPUT} working-directory: ${{ runner.temp }} - - name: Get NPM cache directory - id: npm-cache-dir - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Restore NPM cache - uses: actions/cache/restore@v4 - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: npm-main-${{ matrix.platform }}-${{ hashFiles('./package-lock.json') }} - restore-keys: | - npm-main-${{ matrix.platform }}- - - - name: Download dependencies - # Make up to 3 attempts to install NPM dependencies, to work around transient NPM errors :( - run: | - npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose - - name: Compile code run: npm run build -- --ignore @temporalio/core-bridge diff --git a/.github/workflows/conventions.yml b/.github/workflows/conventions.yml index 9cb879be2..2754eb689 100644 --- a/.github/workflows/conventions.yml +++ b/.github/workflows/conventions.yml @@ -20,23 +20,11 @@ jobs: with: submodules: recursive - - name: Install Node - uses: actions/setup-node@v4 + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-node-deps with: - node-version: 22 - - - name: Get NPM cache directory - id: npm-cache-dir - shell: bash - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Restore NPM cache - uses: actions/cache/restore@v4 - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: npm-main-linux-x64-${{ hashFiles('./package-lock.json') }} - restore-keys: | - npm-main-linux-x64- + node-version: '22' + platform: 'linux-x64' - name: Install protoc uses: arduino/setup-protoc@v3 @@ -58,10 +46,6 @@ jobs: env-vars: '' save-if: false - - name: Download dependencies - run: | - npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose - # eslint-import-resolver-typescript requires packages to be built - name: Compile all non-rust code run: npm run build -- --ignore @temporalio/core-bridge diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index eed46300f..a0bd9abf0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -39,29 +39,11 @@ jobs: with: submodules: recursive - - name: Install Node - uses: actions/setup-node@v4 + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-node-deps with: - node-version: 22 - - - name: Get NPM cache directory - id: npm-cache-dir - shell: bash - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Restore NPM cache - uses: actions/cache/restore@v4 - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: npm-main-linux-x64-${{ hashFiles('./package-lock.json') }} - restore-keys: | - npm-main-linux-x64- - - - name: Download dependencies - # Make up to 3 attempts to install NPM dependencies, to work around transient NPM errors - # Don't build during install phase since we're going to explicitly build anyway - run: | - npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose + node-version: '22' + platform: 'linux-x64' - run: npm run build -- --ignore @temporalio/core-bridge diff --git a/.github/workflows/nightly-throughput-stress.yml b/.github/workflows/nightly-throughput-stress.yml index 7ed30dc9f..c2d25886c 100644 --- a/.github/workflows/nightly-throughput-stress.yml +++ b/.github/workflows/nightly-throughput-stress.yml @@ -75,22 +75,12 @@ jobs: go-version-file: omes/go.mod cache-dependency-path: omes/go.sum - - name: Setup Node - uses: actions/setup-node@v4 + - name: Setup Node and Install Dependencies + id: setup-node + uses: ./.github/actions/setup-node-deps with: - node-version: 22 - - - name: Get NPM cache directory - id: npm-cache-dir - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Restore NPM cache - uses: actions/cache/restore@v4 - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: npm-main-linux-x64-${{ hashFiles('./package-lock.json') }} - restore-keys: | - npm-main-linux-x64- + node-version: '22' + platform: 'linux-x64' - name: Install protoc uses: arduino/setup-protoc@v3 @@ -106,12 +96,6 @@ jobs: with: workspaces: packages/core-bridge -> target - - name: Install SDK dependencies - run: | - npm ci --ignore-scripts --verbose || \ - npm ci --ignore-scripts --verbose || \ - npm ci --ignore-scripts --verbose - - name: Build SDK run: npm run build env: @@ -121,7 +105,7 @@ jobs: uses: actions/cache/save@v4 if: always() with: - path: ${{ steps.npm-cache-dir.outputs.dir }} + path: ${{ steps.setup-node.outputs.cache-dir }} key: npm-main-linux-x64-${{ hashFiles('./package-lock.json') }} - name: Install Temporal CLI diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f32bd35be..750c01977 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -169,27 +169,12 @@ jobs: mv tmp/corebridge-*/* ./ rm -rf tmp - - name: Install Node - uses: actions/setup-node@v4 + - name: Setup Node and Install Dependencies + id: setup-node + uses: ./.github/actions/setup-node-deps with: - node-version: 22 - - - name: Get NPM cache directory - id: npm-cache-dir - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Restore NPM cache - uses: actions/cache/restore@v4 - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: npm-main-${{ matrix.platform }}-${{ hashFiles('./package-lock.json') }} - restore-keys: | - npm-main-${{ matrix.platform }}- - - - name: Download dependencies - # Make up to 3 attempts to install NPM dependencies, to work around transient NPM errors :( - run: | - npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose + node-version: '22' + platform: ${{ matrix.platform }} - name: Compile code run: npm run build -- --ignore @temporalio/core-bridge @@ -208,7 +193,7 @@ jobs: # Only saves NPM cache from the main branch, to reduce pressure on the cache (limited to 10GB). if: ${{ env.IS_MAIN_OR_RELEASE == 'true' }} with: - path: ${{ steps.npm-cache-dir.outputs.dir }} + path: ${{ steps.setup-node.outputs.cache-dir }} key: npm-main-${{ matrix.platform }}-${{ hashFiles('./package-lock.json') }} # Tests that npm init @temporalio results in a working worker and client @@ -258,28 +243,11 @@ jobs: # We don't need the core submodule here since won't build the project submodules: false - - name: Install Node - uses: actions/setup-node@v4 + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-node-deps with: node-version: ${{ matrix.node }} - - - name: Get NPM cache directory - id: npm-cache-dir - shell: bash - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Restore NPM cache - uses: actions/cache/restore@v4 - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: npm-main-${{ matrix.platform }}-${{ hashFiles('./package-lock.json') }} - restore-keys: | - npm-main-${{ matrix.platform }}- - - # No need to compile anything, we just need the package ./scripts and their dependencies - - name: Install dependencies without compilation - run: | - npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose + platform: ${{ matrix.platform }} - name: Restore Verdaccio repo artifact uses: actions/download-artifact@v4 diff --git a/.github/workflows/stress.yml b/.github/workflows/stress.yml index e8dce3896..bbde74d0e 100644 --- a/.github/workflows/stress.yml +++ b/.github/workflows/stress.yml @@ -63,22 +63,11 @@ jobs: submodules: recursive ref: ${{ inputs.ref }} - - name: Install Node - uses: actions/setup-node@v4 + - name: Setup Node and Install Dependencies + uses: ./.github/actions/setup-node-deps with: - node-version: 22 - - - name: Get NPM cache directory - id: npm-cache-dir - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - name: Restore NPM cache - uses: actions/cache/restore@v4 - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: npm-main-linux-x64-${{ hashFiles('./package-lock.json') }} - restore-keys: | - npm-main-linux-x64- + node-version: '22' + platform: 'linux-x64' - name: Install protoc uses: arduino/setup-protoc@v3 @@ -99,11 +88,6 @@ jobs: env-vars: '' save-if: ${{ env.IS_MAIN_OR_RELEASE == 'true' }} - - name: Download dependencies - # Make up to 3 attempts to install NPM dependencies, to work around transient NPM errors - run: | - npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose || npm ci --ignore-scripts --verbose - - name: Compile code run: npm run build env: