Bot PR Auto-Merge #32
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: Bot PR Auto-Merge | |
| on: | |
| pull_request_target: | |
| types: [opened, reopened, synchronize, ready_for_review, closed] | |
| schedule: | |
| - cron: '17 * * * *' | |
| workflow_dispatch: | |
| permissions: | |
| actions: write | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: bot-pr-auto-merge-${{ github.event.pull_request.number || github.run_id }} | |
| cancel-in-progress: false | |
| jobs: | |
| enable-current-pr: | |
| name: enable-current-pr | |
| if: >- | |
| github.event_name == 'pull_request_target' && | |
| github.event.action != 'closed' && | |
| github.event.pull_request.draft == false && | |
| github.event.pull_request.base.ref == github.event.repository.default_branch && | |
| github.event.pull_request.head.repo.full_name == github.repository && | |
| (github.event.pull_request.user.login == 'dependabot[bot]' || | |
| github.event.pull_request.user.login == 'github-advanced-security[bot]') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Enable squash auto-merge | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| run: gh pr merge "$PR_NUMBER" --repo "$GH_REPO" --auto --squash | |
| dispatch-after-merge: | |
| name: dispatch-after-merge | |
| if: >- | |
| github.event_name == 'pull_request_target' && | |
| github.event.action == 'closed' && | |
| github.event.pull_request.merged == true && | |
| github.event.pull_request.base.ref == github.event.repository.default_branch && | |
| github.event.pull_request.head.repo.full_name == github.repository && | |
| (github.event.pull_request.user.login == 'dependabot[bot]' || | |
| github.event.pull_request.user.login == 'github-advanced-security[bot]') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Dispatch main CI and release workflows | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| run: | | |
| gh workflow run ci.yml --repo "$GH_REPO" --ref "$DEFAULT_BRANCH" | |
| gh workflow run docker-build-release.yml --repo "$GH_REPO" --ref "$DEFAULT_BRANCH" | |
| reconcile-open-prs: | |
| name: reconcile-open-prs | |
| if: github.event_name != 'pull_request_target' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Enable squash auto-merge for every eligible bot PR | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| GH_REPO: ${{ github.repository }} | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| shell: bash | |
| run: | | |
| gh api --paginate "repos/$GH_REPO/pulls?state=open&base=$DEFAULT_BRANCH&per_page=100" \ | |
| --jq '.[] | |
| | select(.draft == false) | |
| | select(.head.repo.full_name == env.GH_REPO) | |
| | select(.user.login == "dependabot[bot]" or .user.login == "github-advanced-security[bot]") | |
| | .number' | | |
| while read -r pr_number; do | |
| gh pr merge "$pr_number" --repo "$GH_REPO" --auto --squash | |
| done |