Git Product home page Git Product logo

backport-github-action's Introduction

Backport Github Action

Getting started

Create a file /.github/workflows/backport.yml with the following content:

name: Automatic backport action

on:
  pull_request_target:
    types: ["labeled", "closed"]

jobs:
  backport:
    name: Backport PR
    if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
    runs-on: ubuntu-latest
    steps:
      - name: Backport Action
        uses: sorenlouv/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          auto_backport_label_prefix: backport-to-

      - name: Info log
        if: ${{ success() }}
        run: cat ~/.backport/backport.info.log
        
      - name: Debug log
        if: ${{ failure() }}
        run: cat ~/.backport/backport.debug.log        
          

Now, to backport a pull request, simply apply the label backport-to-production. This will automatically backport the PR to the branch called "production" when the PR is merged.

Configuration

For more fine grained customization, and for the ability to run the Backport Tool as a CLI tool locally, you should create a .backportrc.json file in the root directory:

// .backportrc.json
{
  // example repo info
  "repoOwner": "torvalds",
  "repoName": "linux",

  // `targetBranch` option allows to automatically backport every PR to a specific branch without the need for labels
  "targetBranches": ["production"],

  // the branches available to backport to
  "targetBranchChoices": ["main", "production", "staging"],

  // In this case, adding the label "backport-to-production" will backport the PR to the "production" branch
  "branchLabelMapping": {
    "^backport-to-(.+)$": "$1"
  }
}

See the Backport Tool documentation for all configuration options.

backport-github-action's People

Contributors

bmorelli25 avatar dependabot[bot] avatar krzmbrzl avatar negz avatar reey avatar sorenlouv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

backport-github-action's Issues

Don't require two separate labels

As far as I understand, we currently have to add a lable auto-backport and another label auto-backport-to-xyz in order to have a given PR backported.
This seems like seemingly unneeded duplication information. At least from the user's perspective, it should be enough to have the auto-backport-to-xyz label as this already indicates the desire to have this PR automatically backported.

However, I suspect this is a limitation/complication of being able to search for prefixes (substrings) in the label texts? Aka: with this line in the example config:

contains(github.event.pull_request.labels.*.name, 'auto-backport')

However, it would be a neat feature if we would not require this duplication :)

Provide a way to backport a PR to one or more branches

In a project we have two active branches:

  • master
  • release-<previsous-version>

I simply want that EVERY PR merged to master is automatically tried to be backported to the previous release.

It would therefore be great if one can simply specify the branch for the backport as an option instead of using a label at all.

Backport fails randomly due to "no-branch-exception"

Hi,

We use this tool a lot in my company, thanks for it!
However, sometimes, the backport fails for the following reason:

Error: There are no branches to backport to. Aborting

We didn't manage to understand the context of this failure (we even tried to keep branches after merge but we still have the issue).

Do you know why it happens? Is there any fix/workaround to make it fully reliable?
Thank you for any help.

bump backport

Hi @sqren,

thanks for making such a useful action!

Could you bump backport to the latest version, as it contains a fix for my problem exec error 'git remote rm domenkozar'?

Failing to backport because of merge conflicts should mark the github action step in error

Hi,

I followed the setup described in the README .

When the backport fails because of merge conflicts the action logs the following JSON object:

{
  "status": "success",
  "commits": [
    {
      "author": {
        "name": "Sebastien Arod",
        "email": "[email protected]"
      },
      "sourceCommit": {          
        "committedDate": "2022-05-20T15:08:34Z",
        "message": "xxx.",
        "sha": "dbdcace0fde6e50c46c4b929b3500e8b2aae8cc4"
      },
      "sourcePullRequest": {
        "number": 784,
        "url": "https://github.com/xxx/xxx/pull/784",
        "mergeCommit": {
          "message": "xxx.",
          "sha": "dbdcace0fde6e50c46c4b929b3500e8b2aae8cc4"
        }
      },
      "sourceBranch": "master",
      "expectedTargetPullRequests": [
        {
          "branch": "V5_3",
          "state": "NOT_CREATED"
        }
      ]
    }
  ],
  "results": [
    {
      "targetBranch": "V5_3",
      "status": "handled-error",
      "error": {
        "name": "BackportError",
        "errorContext": {
          "code": "merge-conflict-exception",
          "commitsWithoutBackports": [],
          "conflictingFiles": [
            "xxx.xxx"
          ]
        }
      }
    }
  ]
}

The results property part clearly indicate that there was some merge-conflict-exception but the global status is success and the step is considered successful.

Is this the expected behavior? I would have expected a failed backport to fail the step.

Workflows don't run on backport PR

When the backport action creates the backport PR, I see GH action workflows not triggering on the PR commit (neither push nor pull_request trigger).

I'm guessing this has something to do with the PR being create from a GH action.
If that's the case, this isn't really a feature of this project, but of GH actions itself.

I just thought I'd create an issue here to check if my assumption is correct, or if this can be worked around somehow.

Feature request: include milestone on backports

Hi @sqren, thank you for this github action, it is very useful.

One thing that would help my team would be that when the pull request that is being backported belongs to a github milestone, its backports also belong to the same milestone.

If you are not able to provide this feature for free (which is understandable) would you be open to reviewing a pull request? If that's the case, would you prefer that that's controlled by a config setting, or would you be ok with this being always enabled?

Action fails on PRs that are not backported

Using the example workflow in the readme, the action will fail when a PR is merged that does not have a backport label.
This is functionally correct, but causes confusion because the PR is now displayed with a โŒ (red x) next to it.

Do you have any suggestion how this could be avoided?
To me it feels like the Action should succeed because the PR does not have any relevant labels attached. But I am open to other suggestions.

Here is the error:

  "error": {
    "name": "BackportError",
    "errorContext": {
      "code": "no-branches-exception"
    }
  },
  "errorMessage": "There are no branches to backport to. Aborting."

Example Workflow run: https://github.com/aws/jsii-rosetta/actions/runs/9088130104/job/24977165701
Example PR: aws/jsii-rosetta#1359

Backport action fails with "Author identity unknown"

Hi,

I followed the README instructions but when I run the action it fails with the following result:

{
   "targetBranch": "xx",
   "status": "unhandled-error",
   "error": {
     "name": "SpawnError",
     "context": {
       "cmdArgs": [
         "commit",
         "--no-edit",
         "--no-verify"
       ],
       "code": 128,
       "stderr": "Author identity unknown\n\n*** Please tell me who you are.\n\nRun\n\n  git config --global user.email \"[email protected]\"\n  git config --global user.name \"Your Name\"\n\nto set your account's default identity.\nOmit --global to set the identity only in this repository.\n\nfatal: empty ident name (for <runner@fv-az135-893.uqcy5m2vj4pengxy1oencsd1xf.phxx.internal.cloudapp.net>) not allowed\n",
       "stdout": ""
     }
   }
 }

It looks like the action does not set the git identity when it creates the commits. Is there some additional configuration needed?

backport:skip label no longer works in recent version

The title of this issue is self explanatory, but in recent versions of this action the backport:skip label no longer applies, and causes this to always fail the workflow, at least if it isn't being backported. Can this functionality please be readded?

For reference:

{
  "status": "failure",
  "commits": [],
  "error": {
    "name": "HandledError"
  },
  "errorMessage": "Please specify a target branch: \"--branch 6.1\".\n\nRead more: https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson"
}

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.