Skip to content

Commit db3ba35

Browse files
authored
Use setup-bazel GHA for disk and repository caching (#111)
1 parent 39616e3 commit db3ba35

2 files changed

Lines changed: 17 additions & 61 deletions

File tree

.github/ci.bazelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,29 @@ on:
1313
jobs:
1414
bazel_test:
1515
runs-on: ubuntu-latest
16-
env:
17-
# This is where bazelisk caches its downloads of Bazel.
18-
BAZELISK_HOME: /home/runner/.cache/bazel_ci/bazelisk
1916
steps:
2017
- uses: actions/checkout@v6
2118
- name: Install Ubuntu dependencies
2219
run: .github/ci_setup.bash
23-
# Restore the most appropriate caches.
24-
#
25-
# In the below: `github.ref` will be either "refs/pull/<pr_number>/merge"
26-
# or "refs/heads/master"; `github.run_number` is a monotonically increasing
27-
# serial number; and `github.run_attempt` is a typically 1.
28-
#
29-
# The `key` declared here will never match (since it encodes the current
30-
# run_number) but illustrates the name we'll use to save the caches when
31-
# we're done.
32-
#
33-
# However, one of the `restore-keys` patterns *should* always match. The
34-
# effects we should see from the `restore-keys` patterns are:
35-
#
36-
# * When building the `master` branch, we'll always pull the most recently
37-
# updated master caches. Both restore keys say
38-
# "bazel_ci-refs/heads/master-" and the prior archives are named, e.g.,
39-
# "bazel_ci-refs/heads/master-####-#". GitHub will use the *most
40-
# recently saved* archive name that matches the restore key prefix
41-
# (no matter the lexicographic ordering of the ####-# part).
42-
#
43-
# * Ditto for the first build of a PR; the first restore key will not
44-
# match anything, so it falls back to the master caches.
45-
#
46-
# * For subsequent builds of a PR, the first restore key, e.g.,
47-
# "bazel_ci-refs/pull/###/merge-" should match the most recently saved
48-
# PR key "bazel_ci-refs/pull/###/merge-####-#".
49-
- uses: actions/cache/restore@v5
20+
# Use setup-bazel for caching.
21+
- uses: bazel-contrib/setup-bazel@0.15.0
5022
with:
51-
path: ~/.cache/bazel_ci
52-
key: bazel_ci-${{ github.ref }}-${{ github.run_number }}-${{ github.run_attempt }}
53-
restore-keys: |
54-
bazel_ci-${{ github.ref }}-
55-
bazel_ci-refs/heads/master-
56-
- name: Report cache sizes
57-
run: |
58-
du -ms ~/.cache/bazel_ci/* || true
23+
# Use the cached Bazelisk version, or download if not found.
24+
bazelisk-cache: true
25+
# Enable the disk cache and share it across all workflows
26+
# (i.e., across master and pull requests).
27+
# We want all builds to start from a warm cache, and we're not too
28+
# concerend about pull request builds "polluting" master builds.
29+
disk-cache: true
30+
# Share repository cache globally as well. If repository-cache is set to true,
31+
# it uses the hash of a few bazel files as the key for the cache. You can set
32+
# your own list of files to use to calculate the key by passing them below.
33+
# Passing an empty string tells setup-bazel to use the same key
34+
# every time, regardless of any changes to any files.
35+
repository-cache: ""
36+
# This dumps configuration details to the log.
37+
bazelrc: common --announce_rc=yes
5938
# Actual testing.
6039
- name: Bazel Test
6140
run: |
62-
ln -s .github/ci.bazelrc user.bazelrc
6341
bazelisk test //...
64-
# Save the updated cache snapshots, so we never do the same work twice.
65-
# By default, actions/cache only saves after a successful workflow, but
66-
# our caches are bags of files where we only ever add new files (not change
67-
# an existing files), so it's always safe to snapshot.
68-
- uses: actions/cache/save@v5
69-
if: always()
70-
with:
71-
path: ~/.cache/bazel_ci
72-
key: bazel_ci-${{ github.ref }}-${{ github.run_number }}-${{ github.run_attempt }}

0 commit comments

Comments
 (0)