How to Use a Bazel Remote Cache in GitHub Actions
A Bazel remote cache stores action outputs keyed by their inputs, so CI downloads results instead of rebuilding.
Point --remote_cache at your cache endpoint in .bazelrc or on the command line, authenticate with a header flag, and Bazel reuses any action whose inputs are unchanged.
Steps
- Add the remote cache URL and auth to a CI bazelrc.
- Store the auth token as a secret and inject it as a header.
- Run the build; cache hits skip recompilation.
Workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
bazel build //... \
--remote_cache=grpcs://cache.example.com \
--remote_header=authorization="Bearer ${{ secrets.BAZEL_CACHE_TOKEN }}" \
--remote_upload_local_results=trueGotchas
- PRs from forks should not upload results; gate
--remote_upload_local_resultsto trusted refs. - Non-hermetic actions poison the cache; pin toolchains so inputs are reproducible.
Related guides
How to Share a Build Cache Across Monorepo Packages in GitHub ActionsShare one actions/cache entry across every package in a monorepo by keying on the workspace lockfile hash and…
How to Order Monorepo Jobs by Dependency Graph in GitHub ActionsOrder monorepo CI jobs so dependencies build before dependents in GitHub Actions, using needs to encode the p…