I build code on GitHub Actions using Bazel, which is preinstalled. Bazel has the ability to cache steps on the file-system to skip work on subsequent builds.
But how can I save this cache in GitHub Actions for use in subsequent workflow runs?
Use the cache action, e.g.:
jobs:
build_and_test_ubuntu:
name: Linux Ubuntu 20.04 Bazel build <GCC 9.3.0>
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Mount bazel cache
uses: actions/cache@v3
with:
path: "/home/runner/.cache/bazel"
key: bazel
- name: Build and Test
run: |
bazel build //...
bazel test //...
A github action "setup-bazel" exists to handle a lot of common config, including using bazelisk, as well as setting up local and external build cacheing.
https://github.com/bazel-contrib/setup-bazel
e.g.:
- uses: bazel-contrib/[email protected]
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Store build cache per workflow.
disk-cache: ${{ github.workflow }}
# Share repository cache between workflows.
repository-cache: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With