Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions .github/workflows/bazel-compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
name: Bazel patch compatibility (legs)

# socket-patch in a Bazel workspace, on a real Bazel: the legs of one
# ecosystem. One leg per Bazel release runs the `#[ignore]` tests of the
# ecosystem's module of `e2e_bazel_build` (`go::`) on the release it
# installed. A test builds a fixture workspace, runs the built binary in it
# and reads the result from what Bazel builds next; the test code says which
# fixture files go with which release.
#
# This is a reusable workflow, and nothing starts it but a caller. Each
# ecosystem has one (bazel-go.yml), which says when its legs run (its
# triggers and path lists, its concurrency group) and on which Bazel
# releases (the inputs below). Another ecosystem is one more caller, and no
# change here or in another ecosystem's caller. A called workflow runs with
# the event, the ref and the token of its caller: every `github.*` below is
# the caller's, the token is the `contents: read` the caller grants, and the
# file is the one of the caller's commit, so a pull request that changes it
# runs its own version.
#
# The package under test and every Socket host are loopback stand-ins. A leg
# still needs the network for the ruleset and the toolchain: github.com and
# release-assets.githubusercontent.com (the Bazel release, cached per
# release, and the ruleset archives), bcr.bazel.build (the registry) on
# every run, and the hosts of the ecosystem's toolchain, which its caller
# names. A repository cache saved from main holds the archives and the
# toolchain.
#
# Not required for merge: no caller has a `merge_group` trigger, and no job
# here is a `needs` of ci.yml's `ci-ok`. Setting the repository variable
# BAZEL_COMPAT_DISABLED to `true` turns every leg of every ecosystem off
# without a merge.
#
# To add a Bazel release: one line per platform in scripts/bazel-pins.txt
# and one line of `releases` in each caller that runs it.
#
# No job has a `name:`. GitHub does not expand a matrix expression in the
# name of a job that its `if` skips, so such a name shows up as its source
# text in a pull request's checks. The default title of a leg is the
# caller's job, the job's id here and its matrix values:
# `go / bazel (9.3.2, e9)`.

on:
workflow_call:
inputs:
eco:
description: >-
The ecosystem's module of the `e2e_bazel_build` test target
(`go`). A leg runs the `#[ignore]` tests of that module.
required: true
type: string
fixtures:
description: >-
The ecosystem's fixture, a directory under
crates/socket-patch-cli/tests/fixtures/bazel (`gazelle/bzlmod`).
required: true
type: string
releases:
description: >-
The Linux legs, as a JSON list with one
{"bazel": "<release>", "era": "<directory>"} per leg: a Bazel
release that scripts/bazel-pins.txt pins, and the directory of the
fixture that holds the `MODULE.bazel` this release builds. The
test code decides the era of a release, and the hermetic test of
the ecosystem's module fails when a leg names another.
required: true
type: string
macos:
description: >-
The macOS legs, in the same form. They run nightly and on demand
only.
required: true
type: string

permissions:
contents: read

env:
SOCKET_NO_CONFIG: '1'
SOCKET_NO_UPDATE_CHECK: '1'
SOCKET_TELEMETRY_DISABLED: '1'

jobs:
bazel:
if: github.event.pull_request.draft != true && vars.BAZEL_COMPAT_DISABLED != 'true'
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(inputs.releases) }}
runs-on: ${{ vars.DISABLE_DEPOT_RUNNERS == 'true' && 'ubuntu-latest' || 'depot-ubuntu-24.04-4' }}
timeout-minutes: 45
steps: &bazel-steps
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false

- name: Shellcheck the Bazel installer
# shellcheck is pre-installed on the Linux runners only.
if: runner.os == 'Linux'
run: shellcheck scripts/install-bazel.sh

- run: rustup show

- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
with:
# The key the other workflows give the runner image of this job.
shared-key: dev-${{ runner.os == 'macOS' && 'macos-latest' || 'ubuntu-latest' }}
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Restore the Bazel ${{ matrix.bazel }} binary
# The installer checks a restored file against its pin too, so a
# miss or a stale entry only means a download. Saved from main, and
# shared by every ecosystem that runs the release.
id: bazel-dist
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
timeout-minutes: 5
continue-on-error: true
with:
path: ${{ runner.temp }}/bazel-dist
key: bazel-dist-${{ matrix.bazel }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/bazel-pins.txt', 'scripts/install-bazel.sh') }}

- name: Install Bazel ${{ matrix.bazel }}
env:
BAZEL_VERSION: ${{ matrix.bazel }}
# Prints one line, SOCKET_PATCH_BAZEL_E2E_BAZEL=<the pinned and
# verified binary>. A line of $GITHUB_ENV is a name, `=` and the
# value up to the end of the line, so a space in the path is kept.
run: scripts/install-bazel.sh "$BAZEL_VERSION" "$RUNNER_TEMP/bazel-dist" >> "$GITHUB_ENV"

- name: Save the Bazel ${{ matrix.bazel }} binary
if: >-
github.ref == 'refs/heads/main'
&& steps.bazel-dist.outputs.cache-hit != 'true'
&& steps.bazel-dist.outcome == 'success'
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: ${{ runner.temp }}/bazel-dist
key: ${{ steps.bazel-dist.outputs.cache-primary-key }}

- name: Restore the repository cache
# What Bazel downloads for the fixture: the ruleset archives and the
# language toolchain. One cache per ecosystem and fixture era, keyed
# by the files that pin all of it: `common` and the era's
# directory. The legs of one era share it, whatever their Bazel
# release, and another era or another ecosystem never makes a leg
# save a new copy. A run whose fixture changed starts from the
# newest cache of its era. The cache is content-addressed, so an
# older one, or one that another release of the era saved, is still
# correct, only incomplete: a leg downloads what it lacks, which for
# a second release of an era is what that Bazel resolves for its own
# built-in modules. Whether the package under test can come from it
# is the ecosystem's matter, and its test says how it rules that out.
id: bazel-repos
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
timeout-minutes: 5
continue-on-error: true
with:
path: ${{ runner.temp }}/bazel-repos
key: bazel-repos-${{ inputs.eco }}-${{ matrix.era }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles(format('crates/socket-patch-cli/tests/fixtures/bazel/{0}/common/**', inputs.fixtures), format('crates/socket-patch-cli/tests/fixtures/bazel/{0}/{1}/**', inputs.fixtures, matrix.era)) }}
restore-keys: |
bazel-repos-${{ inputs.eco }}-${{ matrix.era }}-${{ runner.os }}-${{ runner.arch }}-

- name: Run the ${{ inputs.eco }} tests on Bazel ${{ matrix.bazel }}
env:
# A missing Bazel fails the leg instead of printing SKIP, and so
# does a Bazel that is not the release of this leg.
SOCKET_PATCH_BAZEL_E2E_REQUIRED: '1'
SOCKET_PATCH_BAZEL_E2E_VERSION: ${{ matrix.bazel }}
SOCKET_PATCH_BAZEL_E2E_REPO_CACHE: ${{ runner.temp }}/bazel-repos
ECO: ${{ inputs.eco }}
# The ecosystem's module holds one `#[ignore]` test per flow, and a
# test takes its release from the Bazel installed above, so the
# filter is the module's name and nothing is derived from the
# release. The tests are chosen by the module's name as a prefix and
# run by their exact names: a test filter is a substring, and `go::`
# is also inside `cargo::`. The step fails when the module has no
# test: a name that matches nothing would run no test and pass. Two
# tests at a time: each runs a Bazel server of its own.
run: |
names=$(cargo test --locked -p socket-patch-cli --test e2e_bazel_build -- \
--ignored --list | sed -n "s/^\(${ECO}::.*\): test\$/\1/p")
test -n "$names"
echo "$names"
# shellcheck disable=SC2086 # one test name per word
cargo test --locked -p socket-patch-cli --test e2e_bazel_build -- \
--ignored --exact $names --test-threads=2 --nocapture

- name: Save the repository cache
# The first leg of an era to finish on main saves it. Another leg
# of the era that also missed finds the key taken, which the action
# logs without failing the step.
if: >-
github.ref == 'refs/heads/main'
&& steps.bazel-repos.outputs.cache-hit != 'true'
&& steps.bazel-repos.outcome == 'success'
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: ${{ runner.temp }}/bazel-repos
key: ${{ steps.bazel-repos.outputs.cache-primary-key }}

# The macOS legs: nightly and on demand, never on a pull request or a
# push, so they do not queue on the small macOS runner pool.
bazel-macos:
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && vars.BAZEL_COMPAT_DISABLED != 'true'
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(inputs.macos) }}
runs-on: macos-latest
timeout-minutes: 45
steps: *bazel-steps
107 changes: 107 additions & 0 deletions .github/workflows/bazel-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Bazel patch compatibility (Go)

