|
13 | 13 | jobs: |
14 | 14 | bazel_test: |
15 | 15 | 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 |
19 | 16 | steps: |
20 | 17 | - uses: actions/checkout@v6 |
21 | 18 | - name: Install Ubuntu dependencies |
22 | 19 | 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 |
50 | 22 | 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 |
59 | 38 | # Actual testing. |
60 | 39 | - name: Bazel Test |
61 | 40 | run: | |
62 | | - ln -s .github/ci.bazelrc user.bazelrc |
63 | 41 | 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