Skip to content

Commit 5ee52c4

Browse files
committed
review
1 parent 2606527 commit 5ee52c4

2 files changed

Lines changed: 41 additions & 26 deletions

File tree

.github/workflows/typespec-python-regenerate.yml

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ permissions:
2222
pull-requests: write
2323
issues: write
2424

25+
# Note: with cancel-in-progress, a newer run can cancel an older one after it
26+
# has force-pushed the branch but before it finishes updating the tracking
27+
# issue. The newer run will redo the issue update, so the worst case is a
28+
# brief stale issue body that is immediately refreshed.
2529
concurrency:
2630
group: ${{ github.workflow }}
2731
cancel-in-progress: true
@@ -147,10 +151,11 @@ jobs:
147151
fi
148152
# Replace every README.md under gen/ with the template, except:
149153
# - the top-level gen/README.md
150-
# - the template itself (gen/template/README.md)
154+
# - anything under gen/template/ (the template itself and any
155+
# future siblings)
151156
find "$TARGET" -type f -name README.md \
152157
! -path "$TARGET/README.md" \
153-
! -path "$TEMPLATE" \
158+
! -path "$TARGET/template/*" \
154159
-print -exec cp -f "$TEMPLATE" {} \;
155160
156161
- name: Commit and push changes
@@ -242,11 +247,19 @@ jobs:
242247
TITLE="[typespec-python] Regenerate tests from ${SOURCE_LABEL}"
243248
244249
# Reuse an existing open tracking issue if one exists (matched by
245-
# title). We resolve the issue number BEFORE building the PR compare
246-
# URL so we can inject "Fixes #<N>" into the prefilled PR body — this
247-
# way the issue is closed automatically when the PR is merged.
248-
EXISTING_ISSUE=$(gh issue list --state open --search "\"$TITLE\" in:title" \
249-
--json number,title | jq -r --arg title "$TITLE" '.[] | select(.title == $title) | .number' | head -n1 || echo "")
250+
# exact title). We resolve the issue number BEFORE building the PR
251+
# compare URL so we can inject "Fixes #<N>" into the prefilled PR
252+
# body — this way the issue is closed automatically when the PR is
253+
# merged.
254+
#
255+
# We list by label rather than `--search`, because GitHub's search
256+
# tokenizer strips characters like `[`, `]`, `@`, `#` and `/`, so a
257+
# search query over our title can be ambiguous. Listing by label
258+
# plus an exact jq match is both faster and unambiguous.
259+
EXISTING_ISSUE=$(gh issue list --state open --label typespec-python \
260+
--limit 100 --json number,title \
261+
| jq -r --arg title "$TITLE" '.[] | select(.title == $title) | .number' \
262+
| head -n1 || echo "")
250263
251264
if [ -n "$EXISTING_ISSUE" ]; then
252265
ISSUE_NUMBER="$EXISTING_ISSUE"
@@ -276,16 +289,16 @@ jobs:
276289
if [ -n "$EXISTING_PR_URL" ]; then
277290
ISSUE_BODY="A pull request already exists for this regeneration.
278291
279-
👉 [View pull request #${EXISTING_PR_NUMBER}](${EXISTING_PR_URL})
292+
👉 [View pull request #${EXISTING_PR_NUMBER}](${EXISTING_PR_URL})
280293
281-
The branch \`${BRANCH}\` was just updated with the latest regenerated tests; the existing PR will reflect those changes automatically.
294+
The branch \`${BRANCH}\` was just updated with the latest regenerated tests; the existing PR will reflect those changes automatically.
282295
283-
Details:
284-
- Source: [${SOURCE_LABEL}](${TS_REF_URL})
285-
- Branch: [\`${BRANCH}\`](${SERVER}/${REPO}/tree/${BRANCH})
286-
- Latest workflow run: ${RUN_URL}
296+
Details:
297+
- Source: [${SOURCE_LABEL}](${TS_REF_URL})
298+
- Branch: [\`${BRANCH}\`](${SERVER}/${REPO}/tree/${BRANCH})
299+
- Latest workflow run: ${RUN_URL}
287300
288-
${CC_LINE}"
301+
${CC_LINE}"
289302
else
290303
# Build a "compare" URL that opens the PR creation page pre-filled.
291304
# GitHub Actions cannot create PRs directly (org policy), so the
@@ -294,28 +307,28 @@ jobs:
294307
PR_TITLE_ENC=$(jq -rn --arg t "$TITLE" '$t|@uri')
295308
PR_BODY_RAW="Fixes ${ISSUE_LINK}
296309
297-
Source: ${TS_REF_URL}
310+
Source: ${TS_REF_URL}
298311
299-
Automated regeneration of TypeSpec Python generated tests from ${SOURCE_LABEL}.
312+
Automated regeneration of TypeSpec Python generated tests from ${SOURCE_LABEL}.
300313
301-
- Workflow run: ${RUN_URL}
314+
- Workflow run: ${RUN_URL}
302315
303-
This PR was auto-generated."
316+
This PR was auto-generated."
304317
PR_BODY_ENC=$(jq -rn --arg b "$PR_BODY_RAW" '$b|@uri')
305318
COMPARE_URL="${SERVER}/${REPO}/compare/main...${BRANCH}?quick_pull=1&title=${PR_TITLE_ENC}&body=${PR_BODY_ENC}"
306319
307320
ISSUE_BODY="GitHub Actions is not permitted to create pull requests in this repository, so this issue tracks the regeneration instead.
308321
309-
**Click the link below to open a pre-filled PR:**
322+
**Click the link below to open a pre-filled PR:**
310323
311-
👉 [Create pull request from \`${BRANCH}\`](${COMPARE_URL})
324+
👉 [Create pull request from \`${BRANCH}\`](${COMPARE_URL})
312325
313-
Details:
314-
- Source: [${SOURCE_LABEL}](${TS_REF_URL})
315-
- Branch: [\`${BRANCH}\`](${SERVER}/${REPO}/tree/${BRANCH})
316-
- Latest workflow run: ${RUN_URL}
326+
Details:
327+
- Source: [${SOURCE_LABEL}](${TS_REF_URL})
328+
- Branch: [\`${BRANCH}\`](${SERVER}/${REPO}/tree/${BRANCH})
329+
- Latest workflow run: ${RUN_URL}
317330
318-
${CC_LINE}"
331+
${CC_LINE}"
319332
fi
320333
321334
# Write the final body onto the tracking issue (whether reused or

eng/tools/emitter/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ The [`typespec-python-regenerate`](../../../.github/workflows/typespec-python-re
3838
- `[typespec-python] Regenerate tests from microsoft/typespec@main`
3939
- `[typespec-python] Regenerate tests from microsoft/typespec PR #<N>`
4040
- **Body** behavior:
41-
- If no open PR exists from the branch to `main`, the body contains a prefilled compare URL ("Create pull request from `<branch>`") that opens a PR with the title and body already populated.
41+
- If no open PR exists from the branch to `main`, the body contains a prefilled compare URL ("Create pull request from `<branch>`") that opens a PR with the title and body already populated. The prefilled PR body starts with `Fixes <issue URL>` so the tracking issue is closed automatically when the PR is merged.
4242
- If an open PR already exists from the branch to `main`, the body links directly to that PR and notes that the existing PR has been updated with the new commit (a force-push does not close the PR).
4343
- **Assignees / cc**:
4444
- Manual (`workflow_dispatch`) runs are assigned to the user who triggered the run (`github.actor`).
4545
- Automatic (`push`) runs are assigned to the default maintainers (`@iscai-msft`, `@msyyc`).
4646

47+
> **Note:** The auto branch is **force-pushed** on every run. If a reviewer has the compare link open and no PR has been created yet, the diff under that link will change when the next run pushes — they should reopen the link from the tracking issue to see the latest diff. If a PR already exists, the force-push updates the PR in place (it does not close it; review comments on lines that no longer exist become "outdated").
48+
4749

4850
### Failure notifications
4951

0 commit comments

Comments
 (0)