Repository navigation
678 lines (663 loc) · 28.4 KB
/
Copy pathtesting.yaml
File metadata and controls
678 lines (663 loc) · 28.4 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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
---
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2026 The Linux Foundation
name: 'Testing 🧪'
# yamllint disable-line rule:truthy
on:
pull_request:
workflow_dispatch:
inputs:
issues:
description: 'Issues for the manual dry-run (no run scans for issues)'
type: string
default: ''
max_pull_requests:
description: 'Pull requests to attempt in the manual dry-run'
type: string
default: '1'
allow_workflow_edits:
description: 'Let the manual dry-run propose workflow file changes'
type: boolean
default: false
allow_precommit_config_edits:
description: 'Let the manual dry-run change .pre-commit-config.yaml'
type: boolean
default: false
permissions: {}
# A newer push cancels its pull request's stale run. Each manual
# dispatch takes a group of its own, so it neither cancels nor is
# cancelled by pull request runs or another dispatch on the same ref.
concurrency:
group: >-
${{ format('testing-{0}', github.event_name == 'pull_request'
&& github.ref || github.run_id) }}
cancel-in-progress: true
jobs:
# Exercises the select job and the matrix plumbing without an App,
# a model token or an agent session. Two invocations prove that the
# invocation namespace keeps artifact names apart in one run. No run
# scans for issues, so each names an issue of this public
# repository; selected or skipped by name (closed, absent or a pull
# request), it runs every select step.
plumbing:
name: 'Plumbing (secretless, ${{ matrix.invocation }})'
strategy:
matrix:
invocation: [first, second]
if: github.event_name == 'pull_request'
permissions:
issues: read # Named issue reads
contents: read # Asset checkout and public repository reads
actions: read # Report job artifact lookup
checks: read # Select reads other runs' evidence vouches
uses: $/.github/workflows/code-monkey.yaml
with:
org: "${{ github.repository_owner }}"
mode: 'select'
dry_run: true
max_pull_requests: '3'
allow_workflow_edits: false
allow_precommit_config_edits: false
issues: "${{ format('{0}#1', github.repository) }}"
# A login no issue carries: the named issue is skipped by the
# listed-author rule, and every select step still runs.
issue_authors: "${{ github.repository_owner }}"
# Whatever the repository variable says, plumbing keeps the rule on.
# yamllint disable-line rule:line-length
only_known_authors: "${{ 'true' }}" # zizmor: ignore[obfuscation] actionlint types a bare 'true' as a boolean
# Block mode with the organisation allow-list, as the dispatch
# caller runs, so a pull request proves the trusted jobs' egress.
harden_runner_egress: 'block'
# yamllint disable-line rule:line-length
harden_runner_allowlist: '@6e6cab073a93c0d58e4e8846d44e1cbddbac975b' # v0.21.0
# The merge commit, which the local uses: above reads the
# workflow from. The pull request head would pair this workflow
# with scripts from another commit, and fail whenever main has
# changed the interface between them since the branch was cut.
assets_repository: "${{ github.repository }}"
assets_ref: "${{ github.sha }}"
# A full dry-run: the agent works the selected issues and the
# publisher verifies the result without writing anything.
dry-run:
name: 'Agent dry-run (manual)'
if: github.event_name == 'workflow_dispatch'
permissions:
issues: read # Named issue reads
contents: read # Asset checkout and public repository reads
actions: read # Publish and report jobs locate artifacts
checks: read # Select reads other runs' evidence vouches
uses: $/.github/workflows/code-monkey.yaml
with:
org: "${{ github.repository_owner }}"
mode: 'pull-requests'
dry_run: true
model: 'claude-sonnet-5.5'
max_pull_requests: "${{ inputs.max_pull_requests || '1' }}"
max_runtime_minutes: '60'
max_concurrent_agents: '2'
issues: "${{ inputs.issues || '' }}"
issue_authors: "${{ vars.CODE_MONKEY_ISSUE_AUTHORS || '' }}"
only_known_authors: "${{ vars.ONLY_KNOWN_AUTHORS || '' }}"
allow_workflow_edits: ${{ inputs.allow_workflow_edits || false }}
# yamllint disable-line rule:line-length
allow_precommit_config_edits: ${{ inputs.allow_precommit_config_edits || false }}
harden_runner_egress: 'block'
# yamllint disable-line rule:line-length
harden_runner_allowlist: '@6e6cab073a93c0d58e4e8846d44e1cbddbac975b' # v0.21.0
assets_repository: "${{ github.repository }}"
assets_ref: "${{ github.sha }}"
secrets:
copilot_token: "${{ secrets.COPILOT_CLI_TOKEN }}"
regression:
name: 'Offline regression tests'
runs-on: 'ubuntu-latest'
timeout-minutes: 10
permissions:
contents: read # Test checked-out code without write credentials
steps:
- name: 'Harden runner'
# yamllint disable-line rule:line-length
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: 'audit'
- name: 'Checkout repository'
# yamllint disable-line rule:line-length
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Guarded as in code-monkey.yaml, which says why: setup-uv works
# outside the workspace with its interpreter lookup disabled, and
# uv runs only the Python 'Install Python' installs.
- name: 'Set up uv'
id: setup-uv
# yamllint disable-line rule:line-length
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
working-directory: "${{ runner.temp }}"
tool-bin-dir: "${{ runner.temp }}/uv-tool-bin"
# Its post-step 'uv cache prune' would hit the invalid
# preference below.
enable-cache: false
env:
UV_NO_CONFIG: '1'
UV_NO_PROJECT: '1'
# setup-uv's only uv call here is "uv python find", whose
# result it executes; an invalid preference makes uv refuse
# its arguments before any lookup.
UV_PYTHON_PREFERENCE: 'lookup-disabled'
# Inherited, it makes setup-uv probe uv, which the line above
# fails.
UV_PYTHON_ARCH: ''
# setup-uv puts this directory on PATH ahead of its own uv
# before its bare 'uv python find', so an inherited one could
# hold the uv that runs. It is the one 'Install Python' fills.
UV_PYTHON_INSTALL_DIR: "${{ runner.temp }}/uv-python"
- name: 'Install Python'
id: python
shell: bash
# uv starts a .venv interpreter in its working directory to
# inspect it, even under env -i.
working-directory: "${{ runner.temp }}"
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
INSTALL_DIR: "${{ runner.temp }}/uv-python"
run: |
clean=(UV_NO_CONFIG=1 UV_NO_PROJECT=1
"UV_PYTHON_INSTALL_DIR=$INSTALL_DIR"
"UV_CACHE_DIR=$RUNNER_TEMP/uv-cache")
for name in HTTP_PROXY HTTPS_PROXY ALL_PROXY NO_PROXY http_proxy \
https_proxy all_proxy no_proxy SSL_CERT_FILE SSL_CERT_DIR \
UV_NATIVE_TLS; do
if [ -n "${!name+set}" ]; then clean+=("$name=${!name}"); fi
done
env -i "${clean[@]}" "$UV" python install --quiet --no-bin 3.13
# 'python find' starts any .venv interpreter in the working
# directory or above it; 'python list' reads the install's
# metadata instead.
listed=$(env -i "${clean[@]}" "$UV" python list --only-installed \
--managed-python --output-format json 3.13)
# The first entry's "path", past its other keys and the
# objects nested in them.
first='^\[\{([^{}"]|"[^"]*"|\{[^{}]*\})*"path":"([^"]+)"'
py=
if [[ "$listed" =~ $first ]]; then
py="${BASH_REMATCH[2]}"
fi
# uv lists an install below the working directory relative to
# it, so resolve it there, and refuse '..' before the check.
case "$py" in
/*) ;;
?*) py="$PWD/$py" ;;
esac
case "$py/" in
*/../*) py= ;;
esac
case "$py" in
"$INSTALL_DIR"/*) ;;
*) echo "::error::uv found Python outside its install directory"
exit 1 ;;
esac
echo "path=$py" >> "$GITHUB_OUTPUT"
- name: 'Run offline regression suite'
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
PYTHON: "${{ steps.python.outputs.path }}"
run: |
"$UV" run --locked --python "$PYTHON" \
python -B -m unittest discover -s tests -v
# pre-commit.ci skips the actionlint-shellcheck hook because it runs
# past that service's 180-second limit. This job runs the same hook,
# at the rev and arguments .pre-commit-config.yaml pins, so the
# workflow files keep their actionlint and ShellCheck coverage.
actionlint:
name: 'actionlint with ShellCheck'
runs-on: 'ubuntu-latest'
timeout-minutes: 15
permissions:
contents: read # Lint checked-out workflows without write credentials
steps:
- name: 'Harden runner'
# yamllint disable-line rule:line-length
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: 'audit'
- name: 'Checkout repository'
# yamllint disable-line rule:line-length
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Guarded as in code-monkey.yaml, which says why: setup-uv works
# outside the workspace with its interpreter lookup disabled, and
# uv runs only the Python 'Install Python' installs.
- name: 'Set up uv'
id: setup-uv
# yamllint disable-line rule:line-length
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
working-directory: "${{ runner.temp }}"
tool-bin-dir: "${{ runner.temp }}/uv-tool-bin"
# Its post-step 'uv cache prune' would hit the invalid
# preference below.
enable-cache: false
env:
UV_NO_CONFIG: '1'
UV_NO_PROJECT: '1'
# setup-uv's only uv call here is "uv python find", whose
# result it executes; an invalid preference makes uv refuse
# its arguments before any lookup.
UV_PYTHON_PREFERENCE: 'lookup-disabled'
# Inherited, it makes setup-uv probe uv, which the line above
# fails.
UV_PYTHON_ARCH: ''
# setup-uv puts this directory on PATH ahead of its own uv
# before its bare 'uv python find', so an inherited one could
# hold the uv that runs. It is the one 'Install Python' fills.
UV_PYTHON_INSTALL_DIR: "${{ runner.temp }}/uv-python"
- name: 'Install Python'
id: python
shell: bash
# uv starts a .venv interpreter in its working directory to
# inspect it, even under env -i.
working-directory: "${{ runner.temp }}"
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
INSTALL_DIR: "${{ runner.temp }}/uv-python"
run: |
clean=(UV_NO_CONFIG=1 UV_NO_PROJECT=1
"UV_PYTHON_INSTALL_DIR=$INSTALL_DIR"
"UV_CACHE_DIR=$RUNNER_TEMP/uv-cache")
for name in HTTP_PROXY HTTPS_PROXY ALL_PROXY NO_PROXY http_proxy \
https_proxy all_proxy no_proxy SSL_CERT_FILE SSL_CERT_DIR \
UV_NATIVE_TLS; do
if [ -n "${!name+set}" ]; then clean+=("$name=${!name}"); fi
done
env -i "${clean[@]}" "$UV" python install --quiet --no-bin 3.13
# 'python find' starts any .venv interpreter in the working
# directory or above it; 'python list' reads the install's
# metadata instead.
listed=$(env -i "${clean[@]}" "$UV" python list --only-installed \
--managed-python --output-format json 3.13)
# The first entry's "path", past its other keys and the
# objects nested in them.
first='^\[\{([^{}"]|"[^"]*"|\{[^{}]*\})*"path":"([^"]+)"'
py=
if [[ "$listed" =~ $first ]]; then
py="${BASH_REMATCH[2]}"
fi
# uv lists an install below the working directory relative to
# it, so resolve it there, and refuse '..' before the check.
case "$py" in
/*) ;;
?*) py="$PWD/$py" ;;
esac
case "$py/" in
*/../*) py= ;;
esac
case "$py" in
"$INSTALL_DIR"/*) ;;
*) echo "::error::uv found Python outside its install directory"
exit 1 ;;
esac
echo "path=$py" >> "$GITHUB_OUTPUT"
- name: 'Install prek'
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
PYTHON: "${{ steps.python.outputs.path }}"
run: |
"$UV" tool install --python "$PYTHON" 'prek==0.4.10'
- name: 'Run actionlint with ShellCheck'
run: |
"$RUNNER_TEMP/uv-tool-bin/prek" run actionlint-shellcheck --all-files
# Runs the select job's uv steps exactly as code-monkey.yaml writes
# them (the contract tests hold the copies equal) against planted
# interpreters. Files: a .venv and a .python-version in the workspace
# root, setup-uv's default working directory, and in the assets
# checkout, where the pre-flight runs uv, plus a uv.toml in the root.
# Job environment, as an earlier step of a called job could set it
# through GITHUB_PATH and GITHUB_ENV: the bait directory first on
# PATH, a uv Python install directory holding a bait uv, and each
# leg's variables naming the bait. Each planted
# interpreter, and the bait uv, appends to a marker as it starts and
# exits 1, because uv passes over an interpreter that fails without
# failing the step; a control proves the bait live before uv runs.
uv-workdir:
name: 'uv steps ignore planted Python (${{ matrix.leg }})'
runs-on: 'ubuntu-latest'
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
leg: ['uv-python', 'venv']
permissions:
contents: read # Check out the assets as the select job does
steps:
- name: 'Harden runner'
# yamllint disable-line rule:line-length
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: 'audit'
- name: 'Checkout assets'
# yamllint disable-line rule:line-length
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: 'monkey-assets'
persist-credentials: false
- name: 'Plant Python and uv settings'
env:
LEG: "${{ matrix.leg }}"
run: |
exe() {
{ echo '#!/bin/sh'
echo "echo \"ran: \$0\" >> '$RUNNER_TEMP/planted-ran'"
echo 'exit 1'; } > "$1"
chmod +x "$1"
}
plant() {
mkdir -p "$1/.venv/bin" "$1/.venv/conda-meta"
printf 'home = /usr/bin\nversion = 3.12.0\n' > "$1/.venv/pyvenv.cfg"
exe "$1/.venv/bin/python3"
exe "$1/.venv/bin/python"
exe "$1/planted-python"
echo "$1/planted-python" > "$1/.python-version"
}
plant "$GITHUB_WORKSPACE"
plant "$GITHUB_WORKSPACE/monkey-assets"
printf '%s\n' 'cache-dir = "/nonexistent/planted-cache"' \
'required-version = "==0.0.1"' > "$GITHUB_WORKSPACE/uv.toml"
bait="$GITHUB_WORKSPACE/.venv/bin"
exe "$bait/python3.13"
exe "$bait/uv"
echo "$bait" >> "$GITHUB_PATH"
installs="$GITHUB_WORKSPACE/planted-uv-python"
mkdir -p "$installs"
exe "$installs/uv"
{
echo "UV_PYTHON_ARCH=$(uname -m)"
echo 'UV_NO_CACHE=1'
echo "UV_PYTHON_INSTALL_DIR=$installs"
case "$LEG" in
uv-python)
echo "UV_PYTHON=$bait/python3"
echo "UV_PYTHON_SEARCH_PATH=$bait" ;;
venv)
echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv"
echo "CONDA_PREFIX=$GITHUB_WORKSPACE/.venv"
echo "UV_INTERNAL__PARENT_INTERPRETER=$bait/python3" ;;
*) echo "::error::Unknown leg '$LEG'"
exit 1 ;;
esac
} >> "$GITHUB_ENV"
- name: 'Control: the bait is live'
run: |
# Starts the bait through each route this leg planted, from
# /usr/bin/python3 by absolute path: python3 on PATH is the
# bait now. Each start must leave a line in the marker.
routes="$(/usr/bin/python3 -I - <<'PY'
import os
import shutil
workspace = os.environ["GITHUB_WORKSPACE"]
routes = [
shutil.which("python3"),
shutil.which("uv"),
os.path.join(workspace, ".venv", "bin", "python"),
]
for name, below in (
("UV_PYTHON", ()),
("UV_INTERNAL__PARENT_INTERPRETER", ()),
("VIRTUAL_ENV", ("bin", "python")),
("CONDA_PREFIX", ("bin", "python")),
("UV_PYTHON_SEARCH_PATH", ("python3",)),
("UV_PYTHON_INSTALL_DIR", ("uv",)),
):
if os.environ.get(name):
routes.append(os.path.join(os.environ[name], *below))
print("\n".join(str(route) for route in routes))
PY
)"
want=0
while IFS= read -r route; do
want=$((want + 1))
"$route" || true
done <<< "$routes"
got="$(wc -l < "$RUNNER_TEMP/planted-ran" 2>/dev/null || echo 0)"
if [ "$want" -lt 6 ] || [ "$got" -ne "$want" ]; then
echo "::error::$want routes started the bait $got times"
exit 1
fi
rm "$RUNNER_TEMP/planted-ran"
- name: 'Set up uv'
id: setup-uv
# yamllint disable-line rule:line-length
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
working-directory: "${{ runner.temp }}"
tool-bin-dir: "${{ runner.temp }}/uv-tool-bin"
# Its post-step 'uv cache prune' would hit the invalid
# preference below.
enable-cache: false
env:
UV_NO_CONFIG: '1'
UV_NO_PROJECT: '1'
# setup-uv's only uv call here is "uv python find", whose
# result it executes; an invalid preference makes uv refuse
# its arguments before any lookup.
UV_PYTHON_PREFERENCE: 'lookup-disabled'
# Inherited, it makes setup-uv probe uv, which the line above
# fails.
UV_PYTHON_ARCH: ''
# setup-uv puts this directory on PATH ahead of its own uv
# before its bare 'uv python find', so an inherited one could
# hold the uv that runs. It is the one 'Install Python' fills.
UV_PYTHON_INSTALL_DIR: "${{ runner.temp }}/uv-python"
- name: 'Install Python'
id: python
shell: bash
# uv starts a .venv interpreter in its working directory to
# inspect it, even under env -i.
working-directory: "${{ runner.temp }}"
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
INSTALL_DIR: "${{ runner.temp }}/uv-python"
run: |
clean=(UV_NO_CONFIG=1 UV_NO_PROJECT=1
"UV_PYTHON_INSTALL_DIR=$INSTALL_DIR"
"UV_CACHE_DIR=$RUNNER_TEMP/uv-cache")
for name in HTTP_PROXY HTTPS_PROXY ALL_PROXY NO_PROXY http_proxy \
https_proxy all_proxy no_proxy SSL_CERT_FILE SSL_CERT_DIR \
UV_NATIVE_TLS; do
if [ -n "${!name+set}" ]; then clean+=("$name=${!name}"); fi
done
env -i "${clean[@]}" "$UV" python install --quiet --no-bin 3.13
# 'python find' starts any .venv interpreter in the working
# directory or above it; 'python list' reads the install's
# metadata instead.
listed=$(env -i "${clean[@]}" "$UV" python list --only-installed \
--managed-python --output-format json 3.13)
# The first entry's "path", past its other keys and the
# objects nested in them.
first='^\[\{([^{}"]|"[^"]*"|\{[^{}]*\})*"path":"([^"]+)"'
py=
if [[ "$listed" =~ $first ]]; then
py="${BASH_REMATCH[2]}"
fi
# uv lists an install below the working directory relative to
# it, so resolve it there, and refuse '..' before the check.
case "$py" in
/*) ;;
?*) py="$PWD/$py" ;;
esac
case "$py/" in
*/../*) py= ;;
esac
case "$py" in
"$INSTALL_DIR"/*) ;;
*) echo "::error::uv found Python outside its install directory"
exit 1 ;;
esac
echo "path=$py" >> "$GITHUB_OUTPUT"
- name: 'Install zizmor'
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
PYTHON: "${{ steps.python.outputs.path }}"
run: |
version="$(sed -e '/^#/d' -e '/^[[:space:]]*$/d' \
monkey-assets/config/zizmor-version.txt)"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo '::error::config/zizmor-version.txt names no exact version'
exit 1
fi
"$UV" tool install --python "$PYTHON" "zizmor==$version"
- name: 'Pre-flight: workflow contracts and audit'
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
PYTHON: "${{ steps.python.outputs.path }}"
run: |
# uv run reuses an existing project environment, and runs its
# interpreter, in the assets checkout or a uv workspace above
# it, even given an absolute --python. Build the environment
# under RUNNER_TEMP instead, from the trusted interpreter.
cd monkey-assets
UV_PROJECT_ENVIRONMENT="$RUNNER_TEMP/preflight-venv" \
"$UV" run --locked --python "$PYTHON" \
python -B scripts/preflight.py workflow --root .
- name: 'Check outputs and marker'
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
UV_VERSION: "${{ steps.setup-uv.outputs.uv-version }}"
PYTHON_VERSION: "${{ steps.setup-uv.outputs.python-version }}"
PYTHON: "${{ steps.python.outputs.path }}"
run: |
if [ -e "$RUNNER_TEMP/planted-ran" ]; then
echo '::error::A planted interpreter ran:'
cat "$RUNNER_TEMP/planted-ran"
exit 1
fi
installed="$("$UV" --version | cut -d' ' -f2)"
if ! [[ "$UV_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] ||
[ "$UV_VERSION" = 0.0.1 ] || [ "$installed" != "$UV_VERSION" ]; then
echo "::error::uv-version '$UV_VERSION', uv-path runs '$installed'"
exit 1
fi
# setup-uv reports 'unknown' when its own lookup fails, as the
# invalid preference makes it.
[ "$PYTHON_VERSION" = unknown ] || {
echo "::error::setup-uv's Python lookup found '$PYTHON_VERSION'"
exit 1; }
[ "${UV_CACHE_DIR:-}" != /nonexistent/planted-cache ] || {
echo '::error::UV_CACHE_DIR came from the planted uv.toml'
exit 1; }
base="$("$RUNNER_TEMP/preflight-venv/bin/python" -I -c \
'import sys; print(sys.base_prefix)')"
for path in "$PYTHON" "$base"; do
case "$path" in
"$RUNNER_TEMP/uv-python/"*) ;;
*) echo "::error::'$path' is not the Python uv installed"
exit 1 ;;
esac
done
echo "uv $UV_VERSION, Python $base, no planted file used"
docs:
name: 'Documentation build'
if: github.event_name == 'pull_request'
runs-on: 'ubuntu-latest'
permissions:
contents: read # Check out the documentation sources
timeout-minutes: 10
steps:
- name: 'Harden runner'
# yamllint disable-line rule:line-length
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: 'audit'
- name: 'Checkout repository'
# yamllint disable-line rule:line-length
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Guarded as in code-monkey.yaml, which says why: setup-uv works
# outside the workspace with its interpreter lookup disabled, and
# uv runs only the Python 'Install Python' installs.
- name: 'Set up uv'
id: setup-uv
# yamllint disable-line rule:line-length
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
working-directory: "${{ runner.temp }}"
tool-bin-dir: "${{ runner.temp }}/uv-tool-bin"
# Its post-step 'uv cache prune' would hit the invalid
# preference below.
enable-cache: false
env:
UV_NO_CONFIG: '1'
UV_NO_PROJECT: '1'
# setup-uv's only uv call here is "uv python find", whose
# result it executes; an invalid preference makes uv refuse
# its arguments before any lookup.
UV_PYTHON_PREFERENCE: 'lookup-disabled'
# Inherited, it makes setup-uv probe uv, which the line above
# fails.
UV_PYTHON_ARCH: ''
# setup-uv puts this directory on PATH ahead of its own uv
# before its bare 'uv python find', so an inherited one could
# hold the uv that runs. It is the one 'Install Python' fills.
UV_PYTHON_INSTALL_DIR: "${{ runner.temp }}/uv-python"
- name: 'Install Python'
id: python
shell: bash
# uv starts a .venv interpreter in its working directory to
# inspect it, even under env -i.
working-directory: "${{ runner.temp }}"
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
INSTALL_DIR: "${{ runner.temp }}/uv-python"
run: |
clean=(UV_NO_CONFIG=1 UV_NO_PROJECT=1
"UV_PYTHON_INSTALL_DIR=$INSTALL_DIR"
"UV_CACHE_DIR=$RUNNER_TEMP/uv-cache")
for name in HTTP_PROXY HTTPS_PROXY ALL_PROXY NO_PROXY http_proxy \
https_proxy all_proxy no_proxy SSL_CERT_FILE SSL_CERT_DIR \
UV_NATIVE_TLS; do
if [ -n "${!name+set}" ]; then clean+=("$name=${!name}"); fi
done
env -i "${clean[@]}" "$UV" python install --quiet --no-bin 3.13
# 'python find' starts any .venv interpreter in the working
# directory or above it; 'python list' reads the install's
# metadata instead.
listed=$(env -i "${clean[@]}" "$UV" python list --only-installed \
--managed-python --output-format json 3.13)
# The first entry's "path", past its other keys and the
# objects nested in them.
first='^\[\{([^{}"]|"[^"]*"|\{[^{}]*\})*"path":"([^"]+)"'
py=
if [[ "$listed" =~ $first ]]; then
py="${BASH_REMATCH[2]}"
fi
# uv lists an install below the working directory relative to
# it, so resolve it there, and refuse '..' before the check.
case "$py" in
/*) ;;
?*) py="$PWD/$py" ;;
esac
case "$py/" in
*/../*) py= ;;
esac
case "$py" in
"$INSTALL_DIR"/*) ;;
*) echo "::error::uv found Python outside its install directory"
exit 1 ;;
esac
echo "path=$py" >> "$GITHUB_OUTPUT"
# Proves the site builds from the pull request head without
# granting it any Pages permission; the deployment lives in
# documentation.yaml and runs from the default branch alone.
- name: 'Build documentation'
shell: bash
env:
UV: "${{ steps.setup-uv.outputs.uv-path }}"
PYTHON: "${{ steps.python.outputs.path }}"
run: |
venv="$RUNNER_TEMP/docs-venv"
"$UV" venv --python "$PYTHON" "$venv"
"$UV" pip install --python "$venv/bin/python" --require-hashes \
--requirement docs/requirements.txt
"$venv/bin/python" -I -m mkdocs build --strict