Skip to content

Enable BuildBuddy integration in CI with API key injection#1166

Merged
BYVoid merged 3 commits into
masterfrom
claude/enable-buildbuddy-bazel-Y4EVe
May 3, 2026
Merged

Enable BuildBuddy integration in CI with API key injection#1166
BYVoid merged 3 commits into
masterfrom
claude/enable-buildbuddy-bazel-Y4EVe

Conversation

@BYVoid

@BYVoid BYVoid commented May 3, 2026

Copy link
Copy Markdown
Owner

Summary

This PR integrates BuildBuddy remote caching and build event streaming into the CI/CD pipeline by securely injecting the API key at runtime, while maintaining flexibility for local development and fork PRs.

Key Changes

  • GitHub Actions Workflow: Added a new step that conditionally configures BuildBuddy by writing the API key to .bazelrc.user when the BUILDBUDDY_API_KEY secret is available. The step gracefully handles missing secrets (e.g., in fork PRs) with an informative message.
  • Bazel Configuration:
    • Refactored the buildbuddy config to be platform-agnostic by removing the remote executor setting
    • Moved remote executor configuration to platform-specific configs (linux-x86_64-remote and linux-arm64-remote)
    • Added --build_metadata=VISIBILITY=PUBLIC so invocation result pages are viewable without a BuildBuddy account
    • Updated comments to clarify that the API key should be passed via --remote_header=x-buildbuddy-api-key
  • User Config Support: Added .bazelrc.user to .gitignore and configured .bazelrc to import it with try-import, allowing CI and local development to inject environment-specific settings without version control

Local Development Is Unaffected

BuildBuddy is opt-in — it is only activated in CI, not during local development:

  • All BuildBuddy flags live under the build:buildbuddy config namespace, so they only apply when --config=buildbuddy is explicitly passed.
  • CI activates the config by writing build --config=buildbuddy --remote_header=x-buildbuddy-api-key=… into .bazelrc.user at job start. That file is gitignored and never exists locally.
  • .bazelrc loads it via try-import %workspace%/.bazelrc.user, which silently no-ops when the file is absent.

Net effect:

  • Local bazel build //... → no .bazelrc.user, no --config=buildbuddy → zero traffic to BuildBuddy.
  • CI → workflow generates .bazelrc.user → BES upload + remote cache enabled automatically.

A developer who wants BuildBuddy locally can either create their own .bazelrc.user with their personal API key, or pass --config=buildbuddy --remote_header=x-buildbuddy-api-key=$KEY ad hoc.

Implementation Details

  • The BuildBuddy configuration is now split: the base buildbuddy config handles BES and remote caching (safe for all platforms), while platform-specific configs add remote execution capabilities
  • The CI workflow uses bash to conditionally enable BuildBuddy only when the API key secret is present, preventing failures in fork PRs
  • The .bazelrc.user file is generated at runtime and ignored by git, enabling secure credential injection without exposing secrets in the repository

https://claude.ai/code/session_01KVRC2eMbe6ShHJqaTLPxPj

Inject the API key into a gitignored .bazelrc.user at CI time so
build/test runs upload to BuildBuddy and read/write the remote cache.
Falls back gracefully when the secret is missing (e.g. fork PRs).

Also splits --remote_executor out of build:buildbuddy into the
platform-specific *-remote configs so --config=buildbuddy is safe to
use on Linux/macOS/Windows runners for cache+BES only.
Copilot AI review requested due to automatic review settings May 3, 2026 00:05
Adds --build_metadata=VISIBILITY=PUBLIC to the buildbuddy config so
invocation result pages are viewable without a BuildBuddy account.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Integrates BuildBuddy BES/remote caching into CI by injecting an API key at runtime via a generated .bazelrc.user, and refactors Bazel configs to keep remote execution platform-specific while allowing optional user/CI overrides.

Changes:

  • Add CI step to generate .bazelrc.user from BUILDBUDDY_API_KEY when available.
  • Refactor .bazelrc BuildBuddy config to be platform-agnostic, moving --remote_executor into platform-specific configs.
  • Add .bazelrc.user support via try-import and ignore it in git.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
.gitignore Ignores generated .bazelrc.user to avoid committing injected secrets/config.
.github/workflows/bazel.yml Adds conditional BuildBuddy configuration step using a secret-injected environment variable.
.bazelrc Splits BuildBuddy configuration (base vs. platform-specific) and adds optional user/CI import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

run: |
if [ -n "${BUILDBUDDY_API_KEY}" ]; then
echo "build --config=buildbuddy --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.user
echo "BuildBuddy enabled."

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. The bazel test command inherits options from build, including --config=foo resolution against build:foo. Per Bazel's bazelrc docs, when bazel test --config=buildbuddy runs, it activates common:buildbuddy, test:buildbuddy, and build:buildbuddy. So flags under build:buildbuddy (BES + remote cache) do apply during bazel test in our CI.


Generated by Claude Code

Comment thread .bazelrc Outdated

# BuildBuddy.io
# BuildBuddy.io: BES + remote cache (safe to use on any platform).
# Pass the API key with: --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed in 4dfc7b8 — the workflow now writes both --remote_header=x-buildbuddy-api-key=... (for remote cache) and --bes_header=x-buildbuddy-api-key=... (for BES) into .bazelrc.user. The .bazelrc comment was updated to document both flags.


Generated by Claude Code

Comment thread .bazelrc
Comment on lines 16 to 20
build:buildbuddy --bes_results_url=https://app.buildbuddy.io/invocation/
build:buildbuddy --bes_backend=grpcs://remote.buildbuddy.io
build:buildbuddy --remote_cache=grpcs://remote.buildbuddy.io
build:buildbuddy --noremote_upload_local_results # Uploads logs & artifacts without writing to cache
build:buildbuddy --remote_timeout=10m

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment on the workflow file — this is incorrect. bazel test inherits options from build, so bazel test --config=buildbuddy does activate build:buildbuddy flags (BES + remote cache). See Bazel's bazelrc docs. No move to common:buildbuddy needed; CI tests will use BES and remote cache as intended.


Generated by Claude Code

--remote_header is documented as applying to remote cache/execution
gRPC channels; BES uses a separate channel and the dedicated
--bes_header flag. Set both so BuildBuddy's BES backend is
authenticated regardless of any cross-channel header sharing.
@BYVoid BYVoid merged commit 9272916 into master May 3, 2026
37 checks passed
@BYVoid BYVoid deleted the claude/enable-buildbuddy-bazel-Y4EVe branch May 3, 2026 01:00
@frankslin frankslin mentioned this pull request May 9, 2026
31 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants