Skip to content

Commit 3b5d9ae

Browse files
committed
ci: only rebase-merge sibling-update PRs once all CI checks pass
1 parent 3e3a188 commit 3b5d9ae

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

.github/workflows/sibling-dependency-update.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
bump-and-open-pr:
1818
if: github.event_name == 'repository_dispatch'
1919
runs-on: ubuntu-latest
20-
timeout-minutes: 10
20+
timeout-minutes: 35
2121
steps:
2222
- uses: actions/checkout@v7
2323
- uses: pnpm/action-setup@v6
@@ -65,25 +65,30 @@ jobs:
6565
pr_url=$(gh pr create --title "build(deps): bump ${PACKAGE} to ${VERSION}" --body "Automatic dependency bump triggered instantly by the ${PACKAGE} release." --base main --head "$branch")
6666
echo "pr_url=$pr_url" >> "$GITHUB_OUTPUT"
6767
echo "head_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
68-
- name: Wait for this repo own real CI to register on the PR
68+
- name: Wait for all CI checks to pass, then rebase-merge
6969
if: steps.diff.outputs.changed == 'true'
7070
env:
7171
GH_TOKEN: ${{ steps.app-token.outputs.token }}
7272
run: |
73-
for i in $(seq 1 30); do
74-
found=$(gh api "repos/${{ github.repository }}/commits/${{ steps.pr.outputs.head_sha }}/check-runs" --jq '[.check_runs[] | select(.name == "Test")] | length')
75-
if [ "$found" -gt 0 ]; then
76-
echo "ci.yml own Test check has registered after $((i * 3))s"
73+
pr_url="${{ steps.pr.outputs.pr_url }}"
74+
head_sha="${{ steps.pr.outputs.head_sha }}"
75+
repo="${{ github.repository }}"
76+
for i in $(seq 1 90); do
77+
pending=$(gh api "repos/${repo}/commits/${head_sha}/check-runs" --paginate --jq '[.check_runs[] | select(.conclusion == null)] | length')
78+
if [ "$pending" -eq 0 ]; then
79+
failed=$(gh api "repos/${repo}/commits/${head_sha}/check-runs" --paginate --jq '[.check_runs[] | select(.conclusion != "success" and .conclusion != "skipped")] | length')
80+
if [ "$failed" -gt 0 ]; then
81+
echo "::error::CI checks failed on this sibling-update PR. Leaving it open for manual review."
82+
exit 1
83+
fi
84+
echo "All CI checks passed. Rebase-merging."
85+
gh pr merge --rebase "$pr_url"
7786
exit 0
7887
fi
79-
sleep 3
88+
echo "Waiting for ${pending} CI check(s) to complete..."
89+
sleep 20
8090
done
81-
echo "::warning::ci.yml own Test check never registered after 90s -- proceeding anyway, but auto-merge may reject the PR as already clean or merge it immediately" >&2
82-
- name: Enable auto-merge
83-
if: steps.diff.outputs.changed == 'true'
84-
env:
85-
GH_TOKEN: ${{ steps.app-token.outputs.token }}
86-
run: gh pr merge --auto --rebase "${{ steps.pr.outputs.pr_url }}"
91+
echo "::warning::CI did not complete within 30 minutes. PR left open for manual merge." >&2
8792
8893
heal-stranded-prs:
8994
# gh pr merge --auto above only ever fires once, right after a PR opens. If enough other commits land on main before this repo's own CI finishes on that PR, the PR's branch falls behind and GitHub marks it CONFLICTING -- and a conflicting PR can never auto-merge, no matter how green its own CI is, with nothing to ever retry it. This job runs on every push to main (the only time a previously-clean PR can newly become conflicting) and regenerates any bump PR this same workflow opened that is now stuck: closes the stale PR/branch and re-runs the identical bump against the new main, rather than attempting a real git rebase -- a plain `pnpm add <package>@<version>` is fully idempotent and deterministic, so there is no conflict to resolve, only a fresh diff to produce.

0 commit comments

Comments
 (0)