|
| 1 | +name: Auto-merge bot PRs |
| 2 | + |
| 3 | +on: |
| 4 | + # Use pull_request_target because PRs created by GitHub Apps |
| 5 | + # do NOT trigger pull_request events (to prevent infinite loops). |
| 6 | + # pull_request_target always fires and runs in the base branch context. |
| 7 | + pull_request_target: |
| 8 | + types: [ opened, synchronize ] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + # Auto-merge trustify-ci-bot PRs that only change the OpenAPI spec |
| 16 | + auto-merge-openapi: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: github.actor == 'trustify-ci-bot[bot]' |
| 19 | + steps: |
| 20 | + - name: Check changed files |
| 21 | + id: check-files |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ github.token }} |
| 24 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 25 | + run: | |
| 26 | + files=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" \ |
| 27 | + --json files --jq '.files[].path') |
| 28 | +
|
| 29 | + if [ "$files" != "client/openapi/trustd.yaml" ]; then |
| 30 | + echo "::notice::PR changes files beyond client/openapi/trustd.yaml — manual review required" |
| 31 | + echo "$files" |
| 32 | + echo "auto_merge=false" >> "$GITHUB_OUTPUT" |
| 33 | + exit 0 |
| 34 | + fi |
| 35 | +
|
| 36 | + echo "Only client/openapi/trustd.yaml changed." |
| 37 | + echo "auto_merge=true" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + - name: Approve PR |
| 40 | + if: steps.check-files.outputs.auto_merge == 'true' |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ secrets.BOT_APPROVE_TOKEN }} |
| 43 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 44 | + run: | |
| 45 | + gh pr review "$PR_NUMBER" --repo "${{ github.repository }}" --approve \ |
| 46 | + --body "Auto-approved: only client/openapi/trustd.yaml changed." |
| 47 | +
|
| 48 | + - name: Enable auto-merge |
| 49 | + if: steps.check-files.outputs.auto_merge == 'true' |
| 50 | + env: |
| 51 | + GH_TOKEN: ${{ github.token }} |
| 52 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 53 | + run: | |
| 54 | + gh pr merge "$PR_NUMBER" --repo "${{ github.repository }}" --auto --squash |
| 55 | +
|
| 56 | + # Auto-merge Dependabot PRs for patch and minor updates |
| 57 | + auto-merge-dependabot: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + if: github.actor == 'dependabot[bot]' |
| 60 | + steps: |
| 61 | + - name: Fetch Dependabot metadata |
| 62 | + id: metadata |
| 63 | + uses: dependabot/fetch-metadata@v2 |
| 64 | + with: |
| 65 | + github-token: ${{ github.token }} |
| 66 | + |
| 67 | + - name: Approve PR (patch and minor only) |
| 68 | + if: steps.metadata.outputs.update-type != 'version-update:semver-major' |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ secrets.BOT_APPROVE_TOKEN }} |
| 71 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 72 | + run: | |
| 73 | + gh pr review "$PR_NUMBER" --repo "${{ github.repository }}" --approve \ |
| 74 | + --body "Auto-approved: Dependabot ${{ steps.metadata.outputs.update-type }}" |
| 75 | +
|
| 76 | + - name: Enable auto-merge (patch and minor only) |
| 77 | + if: steps.metadata.outputs.update-type != 'version-update:semver-major' |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ github.token }} |
| 80 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 81 | + run: | |
| 82 | + gh pr merge "$PR_NUMBER" --repo "${{ github.repository }}" --auto --squash |
0 commit comments