Skip to content

Commit

Permalink
Automated pull request backporting workflow (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
radtriste authored Dec 15, 2022
1 parent 9364a2e commit 6e737a7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 68 deletions.
13 changes: 7 additions & 6 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ Please make sure that your PR meets the following requirements:

<details>
<summary>
How to setup automatic cherry-pick to another branch ?
How to backport a pull request to a different branch?
</summary>

The cherry-pick action allows to setup automatic cherry-pick from `main` to a specific branch.
In order to automatically create a **backporting pull request** please add one or more labels having the following format `backport-<branch-name>`, where `<branch-name>` is the name of the branch where the pull request must be backported to (e.g., `backport-7.67.x` to backport the original PR to the `7.67.x` branch).

To allow it, you will need to add the corresponding label with pattern: `backport-{RELEASE_BRANCH}`.
For example, if a backport to branch `1.26.x` is needed, then the label should be `backport-1.26.x`.
> **NOTE**: **backporting** is an action aiming to move a change (usually a commit) from a branch (usually the main one) to another one, which is generally referring to a still maintained release branch. Keeping it simple: it is about to move a specific change or a set of them from one branch to another.
Once the PR is merged, the action will retrieve the commit and cherry-pick it to the desired branch.
Once the original pull request is successfully merged, the automated action will create one backporting pull request per each label (with the previous format) that has been added.

*NOTE: You can still add label after the merge and it should still be cherry-picked.*
If something goes wrong, the author will be notified and at this point a manual backporting is needed.

> **NOTE**: this automated backporting is triggered whenever a pull request on `main` branch is labeled or closed, but both conditions must be satisfied to get the new PR created.
</details>
62 changes: 0 additions & 62 deletions .github/workflows/cherry-pick.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/pr-backporting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Pull Request Backporting

on:
pull_request_target:
types: [closed, labeled]
branches:
- main

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
compute-targets:
if: ${{ github.event.pull_request.state == 'closed' && github.event.pull_request.merged }}
runs-on: ubuntu-latest
outputs:
target-branches: ${{ steps.set-targets.outputs.targets }}
env:
LABELS: ${{ toJSON(github.event.pull_request.labels) }}
steps:
- name: Set target branches
id: set-targets
uses: kiegroup/kogito-pipelines/.ci/actions/parse-labels@main
with:
labels: ${LABELS}

backporting:
if: ${{ github.event.pull_request.state == 'closed' && github.event.pull_request.merged && needs.compute-targets.outputs.target-branches != '[]' }}
name: "[${{ matrix.target-branch }}] - Backporting"
runs-on: ubuntu-latest
needs: compute-targets
strategy:
matrix:
target-branch: ${{ fromJSON(needs.compute-targets.outputs.target-branches) }}
fail-fast: true
env:
REVIEWERS: ${{ toJSON(github.event.pull_request.requested_reviewers) }}
steps:
- name: Backporting
uses: kiegroup/kogito-pipelines/.ci/actions/backporting@main
with:
target-branch: ${{ matrix.target-branch }}
additional-reviewers: ${REVIEWERS}

0 comments on commit 6e737a7

Please sign in to comment.