A GitHub action to rebase pull requests in a repository.
The default behavior of the action with no configured inputs is to check the current repository for rebaseable pull requests and rebase them. Pull requests from forks are rebaseable only if they allow edits from maintainers.
- uses: peter-evans/[email protected]
with:
# GitHub auth token
# Default: ${{ github.token }}
token: ''
# The target GitHub repository
# Default: ${{ github.repository }}
repository: ''
# Filter pull requests by head user or head organization and branch name in the
# format user:ref-name or organization:ref-name. For example:
# github:new-script-format or octocat:test-branch.
head: ''
# Filter pull requests by base branch name. Example: gh-pages.
base: ''
# Run this command within the branch before rebasing against `base`
command-to-run-before-rebase: ''
# Run this command when a conflict is found, and try to merge again.
command-to-run-on-conflict: ''
# The default branch for the repo, defaults to master
# Default: master
default-branch: ''
# The Dependabot PR's require a PR Comment to rebase them. When this is `true` a
# comment will be added: `@dependabot rebase`
# Default: true
handle-dependabot: ''
The simplest way to use this action is to schedule it to run periodically.
name: Rebase
on:
schedule:
- cron: '0 0 * * *'
jobs:
rebase:
runs-on: Ubuntu-20.04
steps:
- uses: peter-evans/[email protected]
name: Rebase
on:
push:
branches: [master]
jobs:
rebase:
runs-on: Ubuntu-20.04
steps:
- uses: peter-evans/[email protected]
with:
base: master
name: Rebase Open PR's after a Merge to Dev
on:
push:
branches:
- dev
jobs:
rebase:
runs-on: Ubuntu-20.04
steps:
- uses: peter-evans/[email protected]
with:
base: dev
default-branch: dev
command-to-run-before-rebase: bash -c "grep -m 1 -Po '<version>\K[^<]*' pom.xml > version.tmp"
command-to-run-on-conflict: bash -c ".github/scripts/fix_version_conflicts.rb -s git -v $(cat version.tmp);git add pom.xml;git commit -m \"Fix merge conflict\""
NOTE: This example is using the ruby script for fixing conflicting version numbers in a pom file for maven projects found here
Use the following two workflows and a repo
scoped PAT to add a /rebase
slash command to pull request comments.
The slash-command-dispatch action makes sure that the command is only executable by users with write
access to the repository.
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: Ubuntu-20.04
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v1
with:
token: ${{ secrets.PAT }}
commands: rebase
permission: write
issue-type: pull-request
Name | Description | Default |
---|---|---|
token |
GITHUB_TOKEN or a repo scoped PAT. |
GITHUB_TOKEN |
repository |
The target GitHub repository containing the pull request. | github.repository (Current repository) |
head |
Filter pull requests by head user or head organization and branch name in the format user:ref-name or organization:ref-name . For example: github:new-script-format or octocat:test-branch . |
|
base |
Filter pull requests by base branch name. Example: gh-pages . |
|
command-to-run-before-rebase |
Run this command within the branch before rebasing against base |
|
command-to-run-on-conflict |
Run this command when a conflict is found, and try to merge again. | |
default-branch |
The default branch for the repo, defaults to master | master |
You can rebase requests in another repository by using a repo
scoped PAT instead of GITHUB_TOKEN
.
The user associated with the PAT must have write access to the repository.
This example targets multiple repositories.
name: Rebase
on:
schedule:
- cron: '0 0 * * *'
jobs:
rebase:
strategy:
matrix:
repo: ['my-org/repo1', 'my-org/repo2', 'my-org/repo3']
runs-on: Ubuntu-20.04
steps:
- uses: peter-evans/[email protected]
with:
token: ${{ secrets.PAT }}
repository: ${{ matrix.repo }}