From 3a546ef2ede4a648fb5ccb41e83e0c49993f87df Mon Sep 17 00:00:00 2001 From: George Oastler Date: Tue, 11 Aug 2026 22:10:34 +0100 Subject: [PATCH] ci: skip cache save on self-hosted runners --- .github/actions/save_cargo_cache/action.yml | 17 +++++++++++++++++ .github/actions/save_npm_cache/action.yml | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/.github/actions/save_cargo_cache/action.yml b/.github/actions/save_cargo_cache/action.yml index 85f312a..471b544 100644 --- a/.github/actions/save_cargo_cache/action.yml +++ b/.github/actions/save_cargo_cache/action.yml @@ -1,11 +1,26 @@ name: "save_cargo_cache" +# Every step is gated on runner type, mirroring restore_npm_cache / +# restore_cargo_cache which already skip on self-hosted. Our self-hosted runners +# are persistent (one long-lived VM taking job after job), so the cached +# directories under $HOME survive between jobs and the upload is WAN traffic for +# nothing. It is also not merely wasteful: the cleanup step below deletes every +# key but the newest, so a cache saved on self-hosted hardware displaces the +# ones the GitHub-hosted runners restore from. + +inputs: + save-on-self-hosted: + description: "Whether to save the cargo cache to the GitHub cache backend on self-hosted runners" + required: false + default: "false" + runs: using: "composite" steps: # dirs must exist before cache restore - name: Make dirs + if: ${{ runner.environment != 'self-hosted' || inputs.save-on-self-hosted == 'true' }} shell: bash run: | mkdir -p ~/.cargo @@ -14,6 +29,7 @@ runs: mkdir -p target - name: Save cargo cache + if: ${{ runner.environment != 'self-hosted' || inputs.save-on-self-hosted == 'true' }} uses: actions/cache/save@v4 with: path: | @@ -25,6 +41,7 @@ runs: key: cargo-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}-${{ github.run_attempt }} - name: Cleanup cargo caches + if: ${{ runner.environment != 'self-hosted' || inputs.save-on-self-hosted == 'true' }} shell: bash run: | # remove all but the latest cache, leaving only the cache we just saved diff --git a/.github/actions/save_npm_cache/action.yml b/.github/actions/save_npm_cache/action.yml index b55196e..b22bde2 100644 --- a/.github/actions/save_npm_cache/action.yml +++ b/.github/actions/save_npm_cache/action.yml @@ -1,11 +1,26 @@ name: "save_npm_cache" +# Every step is gated on runner type, mirroring restore_npm_cache / +# restore_cargo_cache which already skip on self-hosted. Our self-hosted runners +# are persistent (one long-lived VM taking job after job), so the cached +# directories under $HOME survive between jobs and the upload is WAN traffic for +# nothing. It is also not merely wasteful: the cleanup step below deletes every +# key but the newest, so a cache saved on self-hosted hardware displaces the +# ones the GitHub-hosted runners restore from. + +inputs: + save-on-self-hosted: + description: "Whether to save the npm cache to the GitHub cache backend on self-hosted runners" + required: false + default: "false" + runs: using: "composite" steps: # dirs must exist before cache restore - name: Make dirs + if: ${{ runner.environment != 'self-hosted' || inputs.save-on-self-hosted == 'true' }} shell: bash run: | mkdir -p ~/.npm @@ -15,11 +30,13 @@ runs: # checks the cache is valid and compresses it - name: Verify npm cache + if: ${{ runner.environment != 'self-hosted' || inputs.save-on-self-hosted == 'true' }} shell: bash run: | npm cache verify - name: Save npm cache + if: ${{ runner.environment != 'self-hosted' || inputs.save-on-self-hosted == 'true' }} uses: actions/cache/save@v4 with: path: | @@ -30,6 +47,7 @@ runs: key: npm-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}-${{ github.run_attempt }} - name: Cleanup npm caches + if: ${{ runner.environment != 'self-hosted' || inputs.save-on-self-hosted == 'true' }} shell: bash run: | # remove all but the latest cache, leaving only the cache we just saved