From a2da63758c6f7ed22eb2d595b18934cd149e0a5d Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Thu, 2 Mar 2023 14:10:53 +0000 Subject: [PATCH] Use a separate GHA cache for each matrix build (#1605) You can't update a GHA cache once you create it, so if we use the same cache for each job in a matrix build, then we end up populating it for the first job that completes, so any slower jobs don't get their dependencies cached. On the other hand, if we create 20 500MB cache items on each build, we're going to exhaust the cache storage as soon as we do a build. So, instead, let's just do the caching for the main branch, and hope that other branches can still benefit from it. --- .github/workflows/ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 643e3db68..6cbfa7743 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,14 @@ jobs: - name: Load cache uses: Swatinem/rust-cache@v2 + with: + # use a separate cache for each job to work around + # https://github.com/Swatinem/rust-cache/issues/124 + key: "${{ matrix.name }}" + + # ... but only save the cache on the main branch + # cf https://github.com/Swatinem/rust-cache/issues/95 + save-if: ${{ github.ref == 'refs/head/main' }} - name: Install nextest uses: taiki-e/install-action@nextest @@ -239,6 +247,14 @@ jobs: - name: Load cache uses: Swatinem/rust-cache@v2 + with: + # use a separate cache for each job to work around + # https://github.com/Swatinem/rust-cache/issues/124 + key: "${{ matrix.cmd }}" + + # ... but only save the cache on the main branch + # cf https://github.com/Swatinem/rust-cache/issues/95 + save-if: ${{ github.ref == 'refs/head/main' }} - name: Install nextest uses: taiki-e/install-action@nextest