Automerges PRs from code owners that only change owned files.
You want CODEOWNERS to be able to self-merge PRs to files they are "owners" of.
The code owners could be external users of a public repo, or collaborators added to a repo that has "Require a pull request before merging" enabled + "Require review from Code Owners".
This bot will check if all files changed in a given PR have the submitter as their codeowner, and if so the PR will be merged automatically.
Note that if you have branch rules, you will need to give the bot a admin token in order to be able to bypass rules:
- GITHUB_TOKEN = ${{ secrets.GITHUB_TOKEN }}
+ GITHUB_TOKEN = ${{ secrets.AUTOMERGE_TOKEN }}
Note
The bot will use as source of truth the CODEOWNERS file at the latest commmit of the default branch. In other words a PR that modifies CODEOWNERS will not be able to hijack the bot.
- Setup CODEOWNERS and restrict user's write access to the repo as needed.
- Add a workflow that uses this Action. If you have other jobs, you might want to have the automerge job depend on their success.
Example workflow:
name: Codeowners Automerge
on:
pull_request_target: { types: [opened, synchronize] }
jobs:
codeowners-automerge:
runs-on: ubuntu-latest
# needs: [other-check1, other-check2]
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Codeowners Automerge Check
uses: kristoff-it/codeowners-automerge@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Supported options:
- name: Codeowners automerge check
uses: kristoff-it/codeowners-automerge@v1
with:
dir: ".github/"
merge_method: 'merge' # 'merge' 'squash' 'rebase'