Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-pull-request

GitHub Action

Update PR Branch

v0.4.0

Update PR Branch

git-pull-request

Update PR Branch

Automatically update the branch of newest (by default) ready to merge PR. Designed to work with the auto-merge option

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Update PR Branch

uses: adRise/update-pr-branch@v0.4.0

Learn more about this action in adRise/update-pr-branch

Choose a version

Update PR Branch Action

GitHub Actions Coverage Status

Automatically update the PR branch

The job of the action is to help click "Update branch" button for you. Designed to work with the auto-merge and "Require branches to be up to date before merging" options. It will update the newest open PR that match the below conditions

  • The PR has the auto-merge option enabled
  • The PR has 2 approvals and no changes-requested review
  • The PR has all checks passed
  • The PR branch has no conflicts with the base branch
  • The PR branch is behind the base branch

When do you need this action

You may consider to use this action if you:

Because of #2, even you have enabled auto-merge for a PR, the PR won't be automatically merged if the PR branch is behind the base branch, for example someone else merges another PR before your PR passes all CI checks. See the screenshot as below.

Update branch

Inputs

token

Required

The personal access token.

Need to note, you can't use GITHUB_TOKEN because of this limitation

base

Required

Default: master

The base branch that the PR will use to fetch open PRs, for example, main, master or dev.

The action will only check PRs that use the base as the base branch.

required_approval_count

Required

Default: 2

The action will skip PRs that have less approvals than required_approval_count.

We could retrieve this value from the repo settings through an API call but that will incur one more request. GitHub has rate limit on API usage of GitHub actions.

API requests - You can execute up to 1000 API requests in an hour across all actions within a repository. If exceeded, additional API calls will fail, which might cause jobs to fail.

Example usage

name: PR update

on:
  push:
    branches:
      - 'master'
jobs:
  autoupdate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: 'master'
      - name: Automatically update PR
        uses: adRise/update-pr-branch@VERSION_YOU_WANT_TO_USE
        with:
          token: ${{ secrets.ACTION_USER_TOKEN }}
          base: 'master'
          required_approval_count: 2

Replace the VERSION_YOU_WANT_TO_USE with the actual version you want to use, check the version format here

Development

yarn
# this compile index.js to dest/init.js for running
yarn build

Note: You need to run yarn build before commit the changes because when the action only use the compiled dest/index.js.