Skip to content

Commit 4b7f184

Browse files
authored
Auto-accept snapshot changes as part of typeshed-sync PRs (#20892)
1 parent d2a6ef7 commit 4b7f184

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

.github/workflows/sync_typeshed.yaml

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ name: Sync typeshed
1616
# 3. Once the Windows worker is done, a MacOS worker:
1717
# a. Checks out the branch created by the Linux worker
1818
# b. Syncs all docstrings available on MacOS that are not available on Linux or Windows
19-
# c. Commits the changes and pushes them to the same upstream branch
20-
# d. Creates a PR against the `main` branch using the branch all three workers have pushed to
19+
# c. Attempts to update any snapshots that might have changed
20+
# (this sub-step is allowed to fail)
21+
# d. Commits the changes and pushes them to the same upstream branch
22+
# e. Creates a PR against the `main` branch using the branch all three workers have pushed to
2123
# 4. If any of steps 1-3 failed, an issue is created in the `astral-sh/ruff` repository
2224

2325
on:
@@ -27,7 +29,12 @@ on:
2729
- cron: "0 0 1,15 * *"
2830

2931
env:
30-
FORCE_COLOR: 1
32+
# Don't set this flag globally for the workflow: it does strange things
33+
# to the snapshots in the `cargo insta test --accept` step in the MacOS job.
34+
#
35+
# FORCE_COLOR: 1
36+
37+
CARGO_TERM_COLOR: always
3138
GH_TOKEN: ${{ github.token }}
3239

3340
# The name of the upstream branch that the first worker creates,
@@ -86,6 +93,8 @@ jobs:
8693
git commit -m "Sync typeshed. Source commit: https://github.com/python/typeshed/commit/$(git -C ../typeshed rev-parse HEAD)" --allow-empty
8794
- name: Sync Linux docstrings
8895
if: ${{ success() }}
96+
env:
97+
FORCE_COLOR: 1
8998
run: |
9099
cd ruff
91100
./scripts/codemod_docstrings.sh
@@ -125,6 +134,8 @@ jobs:
125134
- name: Sync Windows docstrings
126135
id: docstrings
127136
shell: bash
137+
env:
138+
FORCE_COLOR: 1
128139
run: ./scripts/codemod_docstrings.sh
129140
- name: Commit the changes
130141
if: ${{ steps.docstrings.outcome == 'success' }}
@@ -161,26 +172,63 @@ jobs:
161172
git config --global user.name typeshedbot
162173
git config --global user.email '<>'
163174
- name: Sync macOS docstrings
164-
run: ./scripts/codemod_docstrings.sh
165-
- name: Commit and push the changes
166175
if: ${{ success() }}
176+
env:
177+
FORCE_COLOR: 1
167178
run: |
179+
./scripts/codemod_docstrings.sh
168180
git commit -am "Sync macOS docstrings" --allow-empty
169-
181+
- name: Format the changes
182+
if: ${{ success() }}
183+
env:
184+
FORCE_COLOR: 1
185+
run: |
170186
# Here we just reformat the codemodded stubs so that they are
171187
# consistent with the other typeshed stubs around them.
172188
# Typeshed formats code using black in their CI, so we just invoke
173189
# black on the stubs the same way that typeshed does.
174190
uvx black "${VENDORED_TYPESHED}/stdlib" --config "${VENDORED_TYPESHED}/pyproject.toml" || true
175191
git commit -am "Format codemodded docstrings" --allow-empty
176-
192+
- name: Remove typeshed pyproject.toml file
193+
if: ${{ success() }}
194+
run: |
177195
rm "${VENDORED_TYPESHED}/pyproject.toml"
178196
git commit -am "Remove pyproject.toml file"
179-
180-
git push
181-
- name: Create a PR
197+
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
198+
- name: "Install Rust toolchain"
199+
if: ${{ success() }}
200+
run: rustup show
201+
- name: "Install mold"
202+
if: ${{ success() }}
203+
uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
204+
- name: "Install cargo nextest"
205+
if: ${{ success() }}
206+
uses: taiki-e/install-action@522492a8c115f1b6d4d318581f09638e9442547b # v2.62.21
207+
with:
208+
tool: cargo-nextest
209+
- name: "Install cargo insta"
210+
if: ${{ success() }}
211+
uses: taiki-e/install-action@522492a8c115f1b6d4d318581f09638e9442547b # v2.62.21
212+
with:
213+
tool: cargo-insta
214+
- name: Update snapshots
182215
if: ${{ success() }}
183216
run: |
217+
# The `cargo insta` docs indicate that `--unreferenced=delete` might be a good option,
218+
# but from local testing it appears to just revert all changes made by `cargo insta test --accept`.
219+
#
220+
# If there were only snapshot-related failures, `cargo insta test --accept` will have exit code 0,
221+
# but if there were also other mdtest failures (for example), it will return a nonzero exit code.
222+
# We don't care about other tests failing here, we just want snapshots updated where possible,
223+
# so we use `|| true` here to ignore the exit code.
224+
cargo insta test --accept --color=always --all-features --test-runner=nextest || true
225+
- name: Commit snapshot changes
226+
if: ${{ success() }}
227+
run: git commit -am "Update snapshots" || echo "No snapshot changes to commit"
228+
- name: Push changes upstream and create a PR
229+
if: ${{ success() }}
230+
run: |
231+
git push
184232
gh pr list --repo "${GITHUB_REPOSITORY}" --head "${UPSTREAM_BRANCH}" --json id --jq length | grep 1 && exit 0 # exit if there is existing pr
185233
gh pr create --title "[ty] Sync vendored typeshed stubs" --body "Close and reopen this PR to trigger CI" --label "ty"
186234

0 commit comments

Comments
 (0)