[build][bazel] Combine remote setup CI actions (#8893)

When the bazel remote cache was switched from buildbuddy to a self
hosted server in #8342, I asked that the buildbuddy hooks be remain so
that I could still use their caching service for local builds.

The downside of this was that my forks builds aren't leveraging
buildbuddy, so if I'm fiddling with something heavy like a wpimath
robotpy thing, my CI builds never update a cache and never are warm when
I push fixups.


This PR combines the `setup-bazel-remote` and `setup-build-buddy`
actions which set up the bazel remote cache. Rather than having two
different version, the correct one will be choosen in the following
order:
1. Use wpi's server with write access if the `bazel_remote` information
is set (This basically would only happen on main branch in
`wpilibsuite/allwpilib` since secrets aren't accessible from builds
originating in forks)
2. Use buildbuddy if the key it is present (This would work for my fork
builds)
3. Fall back to the readonly version of wpi's server


As seen
[here](https://github.com/bzlmodRio/allwpilib/actions/runs/25777428163/job/75712863120#step:7:28)
the build in my fork will run with buildbuddy, and my PR's build here
should fall back to readonly mode.
This commit is contained in:
PJ Reiniger
2026-06-03 23:16:42 -04:00
committed by GitHub
parent dca59147e1
commit fdc6fd9cb1
5 changed files with 57 additions and 91 deletions

View File

@@ -0,0 +1,38 @@
name: 'Setup Bazel Cache'
description: 'Configures the Bazel remote cache. Prefers WPI bazel-remote (R/W), falls back to BuildBuddy, then readonly WPI cache.'
inputs:
bazel_remote_username:
description: 'WPI Bazel remote cache username'
bazel_remote_password:
description: 'WPI Bazel remote cache password'
bazel_remote_url:
description: 'WPI Bazel remote cache base URL (no credentials or protocol, e.g. gitlib-bazel.wpi.edu)'
default: 'gitlib-bazel.wpi.edu'
buildbuddy_token:
description: 'BuildBuddy API token'
runs:
using: "composite"
steps:
- name: Resolve Bazel cache configuration
env:
CACHE_USER: ${{ inputs.bazel_remote_username }}
CACHE_PASS: ${{ inputs.bazel_remote_password }}
REMOTE_URL: ${{ inputs.bazel_remote_url }}
BB_TOKEN: ${{ inputs.buildbuddy_token }}
shell: bash
run: |
if [ -n "${CACHE_USER}" ] && [ -n "${CACHE_PASS}" ]; then
echo "WPI bazel-remote credentials detected; configuring R/W access"
echo "build:remote_cache --remote_cache=grpcs://${CACHE_USER}:${CACHE_PASS}@${REMOTE_URL}" > bazel_auth.rc
echo "build:ci --config=remote_cache" >> bazel_auth.rc
elif [ -n "${BB_TOKEN}" ]; then
echo "BuildBuddy token detected; configuring BuildBuddy cache"
echo "build:build_buddy --remote_header=x-buildbuddy-api-key=${BB_TOKEN}" > bazel_auth.rc
echo "build:ci --config=build_buddy" >> bazel_auth.rc
else
echo "No cache credentials detected; falling back to readonly WPI cache"
echo "build:ci --config=remote_cache" > bazel_auth.rc
echo "build:ci --config=remote_cache_readonly" >> bazel_auth.rc
fi