Repository navigation
212 lines (197 loc) · 10 KB
/
Copy pathbazel-compatibility.yml
File metadata and controls
212 lines (197 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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:
# A caller without a macOS leg passes `[]`: GitHub fails a job whose
# matrix is empty, so the job is skipped then.
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && fromJSON(inputs.macos)[0] != null && vars.BAZEL_COMPAT_DISABLED != 'true'
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(inputs.macos) }}
runs-on: macos-latest
timeout-minutes: 45
steps: *bazel-steps