|
| 1 | +name: Merge Verified Automation Pull Requests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: [Build Hugo Site] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + merge: |
| 13 | + if: >- |
| 14 | + github.event.workflow_run.conclusion == 'success' && |
| 15 | + github.event.workflow_run.event == 'pull_request' && |
| 16 | + github.event.workflow_run.head_repository.full_name == github.repository && |
| 17 | + (github.event.workflow_run.head_branch == 'automation/update-community-stats' || |
| 18 | + github.event.workflow_run.head_branch == 'automation/sync-meetup-events' || |
| 19 | + github.event.workflow_run.head_branch == 'automation/sync-podcast') |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Create GitHub App token |
| 23 | + id: app-token |
| 24 | + uses: actions/create-github-app-token@v3 |
| 25 | + with: |
| 26 | + client-id: ${{ vars.AUTOMATION_APP_CLIENT_ID }} |
| 27 | + private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }} |
| 28 | + |
| 29 | + - name: Merge the verified automation pull request |
| 30 | + env: |
| 31 | + APP_SLUG: ${{ steps.app-token.outputs.app-slug }} |
| 32 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 33 | + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} |
| 34 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 35 | + run: | |
| 36 | + pull_request=$(gh pr view "$HEAD_BRANCH" --repo "$GITHUB_REPOSITORY" --json number,headRefOid,author,baseRefName,state) |
| 37 | + test "$(jq -r '.author.login' <<<"$pull_request")" = "${APP_SLUG}[bot]" |
| 38 | + test "$(jq -r '.baseRefName' <<<"$pull_request")" = main |
| 39 | + test "$(jq -r '.state' <<<"$pull_request")" = OPEN |
| 40 | + test "$(jq -r '.headRefOid' <<<"$pull_request")" = "$HEAD_SHA" |
| 41 | + gh pr merge "$(jq -r '.number' <<<"$pull_request")" \ |
| 42 | + --repo "$GITHUB_REPOSITORY" \ |
| 43 | + --squash \ |
| 44 | + --delete-branch \ |
| 45 | + --match-head-commit "$HEAD_SHA" |
0 commit comments