Dependabot auto-merge #49
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: Dependabot auto-merge | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| automerge: | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request' && | |
| startsWith(github.event.workflow_run.head_branch, 'dependabot/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Squash-merge Dependabot PR after CI | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| REPOSITORY: ${{ github.repository }} | |
| run: | | |
| set -euo pipefail | |
| pr_number=$(gh pr list --repo "${REPOSITORY}" --head "${HEAD_BRANCH}" --state open --json number -q '.[0].number') | |
| if [ -z "${pr_number}" ] || [ "${pr_number}" = "null" ]; then | |
| echo "No open PR for branch ${HEAD_BRANCH}." | |
| exit 0 | |
| fi | |
| author=$(gh pr view "${pr_number}" --repo "${REPOSITORY}" --json author -q '.author.login') | |
| if [ "${author}" != "app/dependabot" ]; then | |
| echo "Skipping non-Dependabot PR #${pr_number}." | |
| exit 0 | |
| fi | |
| gh pr merge "${pr_number}" --repo "${REPOSITORY}" --squash | |
| echo "Merged PR #${pr_number}." |