Skip to content

Commit 053e9fe

Browse files
authored
ci: start Dependabot CI after GITHUB_TOKEN rebase (#1527)
## Summary Start required CI and restore last-push approval after the hourly Dependabot rebase job rewrites a branch with `GITHUB_TOKEN`. ## Problem `rebase-dependabot.yml` pushes with `GITHUB_TOKEN` on purpose so `require_last_push_approval` can still be satisfied by the App (the App must not be the last pusher). That push leaves `pull_request` runs for CI, Security, and Auto-approve at `action_required` with zero jobs. Required check `ci` never reports, so auto-merge stays `BLOCKED`. That is what stalled #1522, #1524, and #1525 after they were already approved and armed. ## Change After the rebase loop, use the existing auto-approve App token to: 1. Approve those stub workflow runs (same path as `scripts/start-cleanup-pr-ci.sh`) 2. Re-approve the PR (App is not last pusher) 3. Re-arm squash auto-merge on PRs that already have auto-merge enabled Majors without auto-merge stay untouched. ## Validation - YAML parses - Workflow-sanity / actionlint on this PR - Manual unstick of #1522 / #1524 / #1525 used a human rebase plus approve, which is the same last-pusher split this job now automates Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca>
1 parent 4720301 commit 053e9fe

1 file changed

Lines changed: 68 additions & 1 deletion

File tree

.github/workflows/rebase-dependabot.yml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ name: Rebase Dependabot
55
# Replay each behind branch onto origin/main. Do not comment
66
# @dependabot rebase: github-actions[bot] and the auto-approve App are
77
# both rejected ("only users with push access", #1508 / #1509).
8+
#
9+
# Push the rebase with GITHUB_TOKEN (not the App). require_last_push_approval
10+
# dismisses the last pusher's review. If the App pushed, it could not approve
11+
# (#1520). That GITHUB_TOKEN push leaves CI/Security/Auto-approve at
12+
# action_required with zero jobs (#1516 / #1522). The following step uses
13+
# the App token to approve those stubs and re-approve the PR.
814

915
on:
1016
push:
@@ -26,7 +32,7 @@ jobs:
2632
timeout-minutes: 10
2733
permissions:
2834
contents: write
29-
pull-requests: read
35+
pull-requests: write
3036
steps:
3137
- name: Harden runner
3238
uses: step-security/harden-runner@05e31511f85b41b11d1cf0ef85d0992719546e2c # v2.21.0
@@ -38,6 +44,19 @@ jobs:
3844
fetch-depth: 0
3945
persist-credentials: false
4046

47+
# App is not last pusher (rebase uses GITHUB_TOKEN). That is required
48+
# so this token can approve the PR under require_last_push_approval
49+
# and start action_required stub runs (#1516 / #1522).
50+
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
51+
id: app-token
52+
continue-on-error: true
53+
with:
54+
client-id: ${{ vars.AUTO_APPROVE_CLIENT_ID }}
55+
private-key: ${{ secrets.AUTO_APPROVE_PRIVATE_KEY }}
56+
permission-contents: write
57+
permission-pull-requests: write
58+
permission-workflows: write
59+
4160
- name: Rebase Dependabot PRs that are behind main
4261
env:
4362
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -85,3 +104,51 @@ jobs:
85104
"${remote_url}" "HEAD:refs/heads/${branch}"
86105
fi
87106
done
107+
108+
- name: Start CI and re-approve after GITHUB_TOKEN rebase
109+
if: steps.app-token.outputs.token != ''
110+
env:
111+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
112+
REPO: ${{ github.repository }}
113+
run: |
114+
set -euo pipefail
115+
# GITHUB_TOKEN rebase leaves pull_request runs at action_required
116+
# with zero jobs. User tokens 404 on run-approve; App token works
117+
# (start-cleanup-pr-ci.sh). App is not last pusher, so it can also
118+
# satisfy require_last_push_approval. Only touch PRs that already
119+
# have auto-merge armed (skip unreviewed majors).
120+
echo "PLAN: unstick Dependabot PRs with action_required stubs"
121+
for _try in 1 2 3 4 5; do
122+
found=0
123+
nums=$(gh pr list --repo "${REPO}" --author "app/dependabot" \
124+
--state open --json number,autoMergeRequest \
125+
--jq '.[] | select(.autoMergeRequest != null) | .number')
126+
for n in ${nums}; do
127+
branch=$(gh pr view "${n}" --repo "${REPO}" --json headRefName \
128+
--jq .headRefName)
129+
ids=$(gh run list --repo "${REPO}" --branch "${branch}" --limit 15 \
130+
--json databaseId,conclusion \
131+
--jq '.[] | select(.conclusion == "action_required") | .databaseId')
132+
if [ -z "${ids}" ]; then
133+
continue
134+
fi
135+
found=1
136+
echo "DO: approve stubs on #${n}"
137+
while read -r id; do
138+
[ -z "${id}" ] && continue
139+
gh api -X POST "repos/${REPO}/actions/runs/${id}/approve" \
140+
>/dev/null && echo "OK: approved run ${id}" \
141+
|| echo "FAIL: approve ${id} (continuing)"
142+
done <<<"${ids}"
143+
gh pr review --approve "${n}" --repo "${REPO}" \
144+
|| echo "Approve #${n} failed or already approved"
145+
gh pr merge --auto --squash "${n}" --repo "${REPO}" \
146+
|| echo "auto-merge already armed or blocked on #${n}"
147+
done
148+
if [ "${found}" -eq 0 ]; then
149+
echo "OK: no action_required Dependabot stubs"
150+
break
151+
fi
152+
sleep 4
153+
done
154+
echo "DONE: Dependabot unstick pass"

0 commit comments

Comments
 (0)