Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GitHub Actions cache even if build/test fails. #8

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}