From 4f93cf9d758e54de0fad0787b0de20ae81b1e14b Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 11 May 2021 10:46:41 +0900 Subject: [PATCH] ci: create cache always in main, skip saving cache in PRs (#10560) --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8bf9786014..cb4390796f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -190,13 +190,36 @@ jobs: key: a-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }} - - name: Cache build output - uses: actions/cache@v2 + # In main branch, always creates fresh cache + - name: Cache build output (main) + # TODO(kt3k): Change the version to the released version + # when https://github.com/actions/cache/pull/489 (or 571) is merged. + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + if: github.ref == 'refs/heads/main' with: path: | ./target - key: - a-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ hashFiles('Cargo.lock') }} + key: | + a-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ hashFiles('Cargo.lock') }}-${{ github.sha }} + + # Restores cache from the latest main branch's Cache + - name: Cache build output (PR) + # TODO(kt3k): Change the version to the released version + # when https://github.com/actions/cache/pull/489 (or 571) is merged. + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + if: github.ref != 'refs/heads/main' + with: + path: | + ./target + key: | + dummy # Cache never be created for this key. + restore-keys: | + a-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ hashFiles('Cargo.lock') }}- + + # Skips saving cache in PR branches + - name: Skip save cache (PR) + run: echo "CACHE_SKIP_SAVE=true" >> $GITHUB_ENV + if: github.ref != 'refs/heads/main' - name: Apply and update mtime cache uses: ./.github/mtime_cache