|
| 1 | +# Auto-merge dependency updates for repositories WITHOUT branch protection |
| 2 | +# Uses direct merge since --auto flag requires branch protection |
| 3 | +name: Auto-merge dependency PRs |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request_target: |
| 7 | + types: [opened, synchronize, reopened] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + auto-merge: |
| 15 | + name: Auto-merge dependency PRs |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.actor == 'dependabot[bot]' || github.actor == 'renovate[bot]' |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Harden Runner |
| 21 | + uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4089b9f0 # v2.12.0 |
| 22 | + with: |
| 23 | + egress-policy: audit |
| 24 | + |
| 25 | + - name: Dependabot metadata |
| 26 | + id: metadata |
| 27 | + if: github.actor == 'dependabot[bot]' |
| 28 | + uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b # v2.4.0 |
| 29 | + with: |
| 30 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 31 | + |
| 32 | + - name: Auto-approve PR |
| 33 | + run: gh pr review --approve "$PR_URL" |
| 34 | + env: |
| 35 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 36 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Wait for CI checks |
| 39 | + run: | |
| 40 | + echo "Waiting for CI checks to complete..." |
| 41 | + for i in {1..60}; do |
| 42 | + CHECKS=$(gh pr checks "$PR_URL" --json name,state \ |
| 43 | + --jq '[.[] | select(.name != "Auto-merge dependency PRs")]') |
| 44 | + |
| 45 | + FAILED=$(echo "$CHECKS" | jq '[.[] | select(.state == "FAILURE" or .state == "ERROR")] | length') |
| 46 | + PENDING=$(echo "$CHECKS" | jq '[.[] | select(.state == "PENDING" or .state == "QUEUED" or .state == "IN_PROGRESS")] | length') |
| 47 | + |
| 48 | + if [ "$FAILED" != "0" ]; then |
| 49 | + echo "Some checks failed, skipping merge" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | + if [ "$PENDING" = "0" ]; then |
| 54 | + echo "All checks passed!" |
| 55 | + exit 0 |
| 56 | + fi |
| 57 | + |
| 58 | + echo "Waiting for $PENDING check(s)... (attempt $i/60)" |
| 59 | + sleep 10 |
| 60 | + done |
| 61 | + echo "Timeout waiting for checks" |
| 62 | + exit 1 |
| 63 | + env: |
| 64 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 65 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + |
| 67 | + - name: Merge PR |
| 68 | + run: gh pr merge --merge "$PR_URL" |
| 69 | + env: |
| 70 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 71 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments