Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I maintain a Bazel cache with GitHub Actions?

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?

like image 840
sdgfsdh Avatar asked Aug 11 '26 10:08

sdgfsdh


2 Answers

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 //...
like image 52
Vertexwahn Avatar answered Aug 14 '26 12:08

Vertexwahn


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
like image 28
Christian Gruber Avatar answered Aug 14 '26 10:08

Christian Gruber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!