All jobs

Set Up GitHub Actions CI for a Bazel Repository

Yes. An agent writes a GitHub Actions workflow that builds and tests each Bazel module in your repo with the same targets as its existing CI config, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads what the repository already builds, and where, before writing a workflow. In a repository like bazelbuild/examples there is no .github/workflows directory, only a FUNDING.yml, and continuous integration runs on Buildkite from .bazelci/presubmit.yml, which imports nine files. Each one lists tasks with a working_directory, a platform and build_targets or test_targets: tutorial-cpp.yml builds ... in cpp-tutorial/stage1 through stage3 on Linux, macOS and Windows; tutorial-java.yml builds //:ProjectRunner in java-tutorial and //:runner in query-quickstart; bzlmod.yml builds //:main and the other named targets of the six bzlmod lessons on a three-platform matrix; misc.yml builds and tests java-maven with --test_tag_filters=-requires-docker and builds third-party-dependencies; rules.yml builds and tests rules on the latest release and on rolling Bazel, excluding -//runfiles/... on Windows; tutorial-rust.yml builds nine rust-examples on Ubuntu; frontend.yml builds and tests the pnpm workspace in frontend. Each module has its own MODULE.bazel, and a few pin a Bazel release in .bazelversion: 7.4.0 under the Go tutorial stages, 9.x in frontend, 7.x in third-party-dependencies. .pre-commit-config.yaml runs buildifier, renovate.json already enables the github-actions manager, and .gitignore ignores bazel-* and *MODULE.bazel.lock.

The workflow is generated from those files rather than invented. .github/workflows/ci.yml carries one build job with a strategy.matrix whose entries are the Linux tasks of the Buildkite config, each as a directory, a list of build targets, an optional list of test targets and optional extra flags, so java-maven keeps its --test_tag_filters=-requires-docker and rules its full ... build and test. Every step runs with working-directory set to the module and calls bazel build and, when listed, bazel test with --keep_going and a --remote_cache-free configuration, since the examples use none. bazel-contrib/setup-bazel provides Bazelisk and caches the Bazelisk download, the repository cache and the disk cache keyed per directory, and Bazelisk honours each module's .bazelversion; modules without one get USE_BAZEL_VERSION set to the LTS line, mirroring bazel: latest in misc.yml and rules.yml. A second small entry builds the rules directory on rolling Bazel, as rules.yml does.

Platforms are scoped on purpose. The first version runs on ubuntu-latest; a macos job covers only the tasks the Buildkite config runs there that cannot run on Linux, which is the Rust cross-compilation example; the Android directory, which needs an SDK and NDK, and the Windows tasks are listed in the pull request as follow-ups rather than wired in untested. A lint job runs pre-commit run --all-files so buildifier checks every BUILD and .bzl file, which Buildkite does not do today. The file sets permissions: contents: read, concurrency with cancel-in-progress, timeout-minutes per job and fail-fast: false, and pins actions/checkout and setup-bazel by commit SHA with a version comment.

The agent proves the matrix entries before it commits them. It downloads Bazelisk into its sandbox, runs the exact bazel build and bazel test commands for several entries, including cpp-tutorial/stage3, java-tutorial, bzlmod/01-depend_on_bazel_module and java-maven with its tag filter, and keeps each log. It runs pre-commit run --all-files once to see whether buildifier is clean on the current tree, and if it is not, puts that job in a separate commit so the rest of the workflow can merge first. README.md gets an Actions badge next to the Buildkite one.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "codex",
  "input": "Set up GitHub Actions CI for this Bazel repository and open a pull request. Read README.md, .pre-commit-config.yaml, renovate.json, .gitignore, every file under .bazelci and every MODULE.bazel and .bazelversion first. Write .github/workflows/ci.yml with a build job whose matrix is derived from the Linux tasks in the .bazelci files: one entry per working_directory with its build targets, its test targets where listed, and its flags, including --test_tag_filters=-requires-docker for java-maven; run bazel build and bazel test with working-directory set per entry, using bazel-contrib/setup-bazel with bazelisk, repository and disk caches keyed per directory, and USE_BAZEL_VERSION on the LTS line for modules without a .bazelversion. Add an entry for the rules directory on rolling Bazel, a macos job for only the Rust cross-compilation example, and a lint job running pre-commit run --all-files for buildifier. Leave the android directory and the Windows tasks out and list them as follow-ups in the PR. Set permissions contents read, concurrency with cancel-in-progress, timeout-minutes and fail-fast false, and pin actions by commit SHA with version comments. Install bazelisk in the sandbox and run the build and test commands for cpp-tutorial/stage3, java-tutorial, bzlmod/01-depend_on_bazel_module and java-maven to confirm the entries, run pre-commit once, and add an Actions badge to README.md. Put a buildifier fix, if one is needed, in its own commit.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that adds .github/workflows/ci.yml and a badge line in README.md, plus a separate commit of buildifier formatting if pre-commit reported any. The description lists every matrix entry with its directory and targets beside the Buildkite task it came from, so a reviewer can confirm nothing was dropped, and names the directories left for later and why.

The run's record keeps the Bazelisk install and each bazel build and bazel test log from the sandbox, so the reviewer can see that the commands in the matrix are the ones that passed, and the pre-commit output that decided whether a formatting commit was needed.

Before merging, a reviewer decides whether to keep Buildkite beside Actions during a transition, and whether branch protection should require the new build job, which only makes sense after it has run green on the merge of this pull request.

Run it on every repository that builds with Bazel

A platform team sends one POST /o/{org}/sessions per Bazel repository with this prompt and the repository in resources. Each run reads its own layout, so a single-module repository gets one job calling bazel test //... at the root, a repository with a .bazelrc that names a remote cache gets the cache's credentials wired from a secret the reviewer adds, and a repository with an existing Buildkite or Cirrus config gets its tasks translated as this one does.

Send a request_id, a UUID v5 of the repository's full name, so a retried call returns the run already started. Give the key a webhook_url and Rush POSTs run.completed for each run the key starts, with the pull request named in result.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A Bazel workflow copied from a blog post builds the wrong thing: //... at a root that holds a dozen independent modules fails on the first MODULE.bazel it cannot load, and a Bazel version the module does not pin changes under it. The agent reads the existing CI definition, derives each matrix entry from a task that already runs, and executes those commands in a sandbox of its own, so the workflow arrives with evidence that its entries build.

Bazel's first build of a C++, Java and Rust toolchain takes real time and disk, which is why it happens on the agent's machine rather than on a laptop, and why every log stays in the record. The same request goes to every Bazel repository in the org at once, each with its own pull request.

Frequently asked questions

Why not one job that runs bazel test //... at the root?

This repository is many separate Bazel modules, each with its own MODULE.bazel and some with their own .bazelversion, so there is no single root workspace to build. The matrix runs each directory on its own, which is also what the Buildkite config does.

Does it handle .bazelversion?

Bazelisk reads .bazelversion from the working directory, so each module builds with the release it pins. Modules without one get USE_BAZEL_VERSION from the workflow, set to the LTS line, and the rules directory additionally runs on rolling as the Buildkite config asks.

Why are Android and Windows left out?

The Android examples need an SDK and NDK the runner does not have, and the Windows tasks in the Buildkite config carry their own exclusions and DLL caveats. Adding either untested would ship a red job; the pull request lists them with the Buildkite task names so they can be added one at a time.

Will Renovate keep the actions up to date?

Yes. renovate.json already enables the github-actions manager alongside bazel, bazel-module and bazelisk, so the pinned action SHAs get the same update pull requests as bazel_dep versions.

More Bazel jobs

The same job on other stacks

Keep reading