Skip to content

Commit

Permalink
Update GitHub Actions cache even if build/test fails.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 698937143
  • Loading branch information
smolkaj authored and copybara-github committed Nov 21, 2024
1 parent 5c9761a commit fd700e1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ 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:
# Unix timestamp -- seconds since 1970.
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 }}
Expand All @@ -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 }}

0 comments on commit fd700e1

Please sign in to comment.