Skip to content

Updated GitHub actions for auto-merging PRs #6

Updated GitHub actions for auto-merging PRs

Updated GitHub actions for auto-merging PRs #6

Workflow file for this run

name: Auto Merge PRs
on:
pull_request:
types: [opened, reopened, synchronize]
permissions:
pull-requests: write
contents: write
jobs:
automerge:
name: Auto Merge PR
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Check PR author role
id: check_author
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
AUTHOR="${{ github.event.pull_request.user.login }}"
REPO="${{ github.repository }}"
PERMISSION=$(gh api repos/$REPO/collaborators/$AUTHOR/permission --jq '.permission')
echo "PR author: $AUTHOR, permission: $PERMISSION"
# Only allow if admin or maintain
if [[ "$PERMISSION" != "admin" ]]; then
echo "Author is not admin. Exiting."
exit 1
fi
- name: Check if PR is draft
if: ${{ github.event.pull_request.draft == true }}
run: |
echo "PR is a draft. Exiting."
exit 1
- name: Enable auto-merge
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: merge