Code Monkey home page Code Monkey logo

update-branch's Introduction

Update Branch

Merge your pull request in order when enabled the Require branches to be up to date before merging.

Inspired by Merge Queue feature of Mergify.

Safety

Do not merge broken pull requests. By merging your pull requests serially using a queue, your code is safe. Each pull request is tested with the latest CI code.

Save CI time

Rather than overconsuming your CI time by trying to merge multiple pull requests, just run it once before the pull request gets merged.

Quick Start

This action only has effect if you enabled Settings/Branches/YourBranchProtectionRule/Require status checks to pass before merging/Require branches to be up to date before merging.

  1. Enable Allow auto-merge in Settings/Options.

  2. Create a workflow file (.github/workflow/update-branch.yaml):

Example:

name: Update branch

on:
  push:
    branches:
      - main
  pull_request:
    types:
      - labeled
  check_suite:
    types:
      - completed

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  update-branch:
    runs-on: ubuntu-latest
    steps:
      - uses: lcdsmao/update-branch@v3
        with:
          # Or use personal access token
          token: ${{ secrets.GITHUB_TOKEN }}
          # One of MERGE, SQUASH, REBASE (default: MERGE)
          autoMergeMethod: SQUASH
          # Ignore pull requests without these labels
          requiredLabels: auto-merge
          # Required at least 2 approves (default: 0)
          requiredApprovals: 2
          # Required approvals from all requested reviewers
          allRequestedReviewersMustApprove: true
          # Required these status checks success
          requiredStatusChecks: |
            build_pr
            WIP
          # Optionally set the maximum amount of pull requests to match against (default: 50)
          fetchMaxPr: 50
          # Optionally set the maximum amount of pull request checks to fetch (default: 100)
          fetchMaxPrChecks: 100
          # Optionally set the maximum amount of pull request labels to fetch (default: 10)
          fetchMaxPrLabels: 10
          # Optionally set the maximum amount of pull request comments to fetch (default: 50)
          fetchMaxComments: 50
          # The order pr checks should be fetched in. If the required checks are the last ones, consider setting to "last"
          prChecksFetchOrder: first

If you are using a personal access token and it has permission to access branch protection rules, you can set your jobs like:

jobs:
  update-branch:
    runs-on: ubuntu-latest
    steps:
      - uses: lcdsmao/update-branch@v3
        with:
          # Personal access token
          token: ${{ secrets.MY_PAT }}
          # One of MERGE, SQUASH, REBASE (default: MERGE)
          autoMergeMethod: SQUASH
          # Ignore pull requests without these labels
          requiredLabels: auto-merge
          # `Status checks` and `Require approvals` settings will be used
          # Or ignore this key then the action will automatically find main or master branch protection rule
          protectedBranchNamePattern: trunk

update-branch's People

Contributors

dependabot[bot] avatar lcdsmao avatar sindrig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sindrig

update-branch's Issues

Extend README.md of using scenarios.

Please extend README.dm of using scenarios.
Currently is hard to understand how it works in real world or how it would work with other user/automated actions.
Please consider using few scenarios. sample list of branches and describing step by step how it would work.

Cannot read property 'contexts' of null

I receive an error "Cannot read property 'contexts' of null" during exectuion of "update-branch" action.

This action only has effect if you enabled Settings/Branches/YourBranchProtectionRule/Require status checks to pass before merging/Require branches to be up to date before merging.

Done

Enable Allow auto-merge in Settings/Options.

Done

Configuration:

name: Update branch

on:
  push:
    branches:
      - rel_lurbanski
  pull_request:
    types:
      - labeled
  check_suite:
    types:
      - completed

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  update-branch:
    runs-on: self-hosted
    steps:
      - uses: lcdsmao/[email protected]
        with:
          # Or use personal access token
          token: ${{ secrets.GITHUB_TOKEN }}
          # One of MERGE, SQUASH, REBASE (default: MERGE)
          autoMergeMethod: SQUASH
          # Ignore pull requests without these labels
          requiredLabels: auto-merge
          # Required at least 2 approves (default: 0)
          requiredApprovals: 2
          # Required these status checks success
          requiredStatusChecks: |
            Dummy_build
            WIP

Full logs:

##[debug]Evaluating condition for step: 'Run lcdsmao/[email protected]'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Run lcdsmao/[email protected]
##[debug]Loading inputs
##[debug]Evaluating: secrets.GITHUB_TOKEN
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'GITHUB_TOKEN'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Loading env
Run lcdsmao/[email protected]
Condition:
{
  "requiredApprovals": [2](https://github.com/equinix-product/iam-rssi/runs/5448341429?check_suite_focus=true#step:2:2),
  "requiredStatusChecks": [
    "Dummy_build",
    "WIP"
  ],
  "requiredLabels": [
    "auto-merge"
  ]
}
Error: Cannot read property 'contexts' of null
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Run lcdsmao/update-branch@v[3](https://github.com/equinix-product/iam-rssi/runs/5448341429?check_suite_focus=true#step:2:3).1.3

Reconsider PR checks

Hello,

Using the action I’ve faced a situation when some PRs are not processed even if all required conditions are met.
After analysing the code I found this check:

pr.reviewRequests.totalCount === 0 &&



In my case, I'm requesting 6 reviews, however, according to the branch protection rules only 1 approval is required. So, pr.reviewRequests.totalCount can be greater than condition.requiredApprovals and will never be equal to 0 .

Here is my action.yaml:


name: Auto Update/Merge branch

on:
  push:
    branches: [release]
  workflow_dispatch:

jobs:
  Update-merge-branch:
    runs-on: [ self-hosted ]
    steps:
      - uses: lcdsmao/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          autoMergeMethod: SQUASH
          protectedBranchNamePattern: release


Could you please consider this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.