ci: gate PRs on the Bazel lanes, alongside the legacy jobs (D1) (#6941)

* ci(bazel): gate the Bazel lane alongside the legacy jobs (D1)

pr.yml now calls bazel.yml (workflow_call) as its `bazel` job, and its
CI Gate / Required requires the call's aggregate (BAZEL) plus each gated
lane's result (BAZEL_TEST, BAZEL_PURE, BAZEL_EMBEDDED, BAZEL_DOLTSERVER).
No legacy job is removed: PR Core, build-artifacts, the pure-Go/js-wasm
check, domain+uow, contract corpus and pr-risk.yml's embedded tier stay
required (D2 is separate).

- bazel.yml drops its own pull_request/merge_group triggers, so a PR runs
  the lane once; push to main, workflow_dispatch and workflow_call stay.
- Every lane records job.status in an always() last step and exports it
  as a workflow_call output named after the job, next to the rbe job's
  rbe-mode / rbe-enabled.
- .github/scripts/bazel-gate.sh reads the call's rbe-mode/rbe-enabled and
  never re-derives the variable/fork/secret condition: mode skip allows
  every Bazel id to skip, local only the remote-only BAZEL_EMBEDDED,
  remote none; a missing or inconsistent mode fails the gate.
- bazel-integration runs in the PR call but stays advisory (its legacy
  counterparts in main.yml run only on push to main): no gate id, and the
  gate script excuses the aggregate failure only when that lane reported
  failure or cancelled in remote mode; the gated lanes are still checked
  on their own ids.
- Callers (pr.yml, nightly.yml) pass exactly the four RBE secrets that
  bazel.yml now declares, never `secrets: inherit`.
- Inside pr.yml's run the Bazel bd artifact is bazel-ci-build-artifacts,
  so it cannot collide with build-artifacts' ci-build-artifacts upload.
- bazel-autofix.yml now triggers on workflow "PR": the bazel-sync-patch
  artifact is uploaded inside the PR run, and "Bazel" runs are no longer
  PR events. Its security model is unchanged (base-branch checkout only,
  artifact read from the triggering run id, data-only patch).
- Policy tests (review D1 F3/F4/F7):
  - TestBazelLaneIsGatedAlongsideLegacy: every bazel.yml job is the rbe
    job, a gated lane (bazelLaneGateIDs) or an advisory lane with a
    reason; gate ids, env expressions and outputs are derived from that
    map; no re-derivation in the gate step or script.
  - TestBazelGateSimulation runs pr.yml's actual gate step over mode in
    {remote, local, skip} (pull_request and merge_group): the script's
    skips equal the ids whose job `if:` is false, and for each lane that
    should run, it alone skipped, failed or cancelled turns the gate red
    whatever the aggregate says; advisory, aggregate and invalid-mode
    cases too.
  - TestBazelArtifactNamesUniqueInCallerRuns: no artifact name collides
    within a pr.yml or nightly.yml run, following local workflow calls.
  - Autofix: workflow_run on "PR", which must upload bazel-sync-patch
    itself or through an unconditional local call.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): keep integration out of the PR call; pin the call's inputs (D1 review v2)

- N1: bazel.yml gains a string workflow_call input `integration`
  (default "on"); bazel-integration runs only when remote and
  `inputs.integration != 'off'`. A string, not a boolean: on push and
  dispatch the input is null, and null == false would silently stop the
  lane on main. pr.yml passes integration: "off" (main.yml's integration
  jobs, its legacy counterpart, run only on push to main). The gate no
  longer reads bazel-integration and bazel-gate.sh no longer excuses an
  aggregate failure: BAZEL is the call's result, red on a missing or
  inconsistent rbe mode.
- N3: pr.yml's call passes exactly build-artifact-name and
  integration: "off" (no rbe or other override).
- N4: bazel.yml's concurrency group never uses github.workflow (the
  caller's name in a call) and differs from each caller's group for every
  event, so the call cannot deadlock against pr.yml.
- N5: no caller of bazel.yml (pr.yml, nightly.yml) may have a
  pull_request_target or workflow_run trigger.
- Simulation: lanes' run modes are evaluated with pr.yml's call inputs;
  advisory lanes must not run in the PR call, gated lanes must run when
  remote.
- engdocs: runbook for main BUILD drift, a farm outage or the RBE cert
  expiry (~2027-09-27): fix main / renew, or unset RBE_WEST_WORKERS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): record the enforced required-gates ruleset and PR Risk's renamed gate

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): gate the proxied-server and server-Dolt storage lanes

bazel-proxied and bazel-server-storage (remote-only, #6940) join the
gated lanes like bazel-embedded: pr.yml's ci-gate requires
BAZEL_PROXIED and BAZEL_SERVER_STORAGE, each read from the lane's
job.status output (always() recorder step, workflow_call output named
after the job). Both run in pr.yml's call (no integration switch).

bazel-gate.sh allows them to skip in mode local (forks, Dependabot:
pr-risk.yml's legacy tiers cover those PRs) and in mode skip, never in
mode remote. The gate simulation derives this from the jobs' ifs, so
each lane skipped, failed or cancelled in remote mode turns the gate
red. Jobs are renamed "proxied-server tier" / "server-Dolt storage tier"
(shown as "Bazel / ..." under pr.yml's call).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-09-29 03:33:20 -07:00 • committed by GitHub
commit e1b2e79484
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 1161 additions and 91 deletions

56
.github/scripts/bazel-gate.sh vendored Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# pr.yml's ci-gate view of its bazel.yml call (the `bazel` job). bazel.yml's
# rbe job decides the execution mode once and exports it as the call's
# rbe-mode / rbe-enabled outputs; this script reads those outputs and never
# re-derives the decision (repo variable, fork, secrets) itself.
#
# bazel-gate.sh skips the Bazel gate ids whose job is skipped by design
# in this mode, for CI_GATE_SKIPPED_OK:
# skip: every lane and the aggregate (BAZEL)
# local: the remote-only BAZEL_EMBEDDED,
# BAZEL_PROXIED, BAZEL_SERVER_STORAGE
# remote: none
# bazel-gate.sh aggregate the value to gate on for BAZEL: the call's
# aggregate result, or, when the mode is missing
# or invalid (the rbe job failed, the call never
# started), an unexpected value that ci-gate.sh
# rejects.
#
# Any other skip, a failure, a cancellation, or a lane that should run but
# reported nothing (pr.yml maps an empty output to skipped) fails the gate.
#
# Inputs (environment): BAZEL_RBE_MODE, BAZEL_RBE_ENABLED (the call's
# rbe-mode / rbe-enabled outputs), BAZEL_CALL (needs.bazel.result).
set -euo pipefail
mode="${BAZEL_RBE_MODE:-}"
enabled="${BAZEL_RBE_ENABLED:-}"
valid=false
case "$mode/$enabled" in
remote/true | local/false | skip/false) valid=true ;;
esac
case "${1:-}" in
skips)
skips=()
if [[ "$valid" == true ]]; then
case "$mode" in
skip) skips+=(BAZEL BAZEL_TEST BAZEL_PURE BAZEL_EMBEDDED BAZEL_DOLTSERVER BAZEL_PROXIED BAZEL_SERVER_STORAGE) ;;
local) skips+=(BAZEL_EMBEDDED BAZEL_PROXIED BAZEL_SERVER_STORAGE) ;;
esac
fi
echo "${skips[*]-}"
;;
aggregate)
if [[ "$valid" != true ]]; then
echo "invalid-rbe-mode:$(printf '%s/%s' "$mode" "$enabled" | tr -cd 'a-z/')"
else
echo "${BAZEL_CALL:-}"
fi
;;
*)
echo "usage: $0 skips|aggregate" >&2
exit 2
;;
esac

View file

@ -10,9 +10,13 @@
# recipe (fork PRs). Drift elsewhere (third_party/patches, go.mod) is never
# patched; the failing run lists it for a human.
#
# Trigger: only "Bazel" (bazel.yml on pull_request), the one workflow that
# uploads bazel-sync-patch; pr.yml does not call bazel.yml. A run without the
# artifact is a no-op. bazel.yml builds the PR MERGE commit, so the patch also
# Trigger: only "PR" (pr.yml). bazel.yml has no pull_request trigger of its
# own: PRs run it through pr.yml's `bazel` job (workflow_call), so its
# bazel-sync-patch upload belongs to the PR run, and a failing sync step
# fails that run. The "Bazel" workflow's own runs (push to main, dispatch)
# are never pull_request events, so triggering on them would only ever be a
# no-op. A PR run without the artifact (it failed for other reasons) is a
# no-op too. bazel.yml builds the PR MERGE commit, so the patch also
# carries any drift main has; only files in packages the PR itself changed
# are pushed (see the script), so main's drift never lands on an unrelated PR.
#
@ -21,7 +25,10 @@
# cancel-in-progress, so the two bots queue instead of racing on one branch
# or cancelling a fix that is already running. The second one sees the moved
# head and stops; with the PAT its push retriggers CI, which re-derives the
# other fix.
# other fix. Both bots now fire on the same PR run's completion, so one runs
# while the other waits. GitHub keeps one pending job per group: a later PR
# run finishing inside that short window can displace a waiting job, whose
# fix the next failing run re-derives.
#
# SECURITY MODEL: this runs with write permissions via workflow_run, so it
# never checks out or executes PR code. It checks out the base default branch
@ -47,7 +54,7 @@ name: Bazel Autofix
on:
workflow_run:
workflows: ["Bazel"]
workflows: ["PR"]
types: [completed]
permissions:

View file

