Repository navigation
821 lines (756 loc) · 33.8 KB
/
Copy pathfix-bug.yml
File metadata and controls
821 lines (756 loc) · 33.8 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
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# Attempt a focused production fix for a reproduced bug with a passing regression test.
name: "fix-bug"
on:
workflow_call:
inputs:
issue:
description: "An issue URL or number"
required: true
type: string
issue-number:
description: "The verified upstream issue number"
required: true
type: string
reproduction-result:
description: "The confirmed bug reproduction result"
required: true
type: string
reproduction-thread-artifact-id:
description: "The immutable artifact ID of the reproduction Codex thread"
required: true
type: string
parent-pull-request:
description: "The draft regression-test pull request URL"
required: true
type: string
parent-head-ref:
description: "The regression-test branch"
required: true
type: string
parent-head-sha:
description: "The verified regression-test commit"
required: true
type: string
runner:
description: "The runner to use for bug fixing"
default: github-ubuntu-24.04-x86_64-4
required: false
type: string
outputs:
result:
description: "The bug-fix creation result"
value: ${{ jobs.fix.outputs.result }}
pull-request:
description: "The draft stacked bug-fix pull request URL"
value: ${{ jobs.publish.outputs.pull-request }}
permissions: {}
env:
UV_LOCKED: 1
jobs:
fix:
if: github.repository == 'astral-sh/uv'
runs-on: ${{ inputs.runner }}
environment:
name: automations
deployment: false
timeout-minutes: 60
permissions:
actions: read
contents: read
issues: read
outputs:
bundle-artifact-id: ${{ steps.upload-fix.outputs.artifact-id }}
context-artifact-id: ${{ steps.upload-context.outputs.artifact-id }}
context-sha: ${{ steps.issue-context.outputs.head-sha }}
created: ${{ steps.commit-fix.outputs.created }}
existing-head: ${{ steps.prepare.outputs.existing-head }}
parent-head-sha: ${{ steps.prepare.outputs.parent-head-sha }}
publish: ${{ steps.commit-fix.outputs.publish }}
pull-request-title: ${{ steps.commit-fix.outputs.pull-request-title }}
result: ${{ steps.commit-fix.outputs.result }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: "Load issue context"
id: issue-context
uses: $/.github/actions/load-issue-context
with:
issue-number: ${{ inputs.issue-number }}
path: ${{ runner.temp }}/issue-context
- name: "Load reproduction Codex thread"
id: reproduction-thread
uses: $/.github/actions/load-codex-thread
with:
repository: ${{ github.repository }}
run-id: ${{ github.run_id }}
artifact-id: ${{ inputs.reproduction-thread-artifact-id }}
github-token: ${{ github.token }}
path: ${{ runner.temp }}/codex-home/sessions
- name: "Check uv runner support"
if: ${{ !((runner.os == 'Linux' && runner.arch == 'X64') || (runner.os == 'macOS' && runner.arch == 'ARM64')) }}
shell: bash
run: |
echo "Unsupported uv runner: $RUNNER_OS/$RUNNER_ARCH" >&2
exit 1
- name: "Install uv on Linux x64"
if: ${{ runner.os == 'Linux' && runner.arch == 'X64' }}
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.13.6"
checksum: "f29c3e94ffabd7e6f3ba521dba169a9b7ec12100bf3257087f0f24f6123f3645"
enable-cache: false
- name: "Install uv on macOS ARM64"
if: ${{ runner.os == 'macOS' && runner.arch == 'ARM64' }}
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.13.6"
checksum: "60fbd5c8a1ed681845eea28d9d622fcde03c51e91a43465b64a1e17db1ed3472"
enable-cache: false
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
with:
save-if: false
- name: "Install required Python versions"
env:
UV_PYTHON_DOWNLOADS_JSON_URL: crates/uv-python-managed/download-metadata.json
run: uv python install
- name: "Prepare trusted bug-fix context"
id: prepare
env:
GH_TOKEN: ${{ github.token }}
ISSUE: ${{ inputs.issue }}
ISSUE_NUMBER: ${{ inputs.issue-number }}
PARENT_HEAD_REF: ${{ inputs.parent-head-ref }}
PARENT_HEAD_SHA: ${{ inputs.parent-head-sha }}
PARENT_PULL_REQUEST: ${{ inputs.parent-pull-request }}
REPRODUCTION_RESULT: ${{ inputs.reproduction-result }}
run: |
mkdir -p "$RUNNER_TEMP/codex-home"
cp agents/codex/config.toml "$RUNNER_TEMP/codex-home/config.toml"
cp agents/prompts/fix-reproduced-bug.md "$RUNNER_TEMP/fix-reproduced-bug.md"
cp agents/schemas/fix-reproduced-bug.json "$RUNNER_TEMP/fix-reproduced-bug.json"
gh issue view "$ISSUE" \
--repo "$GITHUB_REPOSITORY" \
--json number,title,body,author \
> "$RUNNER_TEMP/issue-triage-event.json"
printf '%s\n' "$REPRODUCTION_RESULT" > "$RUNNER_TEMP/bug-reproduction-result.json"
issue_number="$(jq --raw-output '.number' "$RUNNER_TEMP/issue-triage-event.json")"
if ! [[ "$ISSUE_NUMBER" =~ ^[1-9][0-9]*$ ]] ||
[ "$issue_number" != "$ISSUE_NUMBER" ] ||
[ "$PARENT_HEAD_REF" != "automations/reproduce-bug/$issue_number" ] ||
! [[ "$PARENT_HEAD_SHA" =~ ^[0-9a-f]{40}$ ]] ||
! [[ "$PARENT_PULL_REQUEST" =~ ^https://github\.com/astral-sh/uv-dev/pull/[1-9][0-9]*$ ]]; then
echo "The regression-test pull request context is invalid." >&2
exit 1
fi
pull_request_number="${PARENT_PULL_REQUEST##*/}"
gh api "repos/astral-sh/uv-dev/pulls/$pull_request_number" \
> "$RUNNER_TEMP/bug-regression-pull-request.json"
if ! jq --exit-status \
--arg head_ref "$PARENT_HEAD_REF" '
(.state == "open" or .state == "closed")
and .base.ref == "main"
and .base.repo.full_name == "astral-sh/uv-dev"
and .head.repo.full_name == "astral-sh/uv-dev"
and .head.ref == $head_ref
and (.head.sha | test("^[0-9a-f]{40}$"))
' "$RUNNER_TEMP/bug-regression-pull-request.json" > /dev/null; then
echo "The regression-test pull request no longer matches its verified branch." >&2
exit 1
fi
expected_parent_head_sha="$PARENT_HEAD_SHA"
PARENT_HEAD_SHA="$(jq --raw-output '.head.sha' \
"$RUNNER_TEMP/bug-regression-pull-request.json")"
if jq --exit-status '.state == "closed"' \
"$RUNNER_TEMP/bug-regression-pull-request.json" > /dev/null; then
gh api repos/astral-sh/uv/pulls \
--method GET \
--raw-field state=all \
--raw-field head="astral-sh:$PARENT_HEAD_REF" \
--raw-field base=main \
> "$RUNNER_TEMP/promoted-regression-pull-requests.json"
if ! jq --exit-status \
--arg head_ref "$PARENT_HEAD_REF" \
--arg head_sha "$PARENT_HEAD_SHA" '
length == 1
and (.[0].state == "open" or .[0].merged_at != null)
and .[0].base.ref == "main"
and .[0].base.repo.full_name == "astral-sh/uv"
and .[0].head.repo.full_name == "astral-sh/uv"
and .[0].head.ref == $head_ref
and .[0].head.sha == $head_sha
' "$RUNNER_TEMP/promoted-regression-pull-requests.json" > /dev/null; then
echo "The closed regression-test pull request was not promoted at its verified head." >&2
exit 1
fi
fi
git -c core.hooksPath=/dev/null fetch --no-tags \
https://github.com/astral-sh/uv-dev.git "refs/heads/$PARENT_HEAD_REF"
if [ "$(git rev-parse 'FETCH_HEAD^{commit}')" != "$PARENT_HEAD_SHA" ]; then
echo "The regression-test branch changed; refusing to use a stale revision." >&2
exit 1
fi
if ! git merge-base --is-ancestor "$GITHUB_SHA" "$PARENT_HEAD_SHA" ||
! git merge-base --is-ancestor "$expected_parent_head_sha" "$PARENT_HEAD_SHA"; then
echo "The regression-test branch does not extend its verified revision." >&2
exit 1
fi
while IFS= read -r -d '' path; do
case "$path" in
crates/uv/tests/*|crates/uv-client/tests/it/*) ;;
*)
echo "The regression-test commit changes a non-test file: $path" >&2
exit 1
;;
esac
done < <(git diff --name-only -z "$GITHUB_SHA" "$PARENT_HEAD_SHA")
fix_branch="automations/fix-bug/$issue_number"
gh pr list \
--repo astral-sh/uv-dev \
--head "$fix_branch" \
--state open \
--json number \
--limit 2 \
> "$RUNNER_TEMP/bug-fix-pull-requests.json"
if [ "$(jq 'length' "$RUNNER_TEMP/bug-fix-pull-requests.json")" -gt 1 ]; then
echo "Multiple open pull requests claim the bug-fix branch." >&2
exit 1
fi
fix_head="$(git ls-remote --heads \
https://github.com/astral-sh/uv-dev.git \
"refs/heads/$fix_branch" | cut -f 1)"
existing=false
if [ -n "$fix_head" ]; then
if ! [[ "$fix_head" =~ ^[0-9a-f]{40}$ ]]; then
echo "The existing bug-fix branch head is invalid." >&2
exit 1
fi
gh api "repos/astral-sh/uv-dev/commits/$fix_head" \
> "$RUNNER_TEMP/bug-fix-commit.json"
if ! jq --exit-status --arg head_sha "$fix_head" '
.sha == $head_sha
and .author.login == "astral-automations-bot[bot]"
and .committer.login == "astral-automations-bot[bot]"
' "$RUNNER_TEMP/bug-fix-commit.json" > /dev/null; then
echo "The existing bug-fix branch is not owned by this automation." >&2
exit 1
fi
if [ "$(jq 'length' "$RUNNER_TEMP/bug-fix-pull-requests.json")" = "1" ]; then
fix_pull_request_number="$(jq '.[0].number' \
"$RUNNER_TEMP/bug-fix-pull-requests.json")"
gh api "repos/astral-sh/uv-dev/pulls/$fix_pull_request_number" \
> "$RUNNER_TEMP/bug-fix-pull-request.json"
if ! jq --exit-status \
--arg head_ref "$fix_branch" \
--arg head_sha "$fix_head" \
--arg parent_ref "$PARENT_HEAD_REF" '
.state == "open"
and .user.login == "astral-automations-bot[bot]"
and .base.repo.full_name == "astral-sh/uv-dev"
and .base.ref == $parent_ref
and .head.repo.full_name == "astral-sh/uv-dev"
and .head.ref == $head_ref
and .head.sha == $head_sha
' "$RUNNER_TEMP/bug-fix-pull-request.json" > /dev/null; then
echo "The existing bug-fix pull request is not owned by this automation." >&2
exit 1
fi
fi
git -c core.hooksPath=/dev/null fetch --no-tags \
https://github.com/astral-sh/uv-dev.git "refs/heads/$fix_branch"
if [ "$(git rev-parse 'FETCH_HEAD^{commit}')" != "$fix_head" ] ||
[ "$(git rev-parse "$fix_head^")" != "$PARENT_HEAD_SHA" ] ||
[ "$(git show --no-patch --format=%s "$fix_head")" != "Fix reproduced bug" ] ||
[ "$(git show --no-patch --format=%ae "$fix_head")" != \
"305554984+astral-automations-bot[bot]@users.noreply.github.com" ]; then
echo "The existing bug-fix branch is not the expected automated fix." >&2
exit 1
fi
existing=true
elif [ "$(jq 'length' "$RUNNER_TEMP/bug-fix-pull-requests.json")" != "0" ]; then
echo "The bug-fix pull request exists, but its branch is missing." >&2
exit 1
fi
git -c core.hooksPath=/dev/null checkout --detach \
"$PARENT_HEAD_SHA"
if [ "$existing" = "true" ]; then
git -c core.hooksPath=/dev/null checkout --detach "$fix_head"
fi
{
echo "existing=$existing"
echo "existing-head=$fix_head"
echo "parent-head-sha=$PARENT_HEAD_SHA"
} >> "$GITHUB_OUTPUT"
- name: "Fix reproduced bug"
id: fix-bug
if: steps.prepare.outputs.existing != 'true'
uses: openai/codex-action@c05cfd74ad95c626cdf05c6685e62becc3bf7813
env:
CARGO_HOME: ${{ runner.temp }}/cargo-home
GH_TOKEN: ${{ github.token }}
INSTA_UPDATE: "no"
TMPDIR: ${{ runner.temp }}
UV_CACHE_DIR: ${{ runner.temp }}/uv-fix-bug-cache
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
codex-version: "0.157.1"
codex-home: "${{ runner.temp }}/codex-home"
effort: high
codex-args: >-
["resume", "${{ steps.reproduction-thread.outputs.session-id }}", "-"]
permission-profile: "fix-reproduced-bug"
safety-strategy: drop-sudo
allow-users: "*"
prompt-file: "${{ runner.temp }}/fix-reproduced-bug.md"
output-schema-file: "${{ runner.temp }}/fix-reproduced-bug.json"
- name: "Upload Codex thread"
if: always() && steps.prepare.outputs.existing != 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: codex-thread-fix-reproduced-bug-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/codex-home/sessions
if-no-files-found: warn
- name: "Commit verified bug fix"
id: commit-fix
env:
EXISTING_FIX: ${{ steps.prepare.outputs.existing }}
FIX_RESULT: ${{ steps.fix-bug.outputs.final-message }}
PARENT_HEAD_SHA: ${{ steps.prepare.outputs.parent-head-sha }}
run: |
if [ "$EXISTING_FIX" = "true" ]; then
FIX_RESULT="$(jq --null-input --compact-output \
--arg issue_title "$(jq --raw-output '.title' \
"$RUNNER_TEMP/issue-triage-event.json")" '{
outcome: "fixed",
summary: "Reused the existing verified automated bug fix.",
validation: ["Verified the production fix and existing regression test."],
pull_request_title: $issue_title
}')"
fi
printf '%s\n' "$FIX_RESULT" > "$RUNNER_TEMP/bug-fix-result.json"
fix_outcome="$(jq --raw-output '.outcome' "$RUNNER_TEMP/bug-fix-result.json")"
if [ -z "$(git status --porcelain)" ] && [ "$EXISTING_FIX" != "true" ]; then
if [ "$fix_outcome" != "not_fixed" ]; then
echo "Codex reported a fix, but the checkout is unchanged." >&2
exit 1
fi
{
echo "created=false"
echo "publish=false"
jq --raw-output '
del(.pull_request_title) | "result=\(tojson)"
' "$RUNNER_TEMP/bug-fix-result.json"
} >> "$GITHUB_OUTPUT"
jq --raw-output '.summary' "$RUNNER_TEMP/bug-fix-result.json" \
>> "$GITHUB_STEP_SUMMARY"
exit 0
fi
if [ "$fix_outcome" != "fixed" ] || ! jq --exit-status '
(.validation | length > 0)
and (.pull_request_title | type == "string" and length > 0
and (test("[\\r\\n]") | not))
' "$RUNNER_TEMP/bug-fix-result.json" > /dev/null; then
echo "The modified checkout does not contain a validated bug fix and pull request." >&2
exit 1
fi
git -c core.hooksPath=/dev/null add -A
source_changed=false
regression_changed=false
changed_files=0
while IFS= read -r -d '' path; do
case "$path" in
crates/*/src/*)
source_changed=true
;;
crates/uv/tests/*|crates/uv-client/tests/it/*)
if git diff --name-only "$GITHUB_SHA" "$PARENT_HEAD_SHA" -- "$path" |
grep -Fxq "$path"; then
regression_changed=true
fi
;;
*)
echo "The bug fix changes a protected or unrelated file: $path" >&2
exit 1
;;
esac
changed_files=$((changed_files + 1))
done < <(git diff --cached --name-only -z "$PARENT_HEAD_SHA")
if [ "$source_changed" != "true" ] || [ "$regression_changed" != "true" ] ||
[ "$changed_files" -gt 50 ]; then
echo "The fix must update production code and the existing regression test." >&2
exit 1
fi
if git diff --cached --raw "$PARENT_HEAD_SHA" |
grep -Eq '^:[0-7]+ (120000|160000) '; then
echo "The bug fix introduces a symbolic link or Git submodule." >&2
exit 1
fi
git diff --cached --check "$PARENT_HEAD_SHA"
created=false
if [ "$EXISTING_FIX" != "true" ]; then
git \
-c core.hooksPath=/dev/null \
-c user.name="astral-automations-bot[bot]" \
-c user.email="305554984+astral-automations-bot[bot]@users.noreply.github.com" \
commit --message "Fix reproduced bug"
created=true
fi
git -c core.hooksPath=/dev/null bundle create \
"$RUNNER_TEMP/fixed-bug.bundle" "$PARENT_HEAD_SHA..HEAD"
{
echo "created=$created"
echo "publish=true"
jq --raw-output '"pull-request-title=\(.pull_request_title)"' \
"$RUNNER_TEMP/bug-fix-result.json"
jq --raw-output '
del(.pull_request_title) | "result=\(tojson)"
' "$RUNNER_TEMP/bug-fix-result.json"
} >> "$GITHUB_OUTPUT"
{
printf '%s\n\n' '### Reproduced bug fixed'
jq --raw-output '.summary' "$RUNNER_TEMP/bug-fix-result.json"
} >> "$GITHUB_STEP_SUMMARY"
- name: "Upload issue context"
id: upload-context
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: issue-fix-context-${{ inputs.issue-number }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/issue-context/README.md
if-no-files-found: error
retention-days: 1
- name: "Upload verified bug fix"
id: upload-fix
if: steps.commit-fix.outputs.publish == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: fixed-bug-${{ inputs.issue-number }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/fixed-bug.bundle
if-no-files-found: error
compression-level: 0
retention-days: 1
publish:
needs: fix
if: needs.fix.outputs.publish == 'true'
runs-on: ${{ github.repository_owner == 'astral-sh' && 'github-ubuntu-24.04-x86_64-2' || 'ubuntu-slim' }}
environment:
name: automations
deployment: false
timeout-minutes: 10
permissions:
contents: read
id-token: write # for the existing uv-dev credential broker
outputs:
pull-request: ${{ steps.open-pr.outputs.url }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.fix.outputs.bundle-artifact-id }}
path: ${{ runner.temp }}/fixed-bug
- name: "Verify regression and bug-fix commits"
id: verify
env:
EXISTING_HEAD_SHA: ${{ needs.fix.outputs.existing-head }}
GH_TOKEN: ${{ github.token }}
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_NOSYSTEM: "1"
ISSUE_NUMBER: ${{ inputs.issue-number }}
PARENT_HEAD_REF: ${{ inputs.parent-head-ref }}
PARENT_HEAD_SHA: ${{ needs.fix.outputs.parent-head-sha }}
PARENT_PULL_REQUEST: ${{ inputs.parent-pull-request }}
run: |
pull_request_number="${PARENT_PULL_REQUEST##*/}"
gh api "repos/astral-sh/uv-dev/pulls/$pull_request_number" \
> "$RUNNER_TEMP/bug-regression-pull-request.json"
if ! jq --exit-status \
--arg head_ref "$PARENT_HEAD_REF" \
--arg head_sha "$PARENT_HEAD_SHA" '
(.state == "open" or .state == "closed")
and .base.ref == "main"
and .base.repo.full_name == "astral-sh/uv-dev"
and .head.repo.full_name == "astral-sh/uv-dev"
and .head.ref == $head_ref
and .head.sha == $head_sha
' "$RUNNER_TEMP/bug-regression-pull-request.json" > /dev/null; then
echo "The regression-test pull request changed; refusing to publish the fix." >&2
exit 1
fi
if jq --exit-status '.state == "closed"' \
"$RUNNER_TEMP/bug-regression-pull-request.json" > /dev/null; then
gh api repos/astral-sh/uv/pulls \
--method GET \
--raw-field state=all \
--raw-field head="astral-sh:$PARENT_HEAD_REF" \
--raw-field base=main \
> "$RUNNER_TEMP/promoted-regression-pull-requests.json"
if ! jq --exit-status \
--arg head_ref "$PARENT_HEAD_REF" \
--arg head_sha "$PARENT_HEAD_SHA" '
length == 1
and (.[0].state == "open" or .[0].merged_at != null)
and .[0].base.ref == "main"
and .[0].base.repo.full_name == "astral-sh/uv"
and .[0].head.repo.full_name == "astral-sh/uv"
and .[0].head.ref == $head_ref
and .[0].head.sha == $head_sha
' "$RUNNER_TEMP/promoted-regression-pull-requests.json" > /dev/null; then
echo "The closed regression-test pull request was not promoted at its verified head." >&2
exit 1
fi
fi
git -c core.hooksPath=/dev/null fetch --no-tags \
https://github.com/astral-sh/uv-dev.git "refs/heads/$PARENT_HEAD_REF"
if [ "$(git rev-parse 'FETCH_HEAD^{commit}')" != "$PARENT_HEAD_SHA" ]; then
echo "The regression-test branch changed; refusing to publish the fix." >&2
exit 1
fi
if [ -n "$EXISTING_HEAD_SHA" ]; then
if ! [[ "$EXISTING_HEAD_SHA" =~ ^[0-9a-f]{40}$ ]]; then
echo "The existing bug-fix revision is invalid." >&2
exit 1
fi
fix_branch="automations/fix-bug/$ISSUE_NUMBER"
git -c core.hooksPath=/dev/null fetch --no-tags \
https://github.com/astral-sh/uv-dev.git "refs/heads/$fix_branch"
if [ "$(git rev-parse 'FETCH_HEAD^{commit}')" != "$EXISTING_HEAD_SHA" ]; then
echo "The existing bug-fix branch changed before publication." >&2
exit 1
fi
fi
bundle="$RUNNER_TEMP/fixed-bug/fixed-bug.bundle"
git -c core.hooksPath=/dev/null bundle verify "$bundle"
git -c core.hooksPath=/dev/null fetch --no-tags "$bundle" HEAD
fixed_head="$(git rev-parse 'FETCH_HEAD^{commit}')"
if [ "$(git rev-parse "$fixed_head^")" != "$PARENT_HEAD_SHA" ] ||
[ "$(git show --no-patch --format=%s "$fixed_head")" != "Fix reproduced bug" ] ||
[ "$(git show --no-patch --format=%ae "$fixed_head")" != \
"305554984+astral-automations-bot[bot]@users.noreply.github.com" ]; then
echo "The fix does not extend the verified regression-test commit." >&2
exit 1
fi
if [ -n "$EXISTING_HEAD_SHA" ] && [ "$fixed_head" != "$EXISTING_HEAD_SHA" ]; then
echo "The existing bug-fix bundle does not match its verified branch." >&2
exit 1
fi
source_changed=false
regression_changed=false
changed_files=0
while IFS= read -r -d '' path; do
case "$path" in
crates/*/src/*)
source_changed=true
;;
crates/uv/tests/*|crates/uv-client/tests/it/*)
if git diff --name-only "$GITHUB_SHA" "$PARENT_HEAD_SHA" -- "$path" |
grep -Fxq "$path"; then
regression_changed=true
fi
;;
*)
echo "The fix changes a protected or unrelated file: $path" >&2
exit 1
;;
esac
changed_files=$((changed_files + 1))
done < <(git diff --name-only -z "$PARENT_HEAD_SHA" "$fixed_head")
if [ "$source_changed" != "true" ] || [ "$regression_changed" != "true" ] ||
[ "$changed_files" -gt 50 ]; then
echo "The fix must update production code and the existing regression test." >&2
exit 1
fi
if git diff --raw "$PARENT_HEAD_SHA" "$fixed_head" |
grep -Eq '^:[0-7]+ (120000|160000) '; then
echo "The fix introduces a symbolic link or Git submodule." >&2
exit 1
fi
git diff --check "$PARENT_HEAD_SHA" "$fixed_head"
echo "head_sha=$fixed_head" >> "$GITHUB_OUTPUT"
- name: "Get uv-dev token"
id: token
uses: astral-sh/github-actions/simple-token-service@eb81cf4d13127c3f9539f621c17e4c65327636c8
with:
exchange-url: ${{ secrets.STS_API_URL }}/exchange
audience: ${{ secrets.STS_API_URL }}
repository: astral-sh/uv-dev
permissions: |
contents: write
pull_requests: write
- name: "Open stacked fix pull request"
id: open-pr
env:
FIXED_HEAD_SHA: ${{ steps.verify.outputs.head_sha }}
FIX_SUMMARY: ${{ fromJSON(needs.fix.outputs.result).summary }}
GH_TOKEN: ${{ steps.token.outputs.token }}
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_NOSYSTEM: "1"
ISSUE_NUMBER: ${{ inputs.issue-number }}
PARENT_HEAD_REF: ${{ inputs.parent-head-ref }}
PULL_REQUEST_TITLE: ${{ needs.fix.outputs.pull-request-title }}
run: |
branch="automations/fix-bug/$ISSUE_NUMBER"
gh pr list \
--repo astral-sh/uv-dev \
--head "$branch" \
--state open \
--json number,url,baseRefName,headRefName,headRefOid,author \
--limit 2 \
> "$RUNNER_TEMP/bug-fix-pull-requests.json"
if ! jq --exit-status \
--arg head_ref "$branch" \
--arg head_sha "$FIXED_HEAD_SHA" \
--arg parent_ref "$PARENT_HEAD_REF" '
length <= 1
and all(
.baseRefName == $parent_ref
and .headRefName == $head_ref
and .headRefOid == $head_sha
and .author.is_bot == true
and .author.login == "app/astral-automations-bot"
)
' "$RUNNER_TEMP/bug-fix-pull-requests.json" > /dev/null; then
echo "The existing bug-fix pull request is not owned by this automation." >&2
exit 1
fi
git -c core.hooksPath=/dev/null push \
"https://x-access-token:${GH_TOKEN}@github.com/astral-sh/uv-dev.git" \
"$FIXED_HEAD_SHA:refs/heads/$branch"
pull_request="$(jq --raw-output '.[0].url // empty' \
"$RUNNER_TEMP/bug-fix-pull-requests.json")"
if [ -z "$pull_request" ]; then
printf '%s Fixes astral-sh/uv#%s\n' \
"$FIX_SUMMARY" "$ISSUE_NUMBER" > "$RUNNER_TEMP/bug-fix-pull-request.md"
pull_request="$(
gh pr create \
--repo astral-sh/uv-dev \
--base "$PARENT_HEAD_REF" \
--head "$branch" \
--draft \
--title "$PULL_REQUEST_TITLE" \
--body-file "$RUNNER_TEMP/bug-fix-pull-request.md"
)"
fi
echo "url=$pull_request" >> "$GITHUB_OUTPUT"
printf 'Stacked fix pull request: %s\n' "$pull_request" >> "$GITHUB_STEP_SUMMARY"
context:
needs:
- fix
- publish
if: >-
always() &&
needs.fix.result == 'success' &&
needs.fix.outputs.result != '' &&
(needs.publish.result == 'success' || needs.publish.result == 'skipped')
runs-on: ${{ github.repository_owner == 'astral-sh' && 'github-ubuntu-24.04-x86_64-4' || 'ubuntu-latest' }}
environment:
name: automations
deployment: false
timeout-minutes: 10
concurrency:
group: issue-context-${{ inputs.issue-number }}
cancel-in-progress: false
permissions:
id-token: write # for the uv-dev issue-context credential broker
steps:
- name: "Download issue context"
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.fix.outputs.context-artifact-id }}
path: ${{ runner.temp }}/issue-context-update
- name: "Prepare fix context"
id: prepare-context
env:
CONTEXT_SHA: ${{ needs.fix.outputs.context-sha }}
FIX_PULL_REQUEST: ${{ needs.publish.outputs.pull-request }}
FIX_RESULT: ${{ needs.fix.outputs.result }}
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_NOSYSTEM: "1"
ISSUE_NUMBER: ${{ inputs.issue-number }}
run: |
if ! [[ "$ISSUE_NUMBER" =~ ^[1-9][0-9]*$ ]] ||
! [[ "$CONTEXT_SHA" =~ ^[0-9a-f]{40}$ ]]; then
echo "The issue number or context revision is invalid." >&2
exit 1
fi
printf '%s\n' "$FIX_RESULT" > "$RUNNER_TEMP/bug-fix-result.json"
if ! jq --exit-status --arg pull_request "$FIX_PULL_REQUEST" '
(.summary | type == "string" and length > 0)
and (.validation | type == "array")
and (
(
.outcome == "fixed"
and (.validation | length > 0)
and ($pull_request | test("^https://github\\.com/astral-sh/uv-dev/pull/[1-9][0-9]*$"))
)
or (
.outcome == "not_fixed"
and (.validation | length == 0)
and $pull_request == ""
)
)
' "$RUNNER_TEMP/bug-fix-result.json" > /dev/null; then
echo "The bug-fix result does not match its published pull request." >&2
exit 1
fi
branch="issue/$ISSUE_NUMBER"
git init --quiet "$RUNNER_TEMP/issue-context"
cd "$RUNNER_TEMP/issue-context"
git remote add origin https://github.com/astral-sh/uv-dev.git
git -c core.hooksPath=/dev/null fetch --quiet origin "refs/heads/$branch"
git -c core.hooksPath=/dev/null checkout --quiet FETCH_HEAD
if [ "$(git rev-parse HEAD)" != "$CONTEXT_SHA" ]; then
echo "The issue context changed while the fix was being prepared."
echo "Skipping the stale update to preserve the newer issue context."
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
jq --arg pull_request "$FIX_PULL_REQUEST" '
. + {pull_request: (if $pull_request == "" then null else $pull_request end)}
' "$RUNNER_TEMP/bug-fix-result.json" > fix.json
cp "$RUNNER_TEMP/issue-context-update/README.md" README.md
if [ -n "$FIX_PULL_REQUEST" ] &&
! grep -Fq "$FIX_PULL_REQUEST" README.md; then
printf '\nPull request: %s\n' "$FIX_PULL_REQUEST" >> README.md
fi
git -c core.hooksPath=/dev/null add fix.json README.md
if git diff --cached --quiet; then
echo "The existing fix context is unchanged."
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git \
-c core.hooksPath=/dev/null \
-c user.name="astral-automations-bot[bot]" \
-c user.email="305554984+astral-automations-bot[bot]@users.noreply.github.com" \
commit --message "Update fix context"
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: "Get issue context token"
if: steps.prepare-context.outputs.changed == 'true'
id: token
uses: astral-sh/github-actions/simple-token-service@eb81cf4d13127c3f9539f621c17e4c65327636c8
with:
exchange-url: ${{ secrets.STS_API_URL }}/exchange
audience: ${{ secrets.STS_API_URL }}
repository: astral-sh/uv-dev
permissions: |
contents: write
- name: "Persist fix context"
if: steps.prepare-context.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_NOSYSTEM: "1"
ISSUE_NUMBER: ${{ inputs.issue-number }}
run: |
branch="issue/$ISSUE_NUMBER"
cd "$RUNNER_TEMP/issue-context"
git -c core.hooksPath=/dev/null push \
"https://x-access-token:${GH_TOKEN}@github.com/astral-sh/uv-dev.git" \
"HEAD:refs/heads/$branch"
printf 'Issue context: https://github.com/astral-sh/uv-dev/tree/%s\n' "$branch" \
>> "$GITHUB_STEP_SUMMARY"