Merge Verified Automation Pull Requests #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Merge Verified Automation Pull Requests | |
| on: | |
| workflow_run: | |
| workflows: [Build Hugo Site] | |
| types: [completed] | |
| permissions: | |
| contents: read | |
| jobs: | |
| merge: | |
| if: >- | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.head_repository.full_name == github.repository && | |
| (github.event.workflow_run.head_branch == 'automation/update-community-stats' || | |
| github.event.workflow_run.head_branch == 'automation/sync-meetup-events' || | |
| github.event.workflow_run.head_branch == 'automation/sync-podcast') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| client-id: ${{ vars.AUTOMATION_APP_CLIENT_ID }} | |
| private-key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }} | |
| - name: Merge the verified automation pull request | |
| env: | |
| APP_SLUG: ${{ steps.app-token.outputs.app-slug }} | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | |
| run: | | |
| pull_request=$(gh pr view "$HEAD_BRANCH" --repo "$GITHUB_REPOSITORY" --json number,headRefOid,author,baseRefName,state) | |
| test "$(jq -r '.author.login' <<<"$pull_request")" = "${APP_SLUG}[bot]" | |
| test "$(jq -r '.baseRefName' <<<"$pull_request")" = main | |
| test "$(jq -r '.state' <<<"$pull_request")" = OPEN | |
| test "$(jq -r '.headRefOid' <<<"$pull_request")" = "$HEAD_SHA" | |
| gh pr merge "$(jq -r '.number' <<<"$pull_request")" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --squash \ | |
| --delete-branch \ | |
| --match-head-commit "$HEAD_SHA" |