|
| 1 | +name: Approve Bot PRs and Enable Auto-Merge |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Test Pull Request"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + download: |
| 11 | + name: Download PR Artifact |
| 12 | + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + pr-author: ${{ steps.pr-data.outputs.author }} |
| 16 | + pr-number: ${{ steps.pr-data.outputs.number }} |
| 17 | + steps: |
| 18 | + - name: 'Download artifact' |
| 19 | + uses: paketo-buildpacks/github-config/actions/pull-request/download-artifact@main |
| 20 | + with: |
| 21 | + name: "event-payload" |
| 22 | + repo: ${{ github.repository }} |
| 23 | + run_id: ${{ github.event.workflow_run.id }} |
| 24 | + workspace: "/github/workspace" |
| 25 | + token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} |
| 26 | + - id: pr-data |
| 27 | + run: | |
| 28 | + echo "::set-output name=author::$(jq -r '.pull_request.user.login' < event.json)" |
| 29 | + echo "::set-output name=number::$(jq -r '.pull_request.number' < event.json)" |
| 30 | +
|
| 31 | + approve: |
| 32 | + name: Approve Bot PRs |
| 33 | + needs: download |
| 34 | + if: ${{ needs.download.outputs.pr-author == 'paketo-bot' || needs.download.outputs.pr-author == 'dependabot[bot]' }} |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - name: Check Commit Verification |
| 38 | + id: unverified-commits |
| 39 | + uses: paketo-buildpacks/github-config/actions/pull-request/check-unverified-commits@main |
| 40 | + with: |
| 41 | + token: ${{ secrets.PAKETO_BOT_REVIEWER_GITHUB_TOKEN }} |
| 42 | + repo: ${{ github.repository }} |
| 43 | + number: ${{ needs.download.outputs.pr-number }} |
| 44 | + |
| 45 | + - name: Check for Human Commits |
| 46 | + id: human-commits |
| 47 | + uses: paketo-buildpacks/github-config/actions/pull-request/check-human-commits@main |
| 48 | + with: |
| 49 | + token: ${{ secrets.PAKETO_BOT_REVIEWER_GITHUB_TOKEN }} |
| 50 | + repo: ${{ github.repository }} |
| 51 | + number: ${{ needs.download.outputs.pr-number }} |
| 52 | + |
| 53 | + - name: Checkout |
| 54 | + if: steps.human-commits.outputs.human_commits == 'false' && steps.unverified-commits.outputs.unverified_commits == 'false' |
| 55 | + uses: actions/checkout@v3 |
| 56 | + |
| 57 | + - name: Approve |
| 58 | + if: steps.human-commits.outputs.human_commits == 'false' && steps.unverified-commits.outputs.unverified_commits == 'false' |
| 59 | + uses: paketo-buildpacks/github-config/actions/pull-request/approve@main |
| 60 | + with: |
| 61 | + token: ${{ secrets.PAKETO_BOT_REVIEWER_GITHUB_TOKEN }} |
| 62 | + number: ${{ needs.download.outputs.pr-number }} |
| 63 | + |
| 64 | + - name: Enable Auto-Merge |
| 65 | + if: steps.human-commits.outputs.human_commits == 'false' && steps.unverified-commits.outputs.unverified_commits == 'false' |
| 66 | + run: | |
| 67 | + gh pr merge ${{ needs.download.outputs.pr-number }} --auto --rebase |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }} |
0 commit comments