From 254315b68d6170f4a5fa50b0ddbf5ce415a82699 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Thu, 3 Dec 2026 15:06:13 +0100 Subject: [PATCH] perf(ci): reuse runtime installations within jobs Co-Authored-By: OpenAI Codex --- .github/actions/install-pnpm/action.yml | 18 +++++++++++++++--- .github/actions/setup-node/action.yml | 5 ++++- .github/actions/setup-node/resolve-node.sh | 5 +++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/actions/install-pnpm/action.yml b/.github/actions/install-pnpm/action.yml index fb303b263168..d260450f6944 100644 --- a/.github/actions/install-pnpm/action.yml +++ b/.github/actions/install-pnpm/action.yml @@ -10,9 +10,13 @@ runs: run: | version=$(node -p "require('./package.json').packageManager.slice('pnpm@'.length).split('+')[0]") echo "version=$version" >> "$GITHUB_OUTPUT" + if [ "${SENTRY_CI_PNPM_VERSION:-}" = "$version" ]; then + echo 'installed=true' >> "$GITHUB_OUTPUT" + fi - name: Restore pnpm installation id: cache + if: steps.pnpm.outputs.installed != 'true' uses: actions/cache/restore@v6.1.0 with: path: ${{ runner.temp }}/setup-pnpm @@ -20,12 +24,12 @@ runs: # Without a `version` input, the action reads the version from `packageManager`. With both, it fails. - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 - if: steps.cache.outputs.cache-hit != 'true' + if: steps.pnpm.outputs.installed != 'true' && steps.cache.outputs.cache-hit != 'true' with: dest: ${{ runner.temp }}/setup-pnpm - name: Use cached pnpm - if: steps.cache.outputs.cache-hit == 'true' + if: steps.pnpm.outputs.installed == 'true' || steps.cache.outputs.cache-hit == 'true' shell: bash run: | pnpm_home="$RUNNER_TEMP/setup-pnpm/node_modules/.bin" @@ -33,8 +37,16 @@ runs: echo "$pnpm_home" >> "$GITHUB_PATH" echo "$pnpm_home/bin" >> "$GITHUB_PATH" + - name: Remember installed pnpm version + shell: bash + env: + PNPM_VERSION: ${{ steps.pnpm.outputs.version }} + run: echo "SENTRY_CI_PNPM_VERSION=$PNPM_VERSION" >> "$GITHUB_ENV" + - name: Save pnpm installation - if: steps.cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/develop' + if: >- + steps.pnpm.outputs.installed != 'true' && steps.cache.outputs.cache-hit != 'true' && github.ref == + 'refs/heads/develop' uses: actions/cache/save@v6.1.0 with: path: ${{ runner.temp }}/setup-pnpm diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 77a4f3eb8db3..e2a701f876f1 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -13,6 +13,7 @@ runs: # manifest through the GitHub API in every job, which uses up the repository's `GITHUB_TOKEN` rate limit. - name: Restore Node.js install id: node-cache + if: steps.node.outputs.installed != 'true' uses: actions/cache/restore@v6.1.0 with: path: ${{ steps.node.outputs.cache-path }} @@ -25,7 +26,9 @@ runs: # Only `develop` saves, so PRs share one entry per architecture instead of each creating their own. - name: Save Node.js install - if: steps.node-cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/develop' + if: >- + steps.node.outputs.installed != 'true' && steps.node-cache.outputs.cache-hit != 'true' && github.ref == + 'refs/heads/develop' uses: actions/cache/save@v6.1.0 with: path: ${{ steps.node.outputs.cache-path }} diff --git a/.github/actions/setup-node/resolve-node.sh b/.github/actions/setup-node/resolve-node.sh index a611890c4023..1bb612887228 100755 --- a/.github/actions/setup-node/resolve-node.sh +++ b/.github/actions/setup-node/resolve-node.sh @@ -6,3 +6,8 @@ cache_path="$RUNNER_TOOL_CACHE/node/$version" cache_key="node-toolcache-$RUNNER_OS-$RUNNER_ARCH-$version" printf 'version=%s\ncache-path=%s\ncache-key=%s\n' "$version" "$cache_path" "$cache_key" >> "$GITHUB_OUTPUT" + +arch=$(node -p 'process.arch') +if [ -f "$cache_path/$arch.complete" ] && [ -x "$cache_path/$arch/bin/node" ]; then + echo 'installed=true' >> "$GITHUB_OUTPUT" +fi