diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 730513f17..b8f847c1b 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -16,15 +16,16 @@ Please make sure that your PR meets the following requirements:
-How to setup automatic cherry-pick to another branch ? +How to backport a pull request to a different branch? -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-`, where `` 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.
\ No newline at end of file diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml deleted file mode 100644 index 717825c69..000000000 --- a/.github/workflows/cherry-pick.yml +++ /dev/null @@ -1,62 +0,0 @@ -on: - pull_request_target: - branches: - - main - types: - - "labeled" - - "closed" - -env: - LABEL_PREFIX: 'backport-' - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -jobs: - fetch_labels: - runs-on: ubuntu-latest - outputs: - labels: ${{ steps.set-labels.outputs.labels }} - env: - LABELS: ${{ toJSON(github.event.pull_request.labels) }} - steps: - - name: Retrieve labels - id: set-labels - run: | - printf '%s\n' "${LABELS}" > labels.json - echo "Labels retrieved below" - cat labels.json - - included_labels="$(cat labels.json | jq -c 'map(select(.name | startswith("${{ env.LABEL_PREFIX }}")))')" - echo "included_labels = ${included_labels}" - - echo ::set-output name=labels::{\"include\":$(echo ${included_labels})} - - cherry_pick_release_branch_labels: - runs-on: ubuntu-latest - needs: fetch_labels - if: ${{ github.event.pull_request.state == 'closed' && github.event.pull_request.merged }} - strategy: - matrix: ${{ fromJSON(needs.fetch_labels.outputs.labels) }} - fail-fast: true - name: Cherry pick for ${{ matrix.name }} - steps: - - name: Calculate release branch - run: | - label=${{ matrix.name }} - echo "RELEASE_BRANCH=${label#${{ env.LABEL_PREFIX }}}" >> $GITHUB_ENV - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Perform cherry-pick - uses: carloscastrojumo/github-cherry-pick-action@v1.0.3 - with: - branch: "${{ env.RELEASE_BRANCH }}" - title: "[${{ env.RELEASE_BRANCH }}] ${{ github.event.pull_request.title }}" - body: "cherry-pick: ${{ github.event.pull_request.html_url }}" - labels: | - cherry-pick :cherries: - inherit_labels: false - reviewers: | - radtriste - ${{ github.event.pull_request.user.login }} - diff --git a/.github/workflows/pr-backporting.yml b/.github/workflows/pr-backporting.yml new file mode 100644 index 000000000..e028a852b --- /dev/null +++ b/.github/workflows/pr-backporting.yml @@ -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} \ No newline at end of file