Skip to content

Commit 59dcd49

Browse files
committed
Auto-accept snapshot changes as part of typeshed-sync PRs
1 parent 85ff4f3 commit 59dcd49

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

.github/workflows/sync_typeshed.yaml

Lines changed: 30 additions & 9 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:
@@ -161,26 +163,45 @@ jobs:
161163
git config --global user.name typeshedbot
162164
git config --global user.email '<>'
163165
- name: Sync macOS docstrings
164-
run: ./scripts/codemod_docstrings.sh
165-
- name: Commit and push the changes
166166
if: ${{ success() }}
167167
run: |
168+
./scripts/codemod_docstrings.sh
168169
git commit -am "Sync macOS docstrings" --allow-empty
169-
170+
- name: Format the changes
171+
if: ${{ success() }}
172+
run: |
170173
# Here we just reformat the codemodded stubs so that they are
171174
# consistent with the other typeshed stubs around them.
172175
# Typeshed formats code using black in their CI, so we just invoke
173176
# black on the stubs the same way that typeshed does.
174177
uvx black "${VENDORED_TYPESHED}/stdlib" --config "${VENDORED_TYPESHED}/pyproject.toml" || true
175178
git commit -am "Format codemodded docstrings" --allow-empty
176-
179+
- name: Remove typeshed pyproject.toml file
180+
if: ${{ success() }}
181+
run: |
177182
rm "${VENDORED_TYPESHED}/pyproject.toml"
178183
git commit -am "Remove pyproject.toml file"
179-
180-
git push
181-
- name: Create a PR
184+
- name: "Install cargo insta"
185+
if: ${{ success() }}
186+
uses: taiki-e/install-action@522492a8c115f1b6d4d318581f09638e9442547b # v2.62.21
187+
with:
188+
tool: cargo-insta
189+
- name: Update snapshots
190+
if: ${{ success() }}
191+
run: |
192+
# The `cargo insta` docs indicate that `--unreferenced=delete` might be a good option,
193+
# but from local testing it appears to just revert all changes made by `cargo insta test --accept`.
194+
#
195+
# If there were only snapshot-related failures, `cargo insta test --accept` will have exit code 0,
196+
# but if there were also other mdtest failures (for example), it will return a nonzero exit code.
197+
# We don't care about other tests failing here, we just want snapshots updated where possible,
198+
# so we use `|| true` here to ignore the exit code.
199+
cargo insta test --accept || true
200+
git commit -am "Update snapshots" || echo "No snapshot changes to commit"
201+
- name: Push changes upstream and create a PR
182202
if: ${{ success() }}
183203
run: |
204+
git push
184205
gh pr list --repo "${GITHUB_REPOSITORY}" --head "${UPSTREAM_BRANCH}" --json id --jq length | grep 1 && exit 0 # exit if there is existing pr
185206
gh pr create --title "[ty] Sync vendored typeshed stubs" --body "Close and reopen this PR to trigger CI" --label "ty"
186207

0 commit comments

Comments
 (0)