|
20 | 20 | - if: "!contains(steps.dependabot-metadata.outputs.package-ecosystem, 'npm') && (steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch')" |
21 | 21 | id: check_if_allowed_dependency |
22 | 22 | run: echo "is_allowed_dependency=1" >> "$GITHUB_OUTPUT" |
| 23 | + wait_for_checks: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + needs: [ validate_dependabot_opened_this_PR, validate_this_is_an_allowed_dependency ] |
| 26 | + steps: |
| 27 | + - name: Wait for required checks to pass |
| 28 | + env: |
| 29 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + REPO: ${{ github.repository }} |
| 31 | + SHA: ${{ github.event.pull_request.head.sha }} |
| 32 | + run: | |
| 33 | + echo "Waiting for all required checks to pass on commit $SHA..." |
| 34 | +
|
| 35 | + MAX_RETRIES=30 |
| 36 | + RETRY_DELAY=10 |
| 37 | + ATTEMPT=0 |
| 38 | +
|
| 39 | + while [ $ATTEMPT -lt $MAX_RETRIES ]; do |
| 40 | + echo "Attempt $((ATTEMPT+1))/$MAX_RETRIES" |
| 41 | +
|
| 42 | + # Get all check runs for the commit |
| 43 | + RESPONSE=$(curl -s -H "Authorization: token $GH_TOKEN" \ |
| 44 | + "https://api.github.com/repos/$REPO/commits/$SHA/check-runs") |
| 45 | +
|
| 46 | + # Exclude self (wait_for_checks) |
| 47 | + EXCLUDED_CHECK="wait_for_checks" |
| 48 | +
|
| 49 | + echo "Ignoring ${EXCLUDED_CHECK}" |
| 50 | +
|
| 51 | + # Extract conclusions |
| 52 | + CONCLUSIONS=$(echo "$RESPONSE" | jq -r '.check_runs[] | select(.name != "wait_for_checks") | .name + ":" + (.status + "/" + (.conclusion // "none"))') |
| 53 | +
|
| 54 | + echo "$CONCLUSIONS" |
| 55 | +
|
| 56 | + # Are there any in_progress or queued? |
| 57 | + PENDING=$(echo "$RESPONSE" | jq -r --arg exclude "$EXCLUDED_CHECK" '[.check_runs[] | select(.name != $exclude and .status != "completed")] | length') |
| 58 | +
|
| 59 | + # Are all completed and successful? |
| 60 | + FAILED=$(echo "$RESPONSE" | jq -r --arg exclude "$EXCLUDED_CHECK" '[.check_runs[] | select(.name != $exclude and .status == "completed" and .conclusion != "success")] | length') |
| 61 | +
|
| 62 | + if [ "$PENDING" -eq 0 ] && [ "$FAILED" -eq 0 ]; then |
| 63 | + echo "All checks completed successfully." |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | +
|
| 67 | + if [ "$FAILED" -gt 0 ]; then |
| 68 | + echo "One or more checks failed." |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + echo "Some checks still pending. Waiting $RETRY_DELAY seconds..." |
| 73 | + sleep $RETRY_DELAY |
| 74 | + ATTEMPT=$((ATTEMPT + 1)) |
| 75 | + done |
| 76 | +
|
| 77 | + echo "Timed out waiting for checks to complete." |
| 78 | + exit 1 |
23 | 79 | auto_approve_and_merge: |
24 | 80 | runs-on: ubuntu-latest |
25 | | - needs: [validate_dependabot_opened_this_PR, validate_this_is_an_allowed_dependency] |
| 81 | + needs: [validate_dependabot_opened_this_PR, validate_this_is_an_allowed_dependency, wait_for_checks] |
26 | 82 | if: ${{ needs.validate_this_is_an_allowed_dependency.outputs.is_allowed_dependency == 1 }} |
27 | 83 | steps: |
28 | 84 | - uses: actions/checkout@v4 |
|
0 commit comments