Skip to content

Commit 77be865

Browse files
committed
dependabot automerge when checks passed
1 parent 18bd626 commit 77be865

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

.github/workflows/_update_dependencies.yml

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ jobs:
122122
needs: [update-lockfile, pre-flight]
123123
runs-on: ubuntu-latest
124124
environment: main
125+
outputs:
126+
pr-number: ${{ steps.create-pull-request.outputs.pull-request-number }}
125127
env:
126128
SOURCE_BRANCH: ${{ needs.pre-flight.outputs.bump-branch }}
127129
TARGET_BRANCH: ${{ inputs.target-branch }}
@@ -161,9 +163,79 @@ jobs:
161163
body: |
162164
🚀 PR to bump `uv.lock` in `${{ inputs.target-branch }}`.
163165
164-
📝 Please remember the following to-do's before merge:
165-
- [ ] Verify the presubmit CI
166+
📝 This PR will be automatically merged if all CI checks pass successfully.
167+
If any CI checks fail, the PR will remain open for manual review.
166168
167-
🙏 Please merge this PR only if the CI workflow completed successfully.
169+
🤖 **Auto-merge enabled** - No manual action required if CI passes.
168170
commit-message: ${{ env.title }}
169171
signoff: true
172+
173+
auto-merge:
174+
needs: [create-pr, pre-flight]
175+
runs-on: ubuntu-latest
176+
if: needs.create-pr.outputs.pr-number != ''
177+
env:
178+
PR_NUMBER: ${{ needs.create-pr.outputs.pr-number }}
179+
TARGET_BRANCH: ${{ inputs.target-branch }}
180+
GH_TOKEN: ${{ secrets.PAT }}
181+
steps:
182+
- name: Checkout code
183+
uses: actions/checkout@v4
184+
with:
185+
token: ${{ secrets.PAT }}
186+
187+
- name: Wait for CI checks and auto-merge
188+
run: |
189+
echo "Monitoring PR #${PR_NUMBER} for CI check completion..."
190+
191+
MAX_ATTEMPTS=144 # Wait up to 12 hours (144 attempts * 5 minutes)
192+
ATTEMPT=0
193+
194+
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
195+
ATTEMPT=$((ATTEMPT + 1))
196+
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Checking CI status..."
197+
198+
# Get PR status checks
199+
STATUS_JSON=$(gh pr view ${PR_NUMBER} --json statusCheckRollup)
200+
201+
# Count total checks, successful checks, and failed checks
202+
TOTAL_CHECKS=$(echo "$STATUS_JSON" | jq '.statusCheckRollup | length')
203+
204+
if [ "$TOTAL_CHECKS" -eq 0 ]; then
205+
echo "No status checks found yet. Waiting..."
206+
sleep 300
207+
continue
208+
fi
209+
210+
PENDING_CHECKS=$(echo "$STATUS_JSON" | jq '[.statusCheckRollup[] | select(.conclusion == null or .conclusion == "" or .status == "IN_PROGRESS" or .status == "PENDING" or .status == "QUEUED")] | length')
211+
FAILED_CHECKS=$(echo "$STATUS_JSON" | jq '[.statusCheckRollup[] | select(.conclusion == "FAILURE" or .conclusion == "CANCELLED" or .conclusion == "TIMED_OUT")] | length')
212+
SUCCESS_CHECKS=$(echo "$STATUS_JSON" | jq '[.statusCheckRollup[] | select(.conclusion == "SUCCESS")] | length')
213+
214+
echo "Status: $SUCCESS_CHECKS successful, $FAILED_CHECKS failed, $PENDING_CHECKS pending (out of $TOTAL_CHECKS total)"
215+
216+
# If any checks failed, exit and leave PR open
217+
if [ "$FAILED_CHECKS" -gt 0 ]; then
218+
echo "❌ CI checks failed. Leaving PR open for manual review."
219+
echo "Failed checks:"
220+
echo "$STATUS_JSON" | jq -r '.statusCheckRollup[] | select(.conclusion == "FAILURE" or .conclusion == "CANCELLED" or .conclusion == "TIMED_OUT") | " - \(.name): \(.conclusion)"'
221+
exit 0
222+
fi
223+
224+
# If all checks are done and successful, merge
225+
if [ "$PENDING_CHECKS" -eq 0 ] && [ "$SUCCESS_CHECKS" -gt 0 ]; then
226+
echo "✅ All CI checks passed! Auto-merging PR #${PR_NUMBER}..."
227+
228+
# Merge the PR
229+
gh pr merge ${PR_NUMBER} --squash --auto --delete-branch
230+
231+
echo "✅ PR #${PR_NUMBER} has been merged successfully!"
232+
exit 0
233+
fi
234+
235+
# Still waiting for checks to complete
236+
echo "Waiting for pending checks to complete..."
237+
sleep 300
238+
done
239+
240+
echo "⏱️ Timeout reached. PR #${PR_NUMBER} will remain open for manual review."
241+
exit 0

0 commit comments

Comments
 (0)