Skip to content

Commit ed37175

Browse files
committed
dependabot automerge when checks passed
Signed-off-by: Pablo Garay <pagaray@nvidia.com>
1 parent d858650 commit ed37175

1 file changed

Lines changed: 75 additions & 3 deletions

File tree

.github/workflows/_update_dependencies.yml

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ jobs:
9797
needs: [update-lockfile, pre-flight]
9898
runs-on: ubuntu-latest
9999
environment: main
100+
outputs:
101+
pr-number: ${{ steps.create-pull-request.outputs.pull-request-number }}
100102
env:
101103
SOURCE_BRANCH: ${{ needs.pre-flight.outputs.bump-branch }}
102104
TARGET_BRANCH: ${{ inputs.target-branch }}
@@ -144,10 +146,80 @@ jobs:
144146
body: |
145147
🚀 PR to bump `uv.lock` in `${{ inputs.target-branch }}`.
146148
147-
📝 Please remember the following to-do's before merge:
148-
- [ ] Verify the presubmit CI
149+
📝 This PR will be automatically merged if all CI checks pass successfully.
150+
If any CI checks fail, the PR will remain open for manual review.
149151
150-
🙏 Please merge this PR only if the CI workflow completed successfully.
152+
🤖 **Auto-merge enabled** - No manual action required if CI passes.
151153
commit-message: ${{ env.title }}
152154
signoff: true
153155
committer: "${{ steps.gpg-action.outputs.name }} <${{ steps.gpg-action.outputs.email }}>"
156+
157+
auto-merge:
158+
needs: [create-pr, pre-flight]
159+
runs-on: ubuntu-latest
160+
if: needs.create-pr.outputs.pr-number != ''
161+
env:
162+
PR_NUMBER: ${{ needs.create-pr.outputs.pr-number }}
163+
TARGET_BRANCH: ${{ inputs.target-branch }}
164+
GH_TOKEN: ${{ secrets.PAT }}
165+
steps:
166+
- name: Checkout code
167+
uses: actions/checkout@v4
168+
with:
169+
token: ${{ secrets.PAT }}
170+
171+
- name: Wait for CI checks and auto-merge
172+
run: |
173+
echo "Monitoring PR #${PR_NUMBER} for CI check completion..."
174+
175+
MAX_ATTEMPTS=144 # Wait up to 12 hours (144 attempts * 5 minutes)
176+
ATTEMPT=0
177+
178+
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
179+
ATTEMPT=$((ATTEMPT + 1))
180+
echo "Attempt $ATTEMPT/$MAX_ATTEMPTS: Checking CI status..."
181+
182+
# Get PR status checks
183+
STATUS_JSON=$(gh pr view ${PR_NUMBER} --json statusCheckRollup)
184+
185+
# Count total checks, successful checks, and failed checks
186+
TOTAL_CHECKS=$(echo "$STATUS_JSON" | jq '.statusCheckRollup | length')
187+
188+
if [ "$TOTAL_CHECKS" -eq 0 ]; then
189+
echo "No status checks found yet. Waiting..."
190+
sleep 300
191+
continue
192+
fi
193+
194+
PENDING_CHECKS=$(echo "$STATUS_JSON" | jq '[.statusCheckRollup[] | select(.conclusion == null or .conclusion == "" or .status == "IN_PROGRESS" or .status == "PENDING" or .status == "QUEUED")] | length')
195+
FAILED_CHECKS=$(echo "$STATUS_JSON" | jq '[.statusCheckRollup[] | select(.conclusion == "FAILURE" or .conclusion == "CANCELLED" or .conclusion == "TIMED_OUT")] | length')
196+
SUCCESS_CHECKS=$(echo "$STATUS_JSON" | jq '[.statusCheckRollup[] | select(.conclusion == "SUCCESS")] | length')
197+
198+
echo "Status: $SUCCESS_CHECKS successful, $FAILED_CHECKS failed, $PENDING_CHECKS pending (out of $TOTAL_CHECKS total)"
199+
200+
# If any checks failed, exit and leave PR open
201+
if [ "$FAILED_CHECKS" -gt 0 ]; then
202+
echo "❌ CI checks failed. Leaving PR open for manual review."
203+
echo "Failed checks:"
204+
echo "$STATUS_JSON" | jq -r '.statusCheckRollup[] | select(.conclusion == "FAILURE" or .conclusion == "CANCELLED" or .conclusion == "TIMED_OUT") | " - \(.name): \(.conclusion)"'
205+
exit 0
206+
fi
207+
208+
# If all checks are done and successful, merge
209+
if [ "$PENDING_CHECKS" -eq 0 ] && [ "$SUCCESS_CHECKS" -gt 0 ]; then
210+
echo "✅ All CI checks passed! Auto-merging PR #${PR_NUMBER}..."
211+
212+
# Merge the PR
213+
gh pr merge ${PR_NUMBER} --squash --auto --delete-branch
214+
215+
echo "✅ PR #${PR_NUMBER} has been merged successfully!"
216+
exit 0
217+
fi
218+
219+
# Still waiting for checks to complete
220+
echo "Waiting for pending checks to complete..."
221+
sleep 300
222+
done
223+
224+
echo "⏱️ Timeout reached. PR #${PR_NUMBER} will remain open for manual review."
225+
exit 0

0 commit comments

Comments
 (0)