Skip to content

Commit d3fd2e4

Browse files
authored
fix: auto-retest workflow to support all branches (#4244)
## Summary Update the auto-retest workflow to trigger on PR merges to **any** branch, not just `main`. ## Changes - Remove `branches: [main]` filter — workflow now triggers on merges to all branches - Use `${{ github.event.pull_request.base.ref }}` for dynamic branch targeting in: - Concurrency group (per-branch isolation) - `gh pr list --base` (check PRs targeting the same branch) - Fix `SKIP_LABELS` detection — replace fragile `grep` pipe with robust `jq` expression: - Handles null/missing labels safely (`// []`) - Case-insensitive matching entirely in jq - No longer silently swallows `gh` CLI errors - Properly quotes `$PR_NUM` ## Before / After | Aspect | Before | After | |--------|--------|-------| | Branches | `main` only | All branches | | Concurrency | `auto-retest-main` | `auto-retest-<branch>` | | Label check | `gh ... \| grep \|\| true` | Single jq expression | | Error handling | `gh` failures silently swallowed | `gh` failures visible | ## Test plan - [x] Tested jq expression on PRs with skip labels (wip, has-conflicts) — correctly detected - [x] Tested on PRs without skip labels — returned empty string - [x] Tested edge cases (no labels, null labels) — handled safely <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * CI/CD workflow now detects and respects each pull request’s base branch instead of using a single hardcoded branch. * Open-PR selection and related steps were updated to operate against the detected base branch. * Skip-label detection and logging were simplified for more reliable, efficient workflow behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 59014fb commit d3fd2e4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

.github/workflows/auto-retest-needs-rebase.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ name: Auto-retest PRs after merge
33
on:
44
pull_request_target:
55
types: [closed]
6-
branches: [main]
76

87
permissions:
98
pull-requests: write
109
contents: read
1110

1211
concurrency:
13-
group: auto-retest-main
12+
group: auto-retest-${{ github.event.pull_request.base.ref }}
1413
cancel-in-progress: false
1514

1615
jobs:
@@ -28,6 +27,7 @@ jobs:
2827
id: merged-files
2928
env:
3029
GH_TOKEN: ${{ secrets.BOT3_TOKEN }}
30+
BASE_REF: ${{ github.event.pull_request.base.ref }}
3131
run: |
3232
set -euo pipefail
3333
@@ -53,25 +53,26 @@ jobs:
5353
shell: bash
5454
env:
5555
GH_TOKEN: ${{ secrets.BOT3_TOKEN }}
56+
BASE_REF: ${{ github.event.pull_request.base.ref }}
5657
run: |
5758
set -euo pipefail
5859
59-
# Get all open PRs with main as base branch (excluding drafts)
60-
OPEN_PRS=$(gh pr list --base main --state open --limit 100 --json number,isDraft --jq '.[] | select(.isDraft == false) | .number')
60+
# Get all open PRs targeting the same base branch (excluding drafts)
61+
OPEN_PRS=$(gh pr list --base "$BASE_REF" --state open --limit 100 --json number,isDraft --jq '.[] | select(.isDraft == false) | .number')
6162
6263
if [ -z "$OPEN_PRS" ]; then
63-
echo "No open PRs targeting main branch"
64+
echo "No open PRs targeting $BASE_REF branch"
6465
exit 0
6566
fi
6667
67-
echo "Open PRs targeting main: $OPEN_PRS"
68+
echo "Open PRs targeting $BASE_REF: $OPEN_PRS"
6869
6970
for PR_NUM in $OPEN_PRS; do
7071
echo "================================================"
7172
echo "Checking PR #$PR_NUM"
7273
7374
# Check if PR has has-conflict, hold, wip, or stale labels
74-
SKIP_LABELS=$(gh pr view $PR_NUM --json labels --jq '.labels[].name' | grep -iE "^(has-conflicts|hold|wip|stale)$" || true)
75+
SKIP_LABELS=$(gh pr view "$PR_NUM" --json labels --jq '[.labels // [] | .[].name | select(test("(?i)^(has-conflicts|hold|wip|stale)$"))] | join(",")')
7576
7677
if [ -n "$SKIP_LABELS" ]; then
7778
echo "PR #$PR_NUM has skip label(s): $SKIP_LABELS, skipping retest"

0 commit comments

Comments
 (0)