@ -1,11 +1,25 @@
# Bazel side-by-side lane (advisory). Runs `bazel test //... --config=ci`, the
# PR Core-parity selection (race, -short, dolt skip, -requires-docker), on the
# same commit as pr.yml's go test lanes, plus one job per mirrored CI job
# (pure-Go/js-wasm, the dolt-server lane, pr-risk.yml's embedded-Dolt,
# proxied-server and server-Dolt storage tiers, main.yml's integration jobs).
# It is NOT
# in ci-gate's CI_GATE_REQUIRED; promotion needs the equivalence record
# described in tools/bazel/equivalence.py and a human decision.
# Bazel side-by-side lane, gated alongside the legacy go test jobs. Runs
# `bazel test //... --config=ci`, the PR Core-parity selection (race, -short,
# dolt skip, -requires-docker), plus one job per mirrored CI job (pure-Go and
# js/wasm, the dolt-server lane, pr-risk.yml's embedded-Dolt, proxied-server
# and server-Dolt storage tiers, main.yml's integration jobs).
#
# PRs and merge groups run it through pr.yml's `bazel` job (workflow_call),
# in the same run as the legacy jobs it mirrors, which stay required too.
# This file has no pull_request or merge_group trigger of its own, so a PR
# runs the lane once. Every lane reports its job.status as a workflow_call
# output (named after the job) from an always() last step. pr.yml's ci-gate
# requires the call's aggregate result (BAZEL) and bazel-test, bazel-pure,
# bazel-embedded, bazel-doltserver, bazel-proxied and bazel-server-storage
# (BAZEL_TEST, BAZEL_PURE, BAZEL_EMBEDDED, BAZEL_DOLTSERVER, BAZEL_PROXIED,
# BAZEL_SERVER_STORAGE); .github/scripts/bazel-gate.sh turns the rbe job's
# rbe-mode output into the skips it accepts, so a lane skipped by its `if:`
# below passes and one that should have run and failed, was cancelled or
# reported nothing fails the gate. bazel-integration is not part of the PR
# call (pr.yml passes integration: "off"): its legacy counterparts, main.yml's
# integration jobs, run only on push to main, so it runs on push to main,
# dispatch and nightly, like them. Direct runs (push to main,
# workflow_dispatch, nightly.yml's call) gate nothing.
#
# Execution mode, decided once by the rbe job (every other job needs it and
# reads its outputs; none re-derives the condition) and passed to
@ -22,8 +36,9 @@
# bazel-proxied, bazel-server-storage), which are skipped.
# skip: same-repo runs while RBE_WEST_WORKERS is unset (the farm switch).
# workflow_dispatch with rbe=off simulates a fork run. The decision is also a
# workflow_call output, so a caller's gate can tell an expected skip from a
# missing lane.
# workflow_call output (rbe-mode, rbe-enabled), so pr.yml's gate can tell an
# expected skip from a missing lane without re-deriving it. Callers pass
# exactly the four RBE secrets below, never `secrets: inherit`.
#
# Accepted risk (same model as gascity's bazel-test.yml): on push, merge_group
# and same-repo pull_request runs, code from the PR head runs with the RBE
@ -32,8 +47,8 @@
# edit can point the BEP or the executor anywhere. Anyone who can push a
# branch here can therefore use or copy the certificate and write to the
# farm's cache. Fork PRs never get it: pull_request from a fork receives no
# secrets, this workflow has no pull_request_target trigger, and forks cannot
# write the runner cache. Nor do Dependabot PRs, which run as same-repo but
# secrets, neither this workflow nor its callers have a pull_request_target
# trigger, and forks cannot write the runner cache. Nor do Dependabot PRs, which run as same-repo but
# get no Actions secrets. In place: secrets are referenced by the setup step
# alone (plus the rbe job's emptiness test of RBE_WEST_EXECUTOR, which yields
# a boolean) and never by a workflow- or job-level env (policy-tested), decoded key
@ -43,8 +58,10 @@
# is issued to beads CI alone, so it can be revoked without affecting other
# clients. Maintainers decided (2026-09-28) that same-repo PRs keep remote
# execution under this model. Still open: a beads-only RBE_INSTANCE and
# farm-side denial of client action-cache writes. The lane is advisory and
# nothing downstream consumes artifacts built here.
# farm-side denial of client action-cache writes. Nothing downstream consumes
# artifacts built here yet; in pr.yml's run the bd artifact is
# bazel-ci-build-artifacts, so it cannot collide with the build-artifacts
# job's ci-build-artifacts.
#
# Runner cache: one entry per (.bazelversion, MODULE.bazel.lock) pair, about
# 2 GB (Bazel's --repository_cache plus Bazelisk's Bazel download), written
@ -56,9 +73,6 @@
name: Bazel
on:
pull_request:
branches: [ main, 'release/**' ]
merge_group:
push:
branches: [ main ]
workflow_dispatch:
@ -98,6 +112,38 @@ on:
type: string
required: false
default: ""
# A string, not a boolean: on push and dispatch inputs.integration is
# null, and null == false in GitHub's loose comparison, so a boolean
# test would silently stop the lane on main.
integration:
description: >
"off" skips bazel-integration (pr.yml: its legacy counterparts do
not run on PRs); anything else runs it where remote execution is on.
type: string
required: false
default: "on"
build-artifact-name:
description: >
Name of the uploaded bd artifact (ci-build-artifacts layout). pr.yml
sets bazel-ci-build-artifacts: its build-artifacts job uploads
ci-build-artifacts in the same run.
type: string
required: false
default: "ci-build-artifacts"
# Only what the rbe job and setup-bazel need; callers pass them
# explicitly. None is required: fork and Dependabot runs have none.
secrets:
RBE_WEST_EXECUTOR:
required: false
RBE_TLS_CERT:
required: false
RBE_TLS_KEY:
required: false
RBE_TLS_CA:
required: false
# The rbe job's decision, and each lane's job.status (success, failure or
# cancelled; empty when the lane was skipped or never reported). pr.yml's
# ci-gate reads them through .github/scripts/bazel-gate.sh.
outputs:
rbe-enabled:
description: "'true' when the lanes executed remotely on rbe-west, else 'false'"
@ -105,8 +151,31 @@ on:
rbe-mode:
description: "remote, local (no remote-only jobs) or skip (no jobs): the rbe job's decision"
value: ${{ jobs.rbe.outputs.mode }}
bazel-test:
description: "bazel-test's job.status"
value: ${{ jobs.bazel-test.outputs.result }}
bazel-pure:
description: "bazel-pure's job.status"
value: ${{ jobs.bazel-pure.outputs.result }}
bazel-embedded:
description: "bazel-embedded's job.status"
value: ${{ jobs.bazel-embedded.outputs.result }}
bazel-integration:
description: "bazel-integration's job.status (empty in pr.yml's call, which turns the lane off)"
value: ${{ jobs.bazel-integration.outputs.result }}
bazel-doltserver:
description: "bazel-doltserver's job.status"
value: ${{ jobs.bazel-doltserver.outputs.result }}
bazel-proxied:
description: "bazel-proxied's job.status"
value: ${{ jobs.bazel-proxied.outputs.result }}
bazel-server-storage:
description: "bazel-server-storage's job.status"
value: ${{ jobs.bazel-server-storage.outputs.result }}
# Main runs always finish (they may save the runner cache); PR runs supersede.
# Main runs always finish (they may save the runner cache); PR runs (called
# from pr.yml, whose own group cancels the calling run too) supersede. The
# group differs from pr.yml's, as a called workflow's must.
concurrency:
group: bazel-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
@ -127,7 +196,7 @@ jobs:
# value, and the step runs no repository code (no checkout). Dependabot
# runs read vars but get no secrets, so they come out local, not remote.
rbe:
name: Bazel / execution mode
name: execution mode
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
@ -166,7 +235,7 @@ jobs:
echo "Bazel execution mode: **$mode** (RBE_WEST_WORKERS on: $RBE_VAR_ON, rbe=off: $RBE_INPUT_OFF, fork: $FORK, executor secret: $HAS_EXECUTOR)" | tee -a "$GITHUB_STEP_SUMMARY"
bazel-test:
name: Bazel / test (advisory)
name: test
# Remote-execution runs use the org's Blacksmith pool (the farm's edge
# admits it; GitHub-hosted runners are refused) and do not count against
# GitHub's concurrent-job cap. Local runs (forks, rbe=off, no secrets)
@ -179,6 +248,8 @@ jobs:
# runs while RBE_WEST_WORKERS is unset).
if: ${{ needs.rbe.outputs.mode != 'skip' }}
timeout-minutes: 100
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -222,7 +293,7 @@ jobs:
else tier=local; fi
echo "tier=$tier" >> "$GITHUB_OUTPUT"
{
echo "### Bazel / test (advisory)"
echo "### Bazel / test"
echo
echo "Tier **$tier**: remote execution $REMOTE, runner cache restored $RESTORED."
echo
@ -259,7 +330,7 @@ jobs:
if: ${{ always() && steps.bd-artifact.outcome == 'success' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ci-build-artifacts
name: ${{ inputs.build-artifact-name || 'ci-build-artifacts' }}
path: ${{ runner.temp }}/bd-artifacts/
retention-days: 1
if-no-files-found: error
@ -366,6 +437,16 @@ jobs:
path: ${{ runner.temp }}/bazel-ci-cache
key: bazel-repo-v2-${{ runner.os }}-${{ hashFiles('.bazelversion', 'MODULE.bazel.lock') }}
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr.yml's check-cmd-bd-puregeo-tests job ("Check pure-Go and js/wasm
# boundaries (CGO_ENABLED=0)") with Bazel-built binaries: --config=pure
# builds bd and the job's three pure test binaries and runs its -short
@ -374,12 +455,14 @@ jobs:
# js/wasm, which the Go SDK's go_js_wasm_exec runs under node with the job's
# exact pass-count guard.
bazel-pure:
name: Bazel / pure-Go and js/wasm (advisory)
name: pure-Go and js/wasm
# Same runner and skip rule as bazel-test.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.mode != 'skip' }}
timeout-minutes: 90
outputs:
result: ${{ steps.result.outputs.result }}
env:
PURE_CMD_BD_TESTS: '^Test(Help|CheckRemoteSafety|FormatDestroyToken|ShouldWireInitRemote|ExtractPrefix|IsNumericID|GetWorktreeGitDir|DriftItemStatuses|RunDriftChecks|IsServerProbablyRunning|CheckHooksDriftNotGitRepo|CheckServerDriftNoBeadsDir|CheckRemoteDriftNoBeadsDir|NocgoFactoriesHonorSharedServer|NocgoNewDoltStoreFromConfig_ErrorSuggestsCorrectFlag|NocgoNewReadOnlyStoreFromConfig_ErrorSuggestsCorrectFlag)'
steps:
@ -487,6 +570,16 @@ jobs:
echo "pure cmd/bd subset: $n test cases"
(( n > 0 ))
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr-risk.yml's embedded-Dolt tier ("Test (Embedded Dolt Cmd N/20)",
# "Test (Embedded Dolt Storage N/5)", "Test (Embedded Dolt Conformance -
# core/audit)") as --config=embedded: the embedded-tagged variants of
@ -497,7 +590,7 @@ jobs:
# bazel-test's critical path and budget, and it compiles nothing bazel-test
# does not (same race configuration, shared through the remote cache).
bazel-embedded:
name: Bazel / embedded Dolt tier (advisory)
name: embedded Dolt tier
# Remote execution only: skipped unless the rbe job chose remote (no
# fork, rbe=off or secret-less run). Locally the tier is 27 race test
# processes (~7-10k test-seconds) on one runner, an hour or more per run
@ -509,6 +602,8 @@ jobs:
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' }}
timeout-minutes: 60
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -554,6 +649,16 @@ jobs:
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# main.yml's "Main Linux integration packages (N/6)" and "Main Linux
# integration cmd/bd (N/8)" jobs (nightly.yml's Full Test Suite runs the
# same go test in one job) as --config=integration: every package with
@ -567,14 +672,17 @@ jobs:
# which no run here has. check_testcases.py still catches a target or
# shard that ran no tests.
bazel-integration:
name: Bazel / integration (advisory)
name: integration (advisory)
# Remote execution only, like bazel-embedded: locally the tagged race
# build of //... plus 14 jobs' worth of tests on one runner is well over
# the timeout, for tests main.yml's integration jobs already run.
# the timeout, for tests main.yml's integration jobs already run. Off in
# pr.yml's call (integration: "off"), as those jobs are off on PRs.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' }}
if: ${{ needs.rbe.outputs.enabled == 'true' && inputs.integration != 'off' }}
timeout-minutes: 40
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -621,6 +729,15 @@ jobs:
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output (for
# symmetry; pr.yml's call turns this lane off).
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr.yml's container-backed jobs, "Test (storage domain + uow)" and
# "Contract corpus", as Bazel's dolt-server lane: --config=doltserver runs
# the dolt-server variants (domain/..., uow in 8 shards, tracker/...,
@ -630,12 +747,14 @@ jobs:
# (--config=docker: the same suites against testcontainers on this runner,
# no-remote-exec) stays the A/B control: dispatch with dolt-lane=docker.
bazel-doltserver:
name: Bazel / dolt-server lane (advisory)
name: dolt-server lane
# Same runner and skip rule as bazel-test.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.mode != 'skip' }}
timeout-minutes: 90
outputs:
result: ${{ steps.result.outputs.result }}
env:
BAZEL_DOLT_LANE: ${{ inputs.dolt-lane || 'doltserver' }}
steps:
@ -679,6 +798,16 @@ jobs:
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr-risk.yml's proxied-server tier, "Test (Proxied Dolt Cmd N/15)", as
# --config=doltserver-proxied: //cmd/bd:bd_proxied_test runs the job's
# shard script in 15 Bazel shards, so shard k runs exactly job k's tests.
@ -686,10 +815,10 @@ jobs:
# shared with bazel-doltserver through the remote cache. PR Risk builds
# its bd-cmd-test with -race, as here; main.yml's test-proxied-cmd twin
# uses build-artifacts' non-race bd-cmd-test, so this lane is the stricter
# of the two. A job of its own, not gated by any integration switch, so a
# caller's gate can decide on it separately.
# of the two. A job of its own, not gated by any integration switch: it
# runs in pr.yml's call and its gate requires it (BAZEL_PROXIED).
bazel-proxied:
name: Bazel / proxied-server tier (advisory)
name: proxied-server tier
# Remote execution only, like bazel-embedded: 15 shards of ~5-10
# minutes, each with a dolt sql-server busy on ~4 cores, do not fit a
# GitHub-hosted runner.
@ -697,6 +826,8 @@ jobs:
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' }}
timeout-minutes: 30
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -741,6 +872,16 @@ jobs:
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"
# pr-risk.yml's server-Dolt storage tier, "Test (Server Dolt Conformance)"
# and "Test (Server Dolt Full Suite N/16)", as --config=doltserver-integration:
# the conformance and 16-shard full-suite variants of
@ -749,15 +890,18 @@ jobs:
# exactly --config=integration's build flags, so it compiles nothing
# bazel-integration does not (shared through the remote cache). A job of
# its own, not gated by any integration switch: this is a PR-time tier,
# unlike main.yml's integration jobs.
# unlike main.yml's integration jobs, and pr.yml's gate requires it
# (BAZEL_SERVER_STORAGE).
bazel-server-storage:
name: Bazel / server-Dolt storage tier (advisory)
name: server-Dolt storage tier
# Remote execution only, like bazel-integration: locally the tagged race
# build of //... alone is most of the timeout.
needs: rbe
runs-on: ${{ needs.rbe.outputs.enabled == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}
if: ${{ needs.rbe.outputs.enabled == 'true' }}
timeout-minutes: 30
outputs:
result: ${{ steps.result.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -801,3 +945,13 @@ jobs:
bazel-testlogs/**/test.xml
if-no-files-found: ignore
retention-days: 7
# Last step: the job's result as a workflow_call output for pr.yml's
# ci-gate. always() runs it after a failure, a timeout or a
# cancellation too.
- name: Record job result
id: result
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"

View file

@ -96,14 +96,19 @@ jobs:
retention-days: 7
# Bazel lane with the full go test equivalence listing and the skip-parity
# check (advisory, like the PR run). Remote execution when the repo secrets
# are present.
# check (reported here; PRs gate on it through pr.yml). Remote execution
# when the repo secrets are present; bazel.yml gets those four and nothing
# else.
bazel:
name: Bazel equivalence (full detail)
needs: bazel-go-test-json
if: ${{ !cancelled() && (github.event_name == 'schedule' || inputs.suite == 'bazel') }}
uses: ./.github/workflows/bazel.yml
secrets: inherit
secrets:
RBE_WEST_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR }}
RBE_TLS_CERT: ${{ secrets.RBE_TLS_CERT }}
RBE_TLS_KEY: ${{ secrets.RBE_TLS_KEY }}
RBE_TLS_CA: ${{ secrets.RBE_TLS_CA }}
with:
details: true
go-test-json-artifact: bazel-equivalence-go-test-json

View file

@ -1434,6 +1434,31 @@ jobs:
throw 'Cygwin Make shell smoke failed'
}
# The Bazel lane (bazel.yml), gated alongside the legacy jobs it mirrors
# (PR Core, build-artifacts, the pure-Go/js-wasm check, domain+uow and
# contract corpus, and pr-risk.yml's embedded-Dolt, proxied-server and
# server-Dolt storage tiers), all of which stay required. bazel.yml has no pull_request/merge_group trigger of its own:
# this call is its only PR run. It gets the four RBE secrets and nothing
# else; its rbe job decides remote, local (forks, Dependabot: no
# remote-only lanes) or skip, and exports that for ci-gate. Its
# bazel-integration lane is off here (main.yml's integration jobs, its
# legacy counterpart, run only on push to main; bazel.yml runs it there).
# Its bd artifact is renamed so it cannot collide with build-artifacts'
# upload.
bazel:
name: Bazel
permissions:
contents: read
uses: ./.github/workflows/bazel.yml
secrets:
RBE_WEST_EXECUTOR: ${{ secrets.RBE_WEST_EXECUTOR }}
RBE_TLS_CERT: ${{ secrets.RBE_TLS_CERT }}
RBE_TLS_KEY: ${{ secrets.RBE_TLS_KEY }}
RBE_TLS_CA: ${{ secrets.RBE_TLS_CA }}
with:
build-artifact-name: bazel-ci-build-artifacts
integration: "off"
ci-gate:
name: CI Gate / Required
runs-on: ubuntu-latest
@ -1460,6 +1485,7 @@ jobs:
- fmt-check
- lint
- windows-make-shell
- bazel
if: ${{ always() }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
@ -1490,6 +1516,13 @@ jobs:
FMT_CHECK
LINT
WINDOWS_MAKE_SHELL
BAZEL
BAZEL_TEST
BAZEL_PURE
BAZEL_EMBEDDED
BAZEL_DOLTSERVER
BAZEL_PROXIED
BAZEL_SERVER_STORAGE
BUILD_ARTIFACTS: ${{ needs.build-artifacts.result }}
CHECK_BUILD_TAGS: ${{ needs.check-build-tags.result }}
CHECK_CMD_BD_PUREGEO_TESTS: ${{ needs.check-cmd-bd-puregeo-tests.result }}
@ -1512,10 +1545,32 @@ jobs:
FMT_CHECK: ${{ needs.fmt-check.result }}
LINT: ${{ needs.lint.result }}
WINDOWS_MAKE_SHELL: ${{ needs.windows-make-shell.result }}
# bazel.yml's lanes report their job.status as outputs; a lane that
# did not report (skipped, or lost before its last step) reads as
# skipped, which passes only in the modes bazel-gate.sh allows.
BAZEL_TEST: ${{ needs.bazel.outputs.bazel-test || 'skipped' }}
BAZEL_PURE: ${{ needs.bazel.outputs.bazel-pure || 'skipped' }}
BAZEL_EMBEDDED: ${{ needs.bazel.outputs.bazel-embedded || 'skipped' }}
BAZEL_DOLTSERVER: ${{ needs.bazel.outputs.bazel-doltserver || 'skipped' }}
BAZEL_PROXIED: ${{ needs.bazel.outputs.bazel-proxied || 'skipped' }}
BAZEL_SERVER_STORAGE: ${{ needs.bazel.outputs.bazel-server-storage || 'skipped' }}
# Inputs of bazel-gate.sh, which sets BAZEL (the call's aggregate,
# red on a missing or inconsistent mode) and the expected skips
# from bazel.yml's own rbe job decision.
BAZEL_CALL: ${{ needs.bazel.result }}
BAZEL_RBE_MODE: ${{ needs.bazel.outputs.rbe-mode }}
BAZEL_RBE_ENABLED: ${{ needs.bazel.outputs.rbe-enabled }}
run: |
skipped_ok=""
if [[ "$GITHUB_EVENT_NAME" == "merge_group" ]]; then
skipped_ok="CHECK_NO_BEADS_CHANGES"
fi
# Bazel lanes skipped by design in the call's execution mode (all
# of them in mode skip, the remote-only embedded, proxied and
# server-storage tiers in mode local), and the aggregate unless the
# mode is missing or invalid.
skipped_ok="$skipped_ok $(bash .github/scripts/bazel-gate.sh skips)"
BAZEL="$(bash .github/scripts/bazel-gate.sh aggregate)"
export BAZEL
export CI_GATE_SKIPPED_OK="$skipped_ok"
bash .github/scripts/ci-gate.sh

View file

@ -1,7 +1,7 @@
# Required Check Topology
Status: aggregate gate jobs are implemented; branch-protection and ruleset
adoption remain pending. The aggregate-gate policy below remains maintainer
Status: aggregate gate jobs are implemented, and the default-branch ruleset
requires both aggregates (see Current State). The aggregate-gate policy below remains maintainer
context, but `.github/workflows/*.yml` and their structural tests are
authoritative for current job membership and display names. Copied workflow
wiring and rollout steps in this note describe the initial rollout, not the
@ -36,8 +36,39 @@ Current PR-related workflow names:
- `.github/workflows/pr.yml`: `PR`
Runs on `pull_request` and `merge_group`. Contains the baseline PR jobs,
Linux build artifact stage, policy/lint compatibility jobs, package gates
that consume the Linux artifact, focused storage domain/uow coverage, and
the baseline aggregate gate `PR / CI Gate / Required`.
that consume the Linux artifact, focused storage domain/uow coverage, the
Bazel lane (the `bazel` job calls `bazel.yml`), and the baseline aggregate
gate `PR / CI Gate / Required`.
- `.github/workflows/bazel.yml`: `Bazel`
Runs on `push` to `main`, manual dispatch, and `workflow_call` only. PRs and
merge groups run it once, through `pr.yml`'s `bazel` job. Its `rbe` job
decides the execution mode once (`remote`, `local` for fork and Dependabot
PRs, or `skip` while the `RBE_WEST_WORKERS` repo variable is unset) and
exports it as the `rbe-mode` / `rbe-enabled` outputs; every lane exports its
`job.status` as an output named after the job. `pr.yml`'s gate requires the
call's result (`BAZEL`) and `BAZEL_TEST`, `BAZEL_PURE`, `BAZEL_EMBEDDED`,
`BAZEL_DOLTSERVER`, `BAZEL_PROXIED` and `BAZEL_SERVER_STORAGE`. The legacy jobs these mirror stay required in `pr.yml`
and `pr-risk.yml`.
`.github/scripts/bazel-gate.sh` reads the exported mode, never the variable
or the fork flag: mode `skip` allows every Bazel id to skip, mode `local`
allows only the remote-only `BAZEL_EMBEDDED`, `BAZEL_PROXIED` and
`BAZEL_SERVER_STORAGE` (fork and Dependabot PRs rely on `pr-risk.yml`'s
legacy tiers for those), and mode `remote` allows none.
A lane that should run and fails, is cancelled, or reports no result fails
the gate, and so does a missing or invalid mode.
`bazel-integration` is not part of the PR call (`pr.yml` passes
`integration: "off"`) and has no gate id: its legacy counterparts
(`main.yml`'s integration jobs) run only on push to `main`, and so does it
(plus dispatch and nightly). `scripts/ci_workflow_test.go` fails when a new
`bazel.yml` job has neither a gate id nor an advisory entry.
Runbook: if `main`'s Bazel BUILD files drift (every PR's Bazel lanes go
red, and autofix only patches packages the PR itself changed), the RBE
farm is down, or the beads CI RBE client certificate expires (about
2027-09-27; a partial secret set also fails every same-repo run), fix
`main` (`make bazel-sync`) or renew the secrets, or unset the
`RBE_WEST_WORKERS` repo variable: same-repo runs then take mode `skip`,
which the gate accepts (fork PRs still run locally, so drift on `main`
still reaches them).
- `.github/workflows/pr-risk.yml`: `PR Risk`
Runs on `pull_request` and `merge_group`. Contains embedded Dolt risk
detection, embedded build/test shards, the Nix flake smoke check, and the
@ -63,7 +94,17 @@ Current PR-related workflow names:
As of 2026-05-26, the live `gastownhall/beads` ruleset named
`Protect main - light (beads and gastown)` enforces deletion and non-fast-forward
protection on the default branch. It does not currently require status checks.
protection on the default branch. It does not require status checks.
Since 2026-09-29 a second, beads-only ruleset, `beads main: required CI
gates`, is active on the default branch. It requires the GitHub Actions
checks `CI Gate / Required` (`pr.yml`, which includes the Bazel lanes through
the `bazel` call) and `PR Risk Gate / Required` (`pr-risk.yml`). PR Risk's
gate job was renamed from `CI Gate / Required` to `PR Risk Gate / Required`
(#6939), so the two required contexts are distinct; before that both
workflows reported the same check name. Organization admins and one team
may bypass it. There is no merge queue, so the checks run on
`pull_request`.
## Required Check Contract
@ -102,6 +143,7 @@ Do not require these existing check names directly:
- `Upgrade smoke (<version> -> candidate)`
- `Resolve versions to test`
- `nix build .#default`
- `Bazel / test` and the other jobs of `bazel.yml`
Those checks should remain visible for diagnosis, but branch protection should
point at aggregate gates after the gate jobs are verified.

View file

@ -1204,6 +1204,11 @@ type ciWorkflow struct {
}
type ciWorkflowJob struct {
Name string `yaml:"name"`
Uses string `yaml:"uses"`
With map[string]string `yaml:"with"`
Secrets any `yaml:"secrets"`
Permissions any `yaml:"permissions"`
Needs ciWorkflowStringList `yaml:"needs"`
Steps []ciWorkflowStep `yaml:"steps"`
RunsOn string `yaml:"runs-on"`
@ -1461,7 +1466,7 @@ func captureOne(t *testing.T, pattern, body, source string) string {
return matches[1]
}
// --- Bazel lane (.github/workflows/bazel.yml, advisory) ----------------------
// --- Bazel lane (.github/workflows/bazel.yml, gated through pr.yml) ----------
const (
bazelWorkflowName = "bazel.yml"
@ -1502,8 +1507,59 @@ const (
)
// The only triggers bazel.yml may have. pull_request_target (and
// workflow_run) would run with secrets in the context of fork PRs.
var bazelWorkflowTriggers = []string{"merge_group", "pull_request", "push", "workflow_call", "workflow_dispatch"}
// workflow_run) would run with secrets in the context of fork PRs. PRs and
// merge groups reach it only through pr.yml's call, so it runs once per PR.
var bazelWorkflowTriggers = []string{"push", "workflow_call", "workflow_dispatch"}
// What pr.yml's ci-gate does with each bazel.yml lane (every job but the rbe
// job, whose rbe-mode output the gate reads): a gated lane has a
// CI_GATE_REQUIRED id read from its workflow_call output; an advisory lane is
// not part of pr.yml's call at all (the call's inputs turn it off, checked by
// TestBazelGateSimulation), for the recorded reason. A new job in bazel.yml
// must be added to one of the two (TestBazelLaneIsGatedAlongsideLegacy).
var bazelLaneGateIDs = map[string]string{
bazelJobName: "BAZEL_TEST",
bazelPureJobName: "BAZEL_PURE",
bazelEmbedJobName: "BAZEL_EMBEDDED",
bazelDoltJobName: "BAZEL_DOLTSERVER",
// Remote-only PR Risk tiers (fork and Dependabot PRs rely on
// pr-risk.yml's legacy jobs, like the embedded tier's).
bazelProxiedJobName: "BAZEL_PROXIED",
bazelServerJobName: "BAZEL_SERVER_STORAGE",
}
var bazelAdvisoryLanes = map[string]string{
bazelIntegJobName: "its legacy counterparts, main.yml's integration jobs, run only on push to main",
}
// bazel-integration's if: remote only, and off when the caller passes
// integration: "off" (pr.yml). A string input: on push and dispatch it is
// null, and null != 'off', so the lane keeps running on main.
const bazelIntegIf = "${{ needs.rbe.outputs.enabled == 'true' && inputs.integration != 'off' }}"
// pr.yml's call of bazel.yml: exactly these inputs (review D1 v2 N3). An rbe
// override would put every PR in local mode and ungate the embedded tier
// while the gate stays self-consistent.
var bazelPRCallWith = map[string]string{
"build-artifact-name": "bazel-ci-build-artifacts",
"integration": "off",
}
// The call's aggregate result (needs.bazel.result, through bazel-gate.sh).
const bazelAggregateGateID = "BAZEL"
// The gate script and the rbe job's execution modes.
const bazelGateScript = ".github/scripts/bazel-gate.sh"
var bazelRBEModes = []string{"remote", "local", "skip"}
// The four RBE secrets, the only ones a caller may hand bazel.yml.
var bazelCallSecrets = map[string]string{
"RBE_WEST_EXECUTOR": "${{ secrets.RBE_WEST_EXECUTOR }}",
"RBE_TLS_CERT": "${{ secrets.RBE_TLS_CERT }}",
"RBE_TLS_KEY": "${{ secrets.RBE_TLS_KEY }}",
"RBE_TLS_CA": "${{ secrets.RBE_TLS_CA }}",
}
type ciCompositeAction struct {
Runs struct {
@ -1529,15 +1585,16 @@ func readSetupBazelAction(t *testing.T) ciCompositeAction {
return action
}
// The Bazel lane is advisory until the equivalence record and a human promote
// it: no ci-gate may need it or list it in CI_GATE_REQUIRED.
func TestBazelWorkflowIsAdvisory(t *testing.T) {
// bazel.yml's jobs, their runner, rbe-west gate and skip rules, and the
// setup-bazel env. The skip rules are also what pr.yml's ci-gate accepts as a
// skip (TestBazelGateSimulation).
func TestBazelWorkflowJobsAndExecutionMode(t *testing.T) {
workflow := readCIWorkflow(t, bazelWorkflowName)
var names []string
for name, job := range workflow.Jobs {
names = append(names, name)
if job.ContinueOnError {
t.Errorf("%s continue-on-error hides failures; the lane is advisory by staying out of ci-gate", name)
t.Errorf("%s continue-on-error hides failures from pr.yml's ci-gate", name)
}
if job.TimeoutMinutes == 0 {
t.Errorf("%s has no timeout-minutes", name)
@ -1580,6 +1637,9 @@ func TestBazelWorkflowIsAdvisory(t *testing.T) {
if bazelRemoteOnlyJobs[name] {
want = wantRemoteOnlyIf
}
if name == bazelIntegJobName {
want = bazelIntegIf
}
if job.If != want {
t.Errorf("%s if = %q, want %q", name, job.If, want)
}
@ -1589,23 +1649,694 @@ func TestBazelWorkflowIsAdvisory(t *testing.T) {
}
}
}
for _, name := range []string{"pr.yml", "pr-risk.yml"} {
for jobName, j := range readCIWorkflow(t, name).Jobs {
for _, need := range j.Needs {
if strings.Contains(strings.ToLower(need), "bazel") {
t.Errorf("%s job %q needs %q; the Bazel lane is advisory", name, jobName, need)
}
type bazelWorkflowCall struct {
Inputs map[string]struct {
Type string `yaml:"type"`
Default string `yaml:"default"`
} `yaml:"inputs"`
Secrets map[string]struct {
Required bool `yaml:"required"`
} `yaml:"secrets"`
Outputs map[string]struct {
Value string `yaml:"value"`
} `yaml:"outputs"`
}
func readBazelWorkflowCall(t *testing.T) bazelWorkflowCall {
t.Helper()
path := filepath.Join(sourceRepoRoot(t), ".github", "workflows", bazelWorkflowName)
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
var doc struct {
On struct {
WorkflowCall bazelWorkflowCall `yaml:"workflow_call"`
} `yaml:"on"`
}
if err := yaml.Unmarshal(data, &doc); err != nil {
t.Fatalf("parse %s: %v", path, err)
}
return doc.On.WorkflowCall
}
// Slice D1: pr.yml calls bazel.yml once per PR and merge group, and its
// ci-gate requires the Bazel lanes in addition to (not instead of) the legacy
// jobs they mirror, which stay required in pr.yml and pr-risk.yml.
func TestBazelLaneIsGatedAlongsideLegacy(t *testing.T) {
workflow := readCIWorkflow(t, bazelWorkflowName)
call := readBazelWorkflowCall(t)
// Every job is the rbe job, a gated lane or an advisory lane (review D1
// F4): a new job cannot join the call without a decision about the gate.
wantCallOutputs := map[string]string{
"rbe-enabled": "${{ jobs." + bazelRBEJobName + ".outputs.enabled }}",
"rbe-mode": "${{ jobs." + bazelRBEJobName + ".outputs.mode }}",
}
for name, job := range workflow.Jobs {
if name == bazelRBEJobName {
continue
}
_, gated := bazelLaneGateIDs[name]
_, advisory := bazelAdvisoryLanes[name]
if gated == advisory {
t.Errorf("%s job %s: gated=%v advisory=%v; add it to exactly one of bazelLaneGateIDs (with a CI_GATE_REQUIRED id in pr.yml) or bazelAdvisoryLanes (with the reason)",
bazelWorkflowName, name, gated, advisory)
}
// Each lane reports its job.status from an always() last step.
if !reflect.DeepEqual(job.Outputs, map[string]string{"result": "${{ steps.result.outputs.result }}"}) {
t.Errorf("%s outputs = %v, want only result from the result step", name, job.Outputs)
}
last := job.Steps[len(job.Steps)-1]
if last.ID != "result" || last.If != "${{ always() }}" || !reflect.DeepEqual(last.Env, map[string]string{"JOB_STATUS": "${{ job.status }}"}) ||
last.Run != `echo "result=$JOB_STATUS" >> "$GITHUB_OUTPUT"` {
t.Errorf("%s last step = %+v; want the always() job.status recorder", name, last)
}
wantCallOutputs[name] = "${{ jobs." + name + ".outputs.result }}"
}
for name := range bazelLaneGateIDs {
if _, ok := workflow.Jobs[name]; !ok {
t.Errorf("bazelLaneGateIDs lists %s, which %s does not have", name, bazelWorkflowName)
}
}
for name := range bazelAdvisoryLanes {
if _, ok := workflow.Jobs[name]; !ok {
t.Errorf("bazelAdvisoryLanes lists %s, which %s does not have", name, bazelWorkflowName)
}
}
gotCallOutputs := map[string]string{}
for name, out := range call.Outputs {
gotCallOutputs[name] = out.Value
}
if !reflect.DeepEqual(gotCallOutputs, wantCallOutputs) {
t.Errorf("workflow_call outputs = %v, want %v", gotCallOutputs, wantCallOutputs)
}
// One caller on PR events: pr.yml's bazel job, with the four RBE secrets
// only, read-only contents, and no if (the rbe job decides).
pr := readCIWorkflow(t, "pr.yml")
bazel := pr.job(t, "bazel")
if bazel.Uses != "./.github/workflows/"+bazelWorkflowName || bazel.If != "" || len(bazel.Needs) != 0 {
t.Errorf("pr.yml bazel job uses=%q if=%q needs=%v; want an unconditional call of %s", bazel.Uses, bazel.If, bazel.Needs, bazelWorkflowName)
}
if !reflect.DeepEqual(bazel.Permissions, map[string]any{"contents": "read"}) {
t.Errorf("pr.yml bazel job permissions = %v, want contents: read", bazel.Permissions)
}
if !reflect.DeepEqual(bazel.With, bazelPRCallWith) {
t.Errorf("pr.yml bazel job with = %v, want exactly %v (no rbe or other override)", bazel.With, bazelPRCallWith)
}
if in := call.Inputs["integration"]; in.Type != "string" || in.Default != "on" {
t.Errorf("workflow_call input integration = %+v, want type string, default on (a boolean reads null as false on push)", in)
}
var declared []string
for name := range call.Secrets {
declared = append(declared, name)
if call.Secrets[name].Required {
t.Errorf("workflow_call secret %s is required; fork and Dependabot runs have none", name)
}
}
sort.Strings(declared)
var wantSecrets []string
for name := range bazelCallSecrets {
wantSecrets = append(wantSecrets, name)
}
sort.Strings(wantSecrets)
if !reflect.DeepEqual(declared, wantSecrets) {
t.Errorf("workflow_call secrets = %v, want %v", declared, wantSecrets)
}
callers := 0
entries, err := os.ReadDir(filepath.Join(sourceRepoRoot(t), ".github", "workflows"))
if err != nil {
t.Fatal(err)
}
for _, entry := range entries {
if !strings.HasSuffix(entry.Name(), ".yml") || entry.Name() == bazelWorkflowName {
continue
}
for jobName, job := range readCIWorkflow(t, entry.Name()).Jobs {
if !strings.HasSuffix(job.Uses, "/"+bazelWorkflowName) {
continue
}
callers++
// A caller forwards the RBE secrets: it must never run in a
// fork's privileged context (review D1 v2 N5).
for _, trigger := range yamlMapKeys(readYAMLNode(t, filepath.Join(".github", "workflows", entry.Name())), "on") {
if trigger == "pull_request_target" || trigger == "workflow_run" {
t.Errorf("%s calls %s and has trigger %s; a caller may not run with secrets in a fork PR's context", entry.Name(), bazelWorkflowName, trigger)
}
}
for _, step := range j.Steps {
for key, value := range step.Env {
if strings.Contains(strings.ToUpper(key), "BAZEL") ||
(key == "CI_GATE_REQUIRED" && strings.Contains(strings.ToUpper(value), "BAZEL")) {
t.Errorf("%s job %q step %q env %s=%q wires the Bazel lane into a gate", name, jobName, step.Name, key, value)
}
if entry.Name() != "pr.yml" && entry.Name() != "nightly.yml" {
t.Errorf("%s job %s calls %s; only pr.yml (PRs) and nightly.yml may", entry.Name(), jobName, bazelWorkflowName)
}
got := map[string]string{}
if m, ok := job.Secrets.(map[string]any); ok {
for k, v := range m {
got[k] = fmt.Sprint(v)
}
}
if !reflect.DeepEqual(got, bazelCallSecrets) {
t.Errorf("%s job %s secrets = %v, want exactly %v (never inherit)", entry.Name(), jobName, job.Secrets, bazelCallSecrets)
}
}
}
if callers != 2 {
t.Errorf("%d jobs call %s, want 2 (pr.yml, nightly.yml)", callers, bazelWorkflowName)
}
// The gate: needs the call and requires exactly BAZEL plus one id per
// gated lane, each read from the lane's output (a missing output reads
// as skipped). BAZEL itself comes from bazel-gate.sh, never the env.
gate := pr.job(t, "ci-gate")
evaluate := gate.step(t, "Evaluate CI gate")
required := strings.Fields(evaluate.Env["CI_GATE_REQUIRED"])
if !contains(gate.Needs, "bazel") {
t.Errorf("ci-gate needs = %v, want bazel", gate.Needs)
}
wantBazelIDs := []string{bazelAggregateGateID}
for lane, id := range bazelLaneGateIDs {
wantBazelIDs = append(wantBazelIDs, id)
if want := "${{ needs.bazel.outputs." + lane + " || 'skipped' }}"; evaluate.Env[id] != want {
t.Errorf("ci-gate env %s = %q, want %q", id, evaluate.Env[id], want)
}
}
sort.Strings(wantBazelIDs)
var gotBazelIDs []string
for _, id := range required {
if strings.HasPrefix(id, "BAZEL") {
gotBazelIDs = append(gotBazelIDs, id)
}
}
sort.Strings(gotBazelIDs)
if !reflect.DeepEqual(gotBazelIDs, wantBazelIDs) {
t.Errorf("ci-gate CI_GATE_REQUIRED Bazel ids = %v, want exactly %v", gotBazelIDs, wantBazelIDs)
}
if _, ok := evaluate.Env[bazelAggregateGateID]; ok {
t.Errorf("ci-gate env sets %s; it must come from %s aggregate", bazelAggregateGateID, bazelGateScript)
}
for id, value := range evaluate.Env {
for lane := range bazelAdvisoryLanes {
if strings.Contains(value, "outputs."+lane) {
t.Errorf("ci-gate env %s reads advisory lane %s, which is not in the PR call (%s)", id, lane, bazelAdvisoryLanes[lane])
}
}
}
for key, want := range map[string]string{
"BAZEL_CALL": "${{ needs.bazel.result }}",
"BAZEL_RBE_MODE": "${{ needs.bazel.outputs.rbe-mode }}",
"BAZEL_RBE_ENABLED": "${{ needs.bazel.outputs.rbe-enabled }}",
} {
if evaluate.Env[key] != want {
t.Errorf("ci-gate env %s = %q, want %q", key, evaluate.Env[key], want)
}
}
// The gate reads the call's decision; it never re-derives it.
rederive := regexp.MustCompile(`(?i)RBE_WEST_WORKERS|head\.repo\.fork|HEAD_REPO_FORK|github\.actor|dependabot|secrets\.RBE`)
for key, value := range evaluate.Env {
if rederive.MatchString(key + "=" + value) {
t.Errorf("ci-gate env %s=%q re-derives the Bazel execution mode; read needs.bazel.outputs.rbe-mode", key, value)
}
}
if rederive.MatchString(evaluate.Run) {
t.Errorf("ci-gate run re-derives the Bazel execution mode:\n%s", evaluate.Run)
}
for _, line := range strings.Split(readPolicyFile(t, sourceRepoRoot(t), bazelGateScript), "\n") {
if !strings.HasPrefix(strings.TrimSpace(line), "#") && (rederive.MatchString(line) || strings.Contains(line, "GITHUB_EVENT")) {
t.Errorf("%s re-derives the execution mode: %q", bazelGateScript, line)
}
}
// Legacy jobs stay required: D1 adds, D2 removes.
for id, job := range map[string]string{
"BUILD_ARTIFACTS": "build-artifacts",
"PR_CORE_WRAPPER": "pr-core-wrapper",
"CHECK_CMD_BD_PUREGEO_TESTS": "check-cmd-bd-puregeo-tests",
"TEST_DOMAIN_UOW": "test-domain-uow",
"CONTRACT_CORPUS": "contract-corpus",
} {
if !contains(required, id) || !contains(gate.Needs, job) {
t.Errorf("pr.yml ci-gate no longer requires legacy %s (%s)", job, id)
}
}
risk := readCIWorkflow(t, "pr-risk.yml")
riskGate := risk.job(t, "ci-gate")
riskRequired := strings.Fields(riskGate.step(t, "Evaluate CI gate").Env["CI_GATE_REQUIRED"])
for _, id := range []string{"BUILD_EMBEDDED", "TEST_EMBEDDED_STORAGE", "TEST_EMBEDDED_CONFORMANCE", "TEST_EMBEDDED_CMD"} {
if !contains(riskRequired, id) {
t.Errorf("pr-risk.yml ci-gate no longer requires legacy %s", id)
}
}
// PR Risk does not run the lane a second time.
for jobName, job := range risk.Jobs {
if strings.Contains(job.Uses, "bazel") || contains(job.Needs, "bazel") {
t.Errorf("pr-risk.yml job %s runs or needs the Bazel lane; pr.yml owns it", jobName)
}
}
}
// A called workflow's workflow-level concurrency group is evaluated in the
// caller's context, where github.workflow is the caller's name: a group equal
// to the caller's own deadlocks and GitHub cancels the call (BAZEL cancelled,
// every PR red). So bazel.yml's group never uses github.workflow and, for
// every event its callers run on, differs from each caller's group (review
// D1 v2 N4).
func TestBazelCallConcurrencyDiffersFromCallers(t *testing.T) {
group := func(file string) string {
t.Helper()
var doc struct {
Concurrency struct {
Group string `yaml:"group"`
} `yaml:"concurrency"`
}
if err := yaml.Unmarshal([]byte(readPolicyFile(t, sourceRepoRoot(t), ".github/workflows/"+file)), &doc); err != nil {
t.Fatal(err)
}
return doc.Concurrency.Group
}
bazelGroup := group(bazelWorkflowName)
if bazelGroup == "" || strings.Contains(bazelGroup, "github.workflow") {
t.Fatalf("%s concurrency group = %q; want a fixed prefix, never github.workflow (the caller's name in a call)", bazelWorkflowName, bazelGroup)
}
exprRe := regexp.MustCompile(`\$\{\{\s*(.*?)\s*\}\}`)
eval := func(g, workflowName, event string) string {
t.Helper()
ctx := map[string]string{
"github.workflow": workflowName,
"github.event_name": event,
"github.ref": "refs/pull/123/merge",
"github.event.pull_request.number || github.ref": "123",
}
if event != "pull_request" {
ctx["github.ref"] = "refs/heads/gh-readonly-queue/main/pr-123"
ctx["github.event.pull_request.number || github.ref"] = ctx["github.ref"]
}
return exprRe.ReplaceAllStringFunc(g, func(m string) string {
v, ok := ctx[exprRe.FindStringSubmatch(m)[1]]
if !ok {
t.Fatalf("concurrency group %q: cannot evaluate %s", g, m)
}
return v
})
}
for _, caller := range []string{"pr.yml", "nightly.yml"} {
callerGroup := group(caller)
if callerGroup == "" {
continue // no workflow-level group, nothing to collide with
}
name := yamlScalar(readYAMLNode(t, filepath.Join(".github", "workflows", caller)), "name")
for _, event := range []string{"pull_request", "merge_group", "push", "schedule", "workflow_dispatch"} {
if a, b := eval(bazelGroup, name, event), eval(callerGroup, name, event); a == b {
t.Errorf("%s event %s: %s's concurrency group %q equals the caller's; the call would deadlock", caller, event, bazelWorkflowName, a)
}
}
}
}
// bazelLaneRunModes: the rbe modes in which a lane's `if:` runs it, for a
// call with these inputs. Only the forms TestBazelWorkflowJobsAndExecutionMode
// allows are known. GitHub's != on strings is case-insensitive.
func bazelLaneRunModes(t *testing.T, lane, ifExpr string, with map[string]string) map[string]bool {
t.Helper()
switch ifExpr {
case "${{ needs.rbe.outputs.mode != 'skip' }}":
return map[string]bool{"remote": true, "local": true}
case "${{ needs.rbe.outputs.enabled == 'true' }}":
return map[string]bool{"remote": true}
case bazelIntegIf:
if strings.EqualFold(with["integration"], "off") {
return map[string]bool{}
}
return map[string]bool{"remote": true}
}
t.Fatalf("%s if = %q: teach bazelLaneRunModes which modes run it", lane, ifExpr)
return nil
}
// bazelGateScenario: what pr.yml's ci-gate sees of one bazel.yml call.
type bazelGateScenario struct {
name string
event string
mode, enabled string // the call's rbe-mode / rbe-enabled outputs
call string // needs.bazel.result
outputs map[string]string // the lanes' outputs ("" = not reported)
wantPass bool
wantMention string // a red gate must name this id
}
// runPRGateStep runs pr.yml's actual "Evaluate CI gate" step (its run block,
// under GitHub's bash flags) with its env evaluated for the scenario: every
// non-Bazel need succeeded; Bazel expressions read the scenario. An env
// expression of any other form fails the test, so the simulation cannot
// silently drift from the workflow.
func runPRGateStep(t *testing.T, step ciWorkflowStep, sc bazelGateScenario) (bool, string) {
t.Helper()
expr := regexp.MustCompile(`^\$\{\{ needs\.([A-Za-z0-9_-]+)\.(result|outputs\.([A-Za-z0-9_-]+))( \|\| 'skipped')? \}\}$`)
env := []string{"PATH=" + os.Getenv("PATH"), "GITHUB_EVENT_NAME=" + sc.event}
for key, value := range step.Env {
if !strings.Contains(value, "${{") {
env = append(env, key+"="+value)
continue
}
m := expr.FindStringSubmatch(value)
if m == nil {
t.Fatalf("ci-gate env %s = %q: the gate simulation cannot evaluate it", key, value)
}
var got string
switch {
case m[1] != "bazel" && m[2] == "result":
got = "success"
case m[1] != "bazel":
t.Fatalf("ci-gate env %s = %q: the gate simulation cannot evaluate it", key, value)
case m[2] == "result":
got = sc.call
case m[3] == "rbe-mode":
got = sc.mode
case m[3] == "rbe-enabled":
got = sc.enabled
default:
got = sc.outputs[m[3]]
}
if got == "" && m[4] != "" {
got = "skipped"
}
env = append(env, key+"="+got)
}
cmd := exec.Command("bash", "--noprofile", "--norc", "-eo", "pipefail", "-c", step.Run)
cmd.Dir = sourceRepoRoot(t)
cmd.Env = env
out, err := cmd.CombinedOutput()
return err == nil, string(out)
}
// The gate over every execution mode (review D1 F3): the skip script allows
// exactly the skips the lanes' own `if:`s produce in that mode, and for every
// lane that should run, that lane alone skipped, failed or cancelled turns
// pr.yml's actual gate step red, whatever the aggregate says. The advisory
// integration lane's failure alone keeps it green; a missing or inconsistent
// mode, or an aggregate failure no lane explains, turns it red.
func TestBazelGateSimulation(t *testing.T) {
requireHostTool(t, "bash")
root := sourceRepoRoot(t)
workflow := readCIWorkflow(t, bazelWorkflowName)
pr := readCIWorkflow(t, "pr.yml")
step := pr.job(t, "ci-gate").step(t, "Evaluate CI gate")
callWith := pr.job(t, "bazel").With
lanes := map[string]map[string]bool{} // lane -> modes it runs in, in pr.yml's call
for name, job := range workflow.Jobs {
if name == bazelRBEJobName {
continue
}
lanes[name] = bazelLaneRunModes(t, name, job.If, callWith)
// Advisory lanes are not in the PR call; gated lanes run at least
// when remote.
if _, advisory := bazelAdvisoryLanes[name]; advisory && len(lanes[name]) != 0 {
t.Errorf("advisory lane %s runs in pr.yml's call in modes %v; turn it off there (%s)", name, lanes[name], bazelAdvisoryLanes[name])
}
if _, gated := bazelLaneGateIDs[name]; gated && !lanes[name]["remote"] {
t.Errorf("gated lane %s does not run in pr.yml's call even in remote mode", name)
}
}
enabledFor := func(mode string) string { return strconv.FormatBool(mode == "remote") }
runScript := func(mode, enabled, arg string) string {
t.Helper()
cmd := exec.Command("bash", bazelGateScript, arg)
cmd.Dir = root
cmd.Env = []string{"PATH=" + os.Getenv("PATH"), "BAZEL_RBE_MODE=" + mode, "BAZEL_RBE_ENABLED=" + enabled}
out, err := cmd.Output()
if err != nil {
t.Fatalf("%s %s (mode %q, enabled %q): %v", bazelGateScript, arg, mode, enabled, err)
}
return strings.TrimSpace(string(out))
}
var scenarios []bazelGateScenario
for _, mode := range bazelRBEModes {
// Expected skips, from the jobs' ifs alone.
var wantSkips []string
anyRuns := false
for lane, modes := range lanes {
if modes[mode] {
anyRuns = true
} else if id, gated := bazelLaneGateIDs[lane]; gated {
wantSkips = append(wantSkips, id)
}
}
if !anyRuns {
wantSkips = append(wantSkips, bazelAggregateGateID)
}
sort.Strings(wantSkips)
gotSkips := strings.Fields(runScript(mode, enabledFor(mode), "skips"))
sort.Strings(gotSkips)
if !reflect.DeepEqual(gotSkips, wantSkips) && !(len(gotSkips) == 0 && len(wantSkips) == 0) {
t.Errorf("mode %s: %s skips = %v, want exactly %v (the ids whose job if is false)", mode, bazelGateScript, gotSkips, wantSkips)
}
base := func() map[string]string {
out := map[string]string{}
for lane, modes := range lanes {
if modes[mode] {
out[lane] = "success"
}
}
return out
}
with := func(kv ...string) map[string]string {
out := base()
for i := 0; i+1 < len(kv); i += 2 {
out[kv[i]] = kv[i+1]
}
return out
}
sc := func(name, call string, outputs map[string]string, pass bool, mention string) {
for _, event := range []string{"pull_request", "merge_group"} {
scenarios = append(scenarios, bazelGateScenario{
name: mode + "/" + event + "/" + name, event: event, mode: mode, enabled: enabledFor(mode),
call: call, outputs: outputs, wantPass: pass, wantMention: mention,
})
}
}
sc("every lane as designed", "success", base(), true, "")
sc("aggregate failure no lane explains", "failure", base(), false, bazelAggregateGateID)
sc("aggregate cancelled", "cancelled", base(), false, bazelAggregateGateID)
sc("aggregate skipped", "skipped", base(), mode == "skip", bazelAggregateGateID)
for lane, modes := range lanes {
id, gated := bazelLaneGateIDs[lane]
if !gated {
// Advisory: not in the call, so it cannot report, and
// nothing about it excuses the aggregate.
for _, result := range []string{"failure", "cancelled"} {
sc(lane+" reports "+result+" though off", "failure", with(lane, result), false, bazelAggregateGateID)
}
continue
}
if !modes[mode] {
// Skipped by design (baseline); if it ran anyway and failed,
// the gate still sees it.
sc(lane+" ran and failed", "failure", with(lane, "failure"), false, id)
continue
}
for _, call := range []string{"success", "failure"} {
sc(lane+" alone skipped, aggregate "+call, call, with(lane, ""), false, id)
sc(lane+" failed, aggregate "+call, call, with(lane, "failure"), false, id)
sc(lane+" cancelled, aggregate "+call, call, with(lane, "cancelled"), false, id)
}
sc(lane+" cancelled, aggregate cancelled", "cancelled", with(lane, "cancelled"), false, id)
}
}
// A missing or inconsistent decision (the rbe job failed, the call never
// started, or the outputs disagree) allows no skip and fails the gate.
for _, bad := range []struct{ mode, enabled string }{
{"", ""}, {"remote", "false"}, {"local", "true"}, {"skip", "true"}, {"remote", ""}, {"bogus", "false"}, {"REMOTE", "true"},
} {
if got := runScript(bad.mode, bad.enabled, "skips"); got != "" {
t.Errorf("mode %q enabled %q: skips = %q, want none", bad.mode, bad.enabled, got)
}
all := map[string]string{}
for lane := range lanes {
all[lane] = "success"
}
scenarios = append(scenarios,
bazelGateScenario{name: "invalid " + bad.mode + "/" + bad.enabled + ", every lane success", event: "pull_request",
mode: bad.mode, enabled: bad.enabled, call: "success", outputs: all, wantMention: bazelAggregateGateID},
bazelGateScenario{name: "invalid " + bad.mode + "/" + bad.enabled + ", nothing ran", event: "pull_request",
mode: bad.mode, enabled: bad.enabled, call: "failure", outputs: map[string]string{}, wantMention: bazelAggregateGateID},
)
}
for _, sc := range scenarios {
t.Run(sc.name, func(t *testing.T) {
pass, out := runPRGateStep(t, step, sc)
if pass != sc.wantPass {
t.Errorf("gate pass = %v, want %v (outputs %v, call %s)\n%s", pass, sc.wantPass, sc.outputs, sc.call, out)
}
if !sc.wantPass && sc.wantMention != "" && !regexp.MustCompile(`::error::`+sc.wantMention+`\b`).MatchString(out) {
t.Errorf("red gate does not name %s:\n%s", sc.wantMention, out)
}
})
}
}
// Artifact names are unique within a run, and a called workflow's uploads
// belong to the caller's run: a duplicate name makes the second upload fail
// (409) or a download pick the wrong file. So every run that calls bazel.yml
// (with its own inputs) must not upload any name twice (review D1 F7).
func TestBazelArtifactNamesUniqueInCallerRuns(t *testing.T) {
for _, caller := range []string{"pr.yml", "nightly.yml"} {
t.Run(caller, func(t *testing.T) {
uses := collectRunArtifactUploads(t, caller, nil, "")
var sawBazel bool
for _, u := range uses {
sawBazel = sawBazel || strings.Contains(u.where, "-> "+bazelWorkflowName+" job ")
}
if !sawBazel {
t.Fatalf("%s run has no upload from %s; the collector did not follow the call", caller, bazelWorkflowName)
}
for i, a := range uses {
if a.matrix && a.pattern == nil {
t.Errorf("%s: %s uploads fixed name %q from a matrix job; every leg collides", caller, a.where, a.name)
}
for _, b := range uses[i+1:] {
if bazelArtifactNamesCollide(a, b) {
t.Errorf("%s run: %s and %s both upload %q / %q", caller, a.where, b.where, a.name, b.name)
}
}
}
})
}
}
type runArtifactUpload struct {
name, where string
pattern *regexp.Regexp // nil when the name resolved to a literal
matrix bool
}
func bazelArtifactNamesCollide(a, b runArtifactUpload) bool {
switch {
case a.pattern == nil && b.pattern == nil:
return a.name == b.name
case a.pattern == nil:
return b.pattern.MatchString(a.name)
case b.pattern == nil:
return a.pattern.MatchString(b.name)
}
return a.name == b.name
}
// collectRunArtifactUploads lists the upload-artifact names of one run of
// file: its jobs' steps and, recursively, those of the local workflows its
// jobs call with their `with:` inputs (workflow_call defaults otherwise).
// inputs.X, `inputs.X || 'lit'` and env.X (job, then workflow env) resolve;
// any other expression (a matrix value) becomes a wildcard.
func collectRunArtifactUploads(t *testing.T, file string, with map[string]string, prefix string) []runArtifactUpload {
t.Helper()
path := filepath.Join(sourceRepoRoot(t), ".github", "workflows", file)
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
var doc struct {
On struct {
WorkflowCall struct {
Inputs map[string]struct {
Default any `yaml:"default"`
} `yaml:"inputs"`
} `yaml:"workflow_call"`
} `yaml:"on"`
Env map[string]string `yaml:"env"`
Jobs map[string]struct {
Uses string `yaml:"uses"`
With map[string]any `yaml:"with"`
Env map[string]string `yaml:"env"`
Strategy struct {
Matrix any `yaml:"matrix"`
} `yaml:"strategy"`
Steps []ciWorkflowStep `yaml:"steps"`
} `yaml:"jobs"`
}
if err := yaml.Unmarshal(data, &doc); err != nil {
t.Fatalf("parse %s: %v", path, err)
}
inputs := map[string]string{}
for name, in := range doc.On.WorkflowCall.Inputs {
if in.Default != nil {
inputs[name] = fmt.Sprint(in.Default)
}
}
for k, v := range with {
inputs[k] = v
}
exprRe := regexp.MustCompile(`\$\{\{\s*(.*?)\s*\}\}`)
inputOr := regexp.MustCompile(`^inputs\.([A-Za-z0-9_-]+)(?:\s*\|\|\s*'([^']*)')?$`)
envRef := regexp.MustCompile(`^env\.([A-Za-z0-9_]+)$`)
var out []runArtifactUpload
var names []string
for name := range doc.Jobs {
names = append(names, name)
}
sort.Strings(names)
for _, jobName := range names {
job := doc.Jobs[jobName]
if strings.HasPrefix(job.Uses, "./.github/workflows/") {
callWith := map[string]string{}
for k, v := range job.With {
callWith[k] = fmt.Sprint(v)
}
called := strings.TrimPrefix(job.Uses, "./.github/workflows/")
out = append(out, collectRunArtifactUploads(t, called, callWith, prefix+file+" job "+jobName+" -> ")...)
continue
}
var resolve func(s string, depth int) (string, bool)
resolve = func(s string, depth int) (string, bool) {
literal := true
res := exprRe.ReplaceAllStringFunc(s, func(m string) string {
inner := exprRe.FindStringSubmatch(m)[1]
if in := inputOr.FindStringSubmatch(inner); in != nil {
if v := inputs[in[1]]; v != "" {
return v
}
return in[2]
}
if e := envRef.FindStringSubmatch(inner); e != nil && depth < 4 {
v, ok := job.Env[e[1]]
if !ok {
v, ok = doc.Env[e[1]]
}
if ok {
r, lit := resolve(v, depth+1)
literal = literal && lit
return r
}
}
literal = false
return "\x00"
})
return res, literal
}
for _, step := range job.Steps {
if actionFamily(step.Uses) != "actions/upload-artifact" {
continue
}
name, literal := resolve(step.With["name"], 0)
u := runArtifactUpload{name: name, where: prefix + file + " job " + jobName, matrix: job.Strategy.Matrix != nil}
if !literal {
parts := strings.Split(name, "\x00")
for i := range parts {
parts[i] = regexp.QuoteMeta(parts[i])
}
u.pattern = regexp.MustCompile("^" + strings.Join(parts, ".+") + "$")
u.name = strings.ReplaceAll(name, "\x00", "*")
}
out = append(out, u)
}
}
return out
}
// Every action in the Bazel lane is pinned to a full commit SHA, with the same
@ -1759,8 +2490,13 @@ func TestBazelWorkflowPublishesBuildArtifacts(t *testing.T) {
job := readCIWorkflow(t, bazelWorkflowName).job(t, bazelJobName)
pkg := job.step(t, "Package bd (ci-build-artifacts layout)")
upload := job.step(t, "Upload build artifacts")
if prUpload.With["name"] != "ci-build-artifacts" || upload.With["name"] != prUpload.With["name"] {
t.Errorf("artifact name = %q, want pr.yml's %q (ci-build-artifacts)", upload.With["name"], prUpload.With["name"])
// Named by the build-artifact-name input, pr.yml's name by default; the
// run inside pr.yml renames it (TestBazelLaneIsGatedAlongsideLegacy) so
// the two uploads cannot collide.
if prUpload.With["name"] != "ci-build-artifacts" ||
upload.With["name"] != "${{ inputs.build-artifact-name || '"+prUpload.With["name"]+"' }}" ||
readBazelWorkflowCall(t).Inputs["build-artifact-name"].Default != prUpload.With["name"] {
t.Errorf("artifact name = %q, want the build-artifact-name input defaulting to pr.yml's %q", upload.With["name"], prUpload.With["name"])
}
for _, key := range []string{"retention-days", "if-no-files-found"} {
if upload.With[key] != prUpload.With[key] {
@ -2301,7 +3037,8 @@ func TestBazelDoltServerTiersMirrorPRRisk(t *testing.T) {
}
// Each tier is a remote-only job of its own (the job if is pinned by
// TestBazelWorkflowIsAdvisory via bazelRemoteOnlyJobs): not a step of
// TestBazelWorkflowJobsAndExecutionMode via bazelRemoteOnlyJobs, and
// pr.yml's gate requires it: bazelLaneGateIDs): not a step of
// bazel-doltserver (which also runs locally, and whose job a gate may
// require) or of bazel-integration (which a caller may switch off,
// although the server tier is a PR-time tier).
@ -2315,8 +3052,8 @@ func TestBazelDoltServerTiersMirrorPRRisk(t *testing.T) {
t.Errorf("%s timeout-minutes = %d; it runs remotely only (longest shard ~2-8 min), keep it at most 30", c.job, job.TimeoutMinutes)
}
assertBazelTierStep(t, job, c.job, c.config)
if n := len(job.Steps); n != 5 {
t.Errorf("%s has %d steps, want checkout, setup-bazel, the tier, check_testcases.py, log upload", c.job, n)
if n := len(job.Steps); n != 6 {
t.Errorf("%s has %d steps, want checkout, setup-bazel, the tier, check_testcases.py, log upload, result recorder", c.job, n)
}
logs := job.step(t, "Upload test logs")
if logs.If != "${{ failure() && steps.test.outcome != 'skipped' }}" || logs.With["name"] != c.logs || !strings.HasPrefix(logs.Uses, "actions/upload-artifact@") {
@ -2756,7 +3493,7 @@ func TestBazelWorkflowSecretsAndFailureSurface(t *testing.T) {
secretRef := regexp.MustCompile(`\bsecrets\s*(\.|\[)`)
walkYAML(root, "", func(path string, key bool, value string) {
if key && value == "continue-on-error" {
t.Errorf("%s: %s hides failures; the lane is advisory by staying out of ci-gate", bazelWorkflowName, path)
t.Errorf("%s: %s hides failures from pr.yml's ci-gate", bazelWorkflowName, path)
}
if key && (value == "secrets" && strings.HasPrefix(path, ".jobs.")) {
t.Errorf("%s: %s passes secrets to a called workflow or container", bazelWorkflowName, path)
@ -2832,16 +3569,14 @@ func TestBazelRBEJobDecidesOnce(t *testing.T) {
if err := yaml.Unmarshal([]byte(readPolicyFile(t, sourceRepoRoot(t), ".github/workflows/"+bazelWorkflowName)), &doc); err != nil {
t.Fatal(err)
}
gotCallOutputs := map[string]string{}
for k, v := range doc.On.WorkflowCall.Outputs {
gotCallOutputs[k] = v.Value
}
wantCallOutputs := map[string]string{
// (The lanes' result outputs: TestBazelLaneIsGatedAlongsideLegacy.)
for name, want := range map[string]string{
"rbe-enabled": "${{ jobs.rbe.outputs.enabled }}",
"rbe-mode": "${{ jobs.rbe.outputs.mode }}",
}
if !reflect.DeepEqual(gotCallOutputs, wantCallOutputs) {
t.Errorf("workflow_call outputs = %v, want %v", gotCallOutputs, wantCallOutputs)
} {
if got := doc.On.WorkflowCall.Outputs[name].Value; got != want {
t.Errorf("workflow_call output %s = %q, want %q", name, got, want)
}
}
// Nothing outside the decision step re-derives the condition.
@ -3107,13 +3842,18 @@ func TestBazelAutofixWorkflowSecurity(t *testing.T) {
if err := root.Decode(&doc); err != nil {
t.Fatal(err)
}
// Only "Bazel" (bazel.yml on pull_request) uploads bazel-sync-patch. Any
// other trigger would only ever be a no-op run (and, with a shared
// concurrency group, could get in a real fix's way).
if want := []string{"Bazel"}; !reflect.DeepEqual(doc.On.WorkflowRun.Workflows, want) {
// Only "PR" (pr.yml, whose bazel job calls bazel.yml) uploads
// bazel-sync-patch in a pull_request run: bazel.yml has no pull_request
// trigger of its own, so a "Bazel" run is never a PR event. Any other
// trigger would only ever be a no-op run (and, with a shared concurrency
// group, could get in a real fix's way).
if want := []string{"PR"}; !reflect.DeepEqual(doc.On.WorkflowRun.Workflows, want) {
t.Errorf("workflow_run.workflows = %v, want %v", doc.On.WorkflowRun.Workflows, want)
}
requireWorkflowProducesArtifact(t, bazelWorkflowName, "Bazel", "bazel-sync-patch")
requireWorkflowProducesArtifact(t, "pr.yml", "PR", "bazel-sync-patch")
if slices.Contains(yamlMapKeys(readYAMLNode(t, filepath.Join(".github", "workflows", bazelWorkflowName)), "on"), "pull_request") {
t.Errorf("%s has its own pull_request trigger; its PR runs would upload bazel-sync-patch outside the \"PR\" run this workflow watches", bazelWorkflowName)
}
if !reflect.DeepEqual(doc.On.WorkflowRun.Types, []string{"completed"}) {
t.Errorf("workflow_run.types = %v, want [completed]", doc.On.WorkflowRun.Types)
}
@ -3210,7 +3950,10 @@ func TestBazelAutofixWorkflowSecurity(t *testing.T) {
}
// requireWorkflowProducesArtifact: the workflow a workflow_run trigger names
// runs on pull_request and uploads the artifact the autofix job consumes.
// runs on pull_request and uploads the artifact the autofix job consumes,
// from one of its own jobs or from a local workflow a job calls
// unconditionally (a called workflow's uploads belong to the caller's run,
// under the caller's run id).
func requireWorkflowProducesArtifact(t *testing.T, file, name, artifact string) {
t.Helper()
node := readYAMLNode(t, filepath.Join(".github", "workflows", file))
@ -3220,16 +3963,24 @@ func requireWorkflowProducesArtifact(t *testing.T, file, name, artifact string)
if !slices.Contains(yamlMapKeys(node, "on"), "pull_request") {
t.Errorf("%s has no pull_request trigger; the autofix job only acts on PR runs", file)
}
var uploads bool
for _, job := range readCIWorkflow(t, file).Jobs {
for _, step := range job.Steps {
if strings.HasPrefix(step.Uses, "actions/upload-artifact@") && step.With["name"] == artifact {
uploads = true
uploads := func(wf ciWorkflow) bool {
for _, job := range wf.Jobs {
for _, step := range job.Steps {
if strings.HasPrefix(step.Uses, "actions/upload-artifact@") && step.With["name"] == artifact {
return true
}
}
}
return false
}
if !uploads {
t.Errorf("%s never uploads %s; the workflow_run trigger on it would be dead", file, artifact)
found := uploads(readCIWorkflow(t, file))
for _, job := range readCIWorkflow(t, file).Jobs {
if called, ok := strings.CutPrefix(job.Uses, "./.github/workflows/"); ok && job.If == "" && uploads(readCIWorkflow(t, called)) {
found = true
}
}
if !found {
t.Errorf("%s never uploads %s (itself or through a called workflow); the workflow_run trigger on it would be dead", file, artifact)
}
}