From fd700e1444a4049ee7907988ffbb5c33808c16d7 Mon Sep 17 00:00:00 2001 From: Steffen Smolka Date: Thu, 21 Nov 2024 15:34:28 -0800 Subject: [PATCH] Update GitHub Actions cache even if build/test fails. PiperOrigin-RevId: 698937143 --- .github/workflows/build.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b3af3e6..26f49fc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,8 @@ jobs: run: bazel test --test_output=errors //... - name: Save end time + # Always save the end time so we can calculate the build duration. + if: always() uses: josStorer/get-current-time@v2 id: end-time with: @@ -50,6 +52,8 @@ jobs: format: X - name: Calculate build duration + # Always calculate the build duration so we can update the cache if needed. + if: always() run: | START=${{ steps.start-time.outputs.formattedTime }} END=${{ steps.end-time.outputs.formattedTime }} @@ -58,12 +62,19 @@ jobs: - name: Compress cache + # Always compress the cache so we can update the cache if needed. + if: always() run: rm -rf $(bazel info repository_cache) - name: Save bazel cache uses: actions/cache/save@v4 # Only create a new cache entry if we're on the main branch or the build takes >5mins. - if: github.ref_name == 'main' || env.duration > 300 + # + # NOTE: Even though `always()` evaluates to true, and `true && x == x`, the `always() &&` + # prefix is not redundant! The call to `always()` has a side effect, which is to override + # the default behavior of automagically canceling this step if a previous step failed. + # (Don't blame me, blame GitHub Actions!) + if: always() && (github.ref_name == 'main' || env.duration > 300) with: path: "~/.cache/bazel" key: bazel-${{ hashFiles('*.bazel', '*.bazelrc') }}-${{ github.ref_name }}-${{ github.run_id }}