Repository navigation
432 lines (390 loc) · 19.5 KB
/
Copy pathci.yml
File metadata and controls
432 lines (390 loc) · 19.5 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
name: CI
on:
pull_request:
branches: [main]
# Merges build the caches every pull request restores: GitHub lets a PR read
# its own ref and its base branch, never another PR. Without this each PR's
# first run compiled every dependency from scratch.
push:
branches: [main]
paths:
- .cargo/**
- .github/workflows/ci.yml
- Cargo.lock
- Cargo.toml
- rust-toolchain*
- rustcode/**
- "!rustcode/**/*.md"
- harness/**
- "!harness/**/*.md"
workflow_dispatch:
concurrency:
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# A run on main has to finish to save its cache, so merges queue instead of
# cancelling each other. GitHub keeps only the newest one waiting.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
CARGO_TERM_COLOR: always
# CI does not archive debug symbols. Avoid spending time generating and
# linking them for ephemeral checks and test binaries.
CARGO_PROFILE_DEV_DEBUG: "0"
CARGO_PROFILE_TEST_DEBUG: "0"
# No sccache: it stores each object through the Actions cache API, which
# throttled about 80% of its writes and then rust-cache's own save.
permissions:
contents: read
jobs:
changes:
name: detect relevant changes
runs-on: ubuntu-24.04
permissions:
# The changed paths come from the pull request's file list, so no
# clone of the repository or its history is needed to diff it.
contents: read
pull-requests: read
outputs:
code: ${{ steps.filter.outputs.code }}
packages: ${{ steps.filter.outputs.packages }}
release: ${{ steps.filter.outputs.release }}
scripts: ${{ steps.filter.outputs.scripts }}
seatbelt: ${{ steps.filter.outputs.seatbelt }}
steps:
- name: Check out the change matchers
if: github.event_name == 'pull_request'
uses: actions/checkout@v7
with:
# The matchers under scripts/ are what runs next, and nothing
# else is needed: one commit of that directory instead of the
# whole history. Their self-tests run in the lint job. A
# release PR repeats this below with the full history.
fetch-depth: 1
sparse-checkout: scripts
- name: List the changed files
id: files
if: github.event_name == 'pull_request'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
changed_files="$RUNNER_TEMP/changed-files"
gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files \
--paginate --jq '.[].filename' > "$changed_files"
# The files API stops at 3000 entries, so a list that long is
# not the whole change: run everything rather than guess.
if [[ "$(wc -l < "$changed_files")" -ge 3000 ]]; then
echo "The file list is truncated; treating every check as relevant"
echo "truncated=true" >> "$GITHUB_OUTPUT"
echo "release_metadata=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "truncated=false" >> "$GITHUB_OUTPUT"
# A release PR touches only version literals and the changelog.
# The paths are all this step can see, so the prefilter only
# rules a PR out; the filter step rechecks the diff against
# scripts/ci-version-only.sh under the full checkout below.
if [[ -s "$changed_files" ]] &&
bash scripts/ci-version-only.sh --prefilter < "$changed_files"; then
echo "release_metadata=true" >> "$GITHUB_OUTPUT"
else
echo "release_metadata=false" >> "$GITHUB_OUTPUT"
fi
- name: Check out the release metadata diff
# The full history to diff the version literals against, and the
# matcher to read it: the diff needs objects, not a worktree.
if: github.event_name == 'pull_request' && steps.files.outputs.release_metadata == 'true'
uses: actions/checkout@v7
with:
fetch-depth: 0
sparse-checkout: scripts
- name: Check out repository
if: github.event_name != 'pull_request'
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Check changed paths
id: filter
shell: bash
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
RELEASE_METADATA: ${{ steps.files.outputs.release_metadata }}
TRUNCATED: ${{ steps.files.outputs.truncated }}
run: |
if [[ "$GITHUB_EVENT_NAME" != "pull_request" ]]; then
echo "code=true" >> "$GITHUB_OUTPUT"
echo "packages=--workspace" >> "$GITHUB_OUTPUT"
echo "scripts=true" >> "$GITHUB_OUTPUT"
echo "seatbelt=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "$TRUNCATED" == "true" ]]; then
echo "code=true" >> "$GITHUB_OUTPUT"
echo "packages=--workspace" >> "$GITHUB_OUTPUT"
echo "scripts=true" >> "$GITHUB_OUTPUT"
echo "seatbelt=true" >> "$GITHUB_OUTPUT"
exit 0
fi
changed_files="$(< "$RUNNER_TEMP/changed-files")"
if [[ "$RELEASE_METADATA" == "true" ]] && bash scripts/ci-version-only.sh "$BASE_SHA"; then
packages=""
echo "release=true" >> "$GITHUB_OUTPUT"
echo "Release metadata only; reusing checks from the code PR"
else
packages="$(bash scripts/ci-affected-packages.sh <<< "$changed_files")"
fi
echo "packages=$packages" >> "$GITHUB_OUTPUT"
if [[ -n "$packages" ]] && grep -Eq '^(Cargo\.(toml|lock)$|rust-toolchain|\.cargo/|rustcode/engine/|rustcode/core/(rustcode-tools|rustcode-tool-protocol)/|src/|tests/)' <<< "$changed_files"; then
echo "seatbelt=true" >> "$GITHUB_OUTPUT"
else
echo "seatbelt=false" >> "$GITHUB_OUTPUT"
fi
if grep -Eq '^scripts/' <<< "$changed_files"; then
echo "scripts=true" >> "$GITHUB_OUTPUT"
else
echo "scripts=false" >> "$GITHUB_OUTPUT"
fi
if bash scripts/ci-relevant-changes.sh <<< "$changed_files"; then
echo "Relevant code or build files changed"
echo "code=true" >> "$GITHUB_OUTPUT"
else
echo "No relevant code or build files changed"
echo "code=false" >> "$GITHUB_OUTPUT"
fi
test:
# Keep this context name stable: branch protection requires nothing on
# main, so scripts/pr-merge.sh waits for every non-advisory check by
# name, this one included.
needs: changes
name: test
runs-on: ubuntu-24.04
# Healthy runs finish in ~6min. A hung runner or wedged test must
# fail fast instead of burning the 6h default (seen 20min+ stuck).
timeout-minutes: 20
env:
AFFECTED_PACKAGES: ${{ needs.changes.outputs.packages }}
steps:
- name: Check out repository
uses: actions/checkout@v7
# A release PR (version literals, lockfiles and the changelog only,
# scripts/ci-version-only.sh) reuses the suite that ran on its
# code PRs and on main. It runs this instead, in seconds, so the
# job still reports: the full suite took ~6 of the release PR's
# 6.6 min.
- name: Check release version consistency
if: needs.changes.outputs.release == 'true'
run: bash scripts/ci-version-consistency.sh
- name: Install Rust toolchain
if: env.AFFECTED_PACKAGES != ''
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache
if: env.AFFECTED_PACKAGES != ''
uses: Swatinem/rust-cache@v2
with:
# Its own key: clippy's check-only artifacts are no use to
# `cargo test`, and with one shared key lint finished first
# and test could not save.
shared-key: linux
env-vars: "CARGO CC CFLAGS CXX CMAKE RUSTC RUSTDOC RUSTUP"
save-if: ${{ github.ref == 'refs/heads/main' }}
# A failing test says nothing about the compiled dependencies.
cache-on-failure: true
- name: Install bubblewrap
if: env.AFFECTED_PACKAGES != ''
# Four sandbox tests need bubblewrap. When Ubuntu's mirrors cannot
# be reached, the test step skips those four and says so.
run: |
if ! { sudo apt-get update && sudo apt-get install --no-install-recommends -y bubblewrap; }; then
echo "::warning::bubblewrap could not be installed (Ubuntu mirror unreachable); the tests that need it are skipped"
echo "NO_BWRAP=1" >> "$GITHUB_ENV"
fi
- name: Run tests
if: env.AFFECTED_PACKAGES != ''
# These tests depend on user-installed skills or runner-specific
# ripgrep output. Keep them in the local suite, but exclude them
# from the clean-runner gate until they have portable fixtures.
# Include consumers of changed libraries. Shared core changes and
# workspace build inputs select the full suite.
# Sandbox-gated tests skip themselves when bubblewrap cannot run
# (GitHub runners block unprivileged user namespaces).
shell: bash
run: |
read -ra packages <<< "$AFFECTED_PACKAGES"
bwrap_skips=()
if [[ -n "${NO_BWRAP:-}" ]]; then
bwrap_skips=(
--skip tools::exec::sandbox::tests::missing_unused_session_scratch_root_is_omitted
--skip tools::exec::sandbox::tests::working_directory_outside_writable_roots_fails_closed
--skip tools::exec::sandbox::tests::working_directory_symlink_cannot_escape_workspace
--skip tools::exec::tests::restricted_failures_name_the_sandbox_and_trusted_failures_do_not
)
fi
cargo test --locked "${packages[@]}" -- "${bwrap_skips[@]}" \
--skip control_plane_tool_does_not_stall_while_reading_workspace_root \
--skip grep_stops_at_byte_cap_for_large_matching_lines
lint:
# Keep linting separate from the test job so the expensive compiler
# work runs in parallel. Branch protection requires nothing on main;
# scripts/pr-merge.sh waits for every non-advisory check, this one and
# `test` included, before merging.
needs: changes
name: lint
runs-on: ubuntu-24.04
env:
AFFECTED_PACKAGES: ${{ needs.changes.outputs.packages }}
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Check no new code comments
# Ratchet over Rust and TypeScript (docs/adr/0001-comment-ratchet.md):
# a file may not gain comment lines, and the baseline shrinks.
run: |
python3 scripts/check-comments.py --self-test
python3 scripts/check-comments.py
- name: Check no Rust file grows past its size cap
# scripts/check-rust-size.py: no new file past 2,000 lines, and
# the files already past it may only shrink.
run: python3 scripts/check-rust-size.py
- name: Install Rust toolchain
if: env.AFFECTED_PACKAGES != ''
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Rust Cache
if: env.AFFECTED_PACKAGES != ''
uses: Swatinem/rust-cache@v2
with:
shared-key: linux-lint
env-vars: "CARGO CC CFLAGS CXX CMAKE RUSTC RUSTDOC RUSTUP"
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Check formatting
if: env.AFFECTED_PACKAGES != ''
run: cargo fmt --all -- --check
# The installer and the change matchers under scripts/ test
# themselves. Only a change to them can break those tests, and any
# scripts/ change sets `scripts`, so they run on the PR that
# changes them.
- name: Check shell installer syntax
if: needs.changes.outputs.scripts == 'true'
run: bash -n scripts/install.sh
- name: Check Linux installer with isolated release assets
if: needs.changes.outputs.scripts == 'true'
run: python3 scripts/test-install-linux.py
- name: Check CI change matcher
if: needs.changes.outputs.scripts == 'true'
run: bash scripts/test-ci-relevant-changes.sh
- name: Check affected package matcher
if: needs.changes.outputs.scripts == 'true'
run: bash scripts/test-ci-affected-packages.sh
- name: Check version-only matcher
if: needs.changes.outputs.scripts == 'true'
run: bash scripts/test-ci-version-only.sh
- name: Clippy correctness gate
if: env.AFFECTED_PACKAGES != ''
# The codebase has an established clippy warning baseline. Keep
# those visible locally while denying correctness lints and dead
# code: platform- and test-only items are gated with `cfg`, so a
# dead-code warning on Linux is real (#3950).
shell: bash
run: |
read -ra packages <<< "$AFFECTED_PACKAGES"
cargo clippy --locked "${packages[@]}" -- -A warnings -D clippy::correctness -D dead_code
- name: Check the TUI stays behind the frontend seam
if: needs.changes.outputs.code == 'true'
# The render layer may only reach core through
# rustcode::controller, plus the convergence allow-list in
# scripts/frontend-seam-allowlist.txt (issue #1431).
run: bash scripts/check-frontend-seam.sh
- name: Test the frontend-seam guard
if: needs.changes.outputs.code == 'true'
run: bash scripts/test-check-frontend-seam.sh
macos-seatbelt:
needs: changes
if: needs.changes.outputs.seatbelt == 'true'
name: macOS Seatbelt
runs-on: macos-15
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: macos-seatbelt
env-vars: "CARGO CC CFLAGS CXX CMAKE RUSTC RUSTDOC RUSTUP"
save-if: ${{ github.ref == 'refs/heads/main' }}
cache-on-failure: true
# `cargo test` compiles what it runs; a separate `cargo check --tests`
# first compiled the crate a second time (~5 of this job's 10 min).
# The Linux `test` job compiles every test target.
- name: Test Seatbelt enforcement
run: cargo test --locked --lib tools::exec::sandbox::tests -- --test-threads=1
portability:
name: ${{ matrix.name }} portability coverage
needs: changes
if: needs.changes.outputs.packages != ''
# Linux is the required quality gate. Native platform checks remain
# visible and actionable without delaying or blocking a merge.
continue-on-error: true
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: macOS
os: macos-latest
cache_key: macos
- name: Windows
os: windows-latest
cache_key: windows
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Check PowerShell installer syntax
if: runner.os == 'Windows'
shell: pwsh
run: |
$tokens = $null
$errors = $null
$path = Join-Path $PWD "scripts/install.ps1"
$null = [System.Management.Automation.Language.Parser]::ParseFile(
$path,
[ref]$tokens,
[ref]$errors
)
if ($errors.Count -gt 0) {
$errors | ForEach-Object { Write-Error $_.Message }
exit 1
}
Write-Output "PowerShell syntax OK"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.cache_key }}
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Check platform compilation
# Linux runs the behavioral suite. These advisory jobs verify the
# shipped binary's native macOS/Windows cfg without compiling or
# linking the test harness again.
shell: bash
env:
AFFECTED_PACKAGES: ${{ needs.changes.outputs.packages }}
run: |
read -ra packages <<< "$AFFECTED_PACKAGES"
cargo check --locked "${packages[@]}"
- name: Test the fresh-profile migration checkpoint
# The step above only compiles, and migrating user data depends
# on the native file semantics: a flush through a reopened
# read-only handle failed on Windows with "Access is denied",
# which left a fresh profile unmigrated (#3118). One test target
# runs that case for real, and it links only the library because
# the library's own test modules hold unix-only assertions.
if: runner.os == 'Windows'
run: cargo test --locked --test storage_migrations_fresh_profile
- name: Test Windows private file permissions
if: runner.os == 'Windows'
run: cargo test --locked --test private_files_windows
- name: Test Windows scheduler daemon
if: runner.os == 'Windows'
run: cargo test --locked --test daemon_windows