# The Go flow of the real-Bazel tests (`go::` in `e2e_bazel_build`): hosted
# mode for a module that gazelle's `go_deps` resolves from `go.mod`, on
# each Bazel release below. bazel-compatibility.yml holds the legs and what
# every ecosystem shares; this file says when the Go legs run and on which
# releases.
#
# Beyond what every leg needs, a Go leg downloads the Go SDK from
# dl.google.com (about 100 MB, held by its repository cache) and asks go.dev
# for the Go release list on every run. A Go module under test never comes
# from the repository cache: `go` fetches a module into the output base,
# which every test makes anew.
#
# Not required for merge: no `merge_group` trigger, and no job here is a
# `needs` of ci.yml's `ci-ok`.

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
# What a pull request run covers: the Go flow and its fixture, the
# harness and the workflows that run it, the Bazel installer and its
# pins, and the Go files the flow runs through, as go-compatibility.yml
# lists them. Nothing another ecosystem's flow owns is here, so a change
# to one ecosystem starts that ecosystem's legs only.
#
# What it does not cover: shared engine code (patch/redirect/mod.rs,
# hosted/, commands/), the shared test helpers and the toolchain files.
# A change there gets its run on the push to main (when the file is in
# the list below) or in the nightly run, not on the pull request: that
# is the price of not running every ecosystem's legs on every shared
# change. On demand, workflow_dispatch runs the legs on any branch.
paths:
- '.github/workflows/bazel-go.yml'
- '.github/workflows/bazel-compatibility.yml'
- 'scripts/install-bazel.sh'
- 'scripts/bazel-pins.txt'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/go.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs'
- 'crates/socket-patch-cli/tests/fixtures/bazel/gazelle/**'
- 'crates/*/src/**/*golang*'
- 'crates/*/src/**/*golang*/**'
- 'crates/socket-patch-core/src/vendor/go*.rs'
push:
branches: [main]
# The pull request paths, and what only a push to main covers: the
# root of the test target (it changes when an ecosystem's module is
# added; ci.yml builds the target and runs its hermetic tests on every
# pull request), the shared engine code and test helpers the flow runs
# through, and the toolchain files. A main push outside this list waits
# for the nightly run below.
paths:
- '.github/workflows/bazel-go.yml'
- '.github/workflows/bazel-compatibility.yml'
- 'scripts/install-bazel.sh'
- 'scripts/bazel-pins.txt'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/go.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs'
- 'crates/socket-patch-cli/tests/fixtures/bazel/gazelle/**'
- 'crates/*/src/**/*golang*'
- 'crates/*/src/**/*golang*/**'
- 'crates/socket-patch-core/src/vendor/go*.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
- 'crates/socket-patch-core/src/hosted/**'
- 'crates/socket-patch-cli/src/commands/**'
- 'crates/socket-patch-cli/tests/common/**'
- 'crates/socket-patch-cli/tests/hosted_memory_common/**'
- 'Cargo.lock'
- 'Cargo.toml'
- 'crates/*/Cargo.toml'
- 'rust-toolchain.toml'
- '.cargo/**'
schedule:
# Nightly, so a main change outside the push list still gets a run
# within a day. The macOS leg runs here and on demand only.
- cron: '17 4 * * *'
workflow_dispatch:

permissions:
contents: read

# The nightly run has a group of its own. A group holds one pending run, so
# in the group of main's pushes a second push would replace a nightly that
# waits behind the first, and the nightly is the only run with the macOS leg.
concurrency:
group: bazel-go-${{ github.event.pull_request.number || github.ref }}${{ github.event_name == 'schedule' && '-nightly' || '' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
go:
uses: ./.github/workflows/bazel-compatibility.yml
with:
eco: go
fixtures: gazelle/bzlmod
# One leg per line: a Bazel release, and the era of the fixture that
# `go::FIXTURE` gives it.
releases: >-
[
{"bazel": "9.3.2", "era": "e9"},
{"bazel": "8.8.2", "era": "e9"},
{"bazel": "7.7.2", "era": "e7"}
]
macos: >-
[
{"bazel": "9.3.2", "era": "e9"}
]
Loading
Loading