-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated pull request backporting workflow (#743)
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: 'Pull Request Backporting' | ||
description: 'Creates a backporting pull request' | ||
|
||
inputs: | ||
target-branch: | ||
description: "The branch where the cherry-pick must be applied" | ||
required: true | ||
title: | ||
description: "The cherry-pick pull request title" | ||
default: "${{ github.event.pull_request.title }}" | ||
required: false | ||
body: | ||
description: "The cherry-pick pull request body" | ||
default: "${{ github.event.pull_request.body }}" | ||
required: false | ||
original-pr-url: | ||
description: "Original pull request url" | ||
default: "${{ github.event.pull_request.html_url }}" | ||
required: false | ||
original-pr-branch: | ||
description: "Original pull request branch name" | ||
default: "${{ github.event.pull_request.head.ref }}" | ||
required: false | ||
author: | ||
description: "Author of the original pull request" | ||
default: "${{ github.event.pull_request.user.login }}" | ||
required: false | ||
additional-reviewers: | ||
description: "Additional backported pull request reviewers, e.g., toJSON(github.event.pull_request.requested_reviewers)" | ||
default: "[]" | ||
required: false | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Prepare reviewers | ||
id: prepare-reviewers | ||
shell: bash | ||
run: | | ||
echo "Additional reviewers retrieved below" | ||
echo "${{ inputs.additional-reviewers }}" | ||
reviewers="$(echo ${{ inputs.additional-reviewers }} | jq -c 'map(.login)' | jq -cr '. |= . + ["${{ inputs.author }}"] | unique | join(",")')" | ||
echo "reviewers = ${reviewers}" | ||
echo "BACKPORT_REVIEWERS=${reviewers}" >> $GITHUB_ENV | ||
- name: Perform cherry pick | ||
id: cherry-pick | ||
uses: carloscastrojumo/github-cherry-pick-action@v1.0.5 | ||
with: | ||
branch: "${{ inputs.target-branch }}" | ||
title: "[${{ inputs.target-branch }}] ${{ inputs.title }}" | ||
body: "**Backport:** ${{ inputs.original-pr-url }}\r\n\r\n${{ inputs.body }}" | ||
labels: | | ||
cherry-pick :cherries: | ||
inherit_labels: false | ||
cherry-pick-branch: "${{ inputs.target-branch }}_${{ inputs.original-pr-branch }}" | ||
reviewers: ${{ env.BACKPORT_REVIEWERS }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: 'Parse Labels' | ||
description: 'Extract target branches or refs from labels' | ||
|
||
inputs: | ||
labels: | ||
description: "List of label objects to be parsed, e.g., github.event.pull_request.labels" | ||
required: true | ||
label-prefix: | ||
description: "Extract targets from labels matching this provided prefix" | ||
default: "backport-" | ||
required: false | ||
|
||
outputs: | ||
targets: | ||
description: "Extracted targets" | ||
value: ${{ steps.extract-targets.outputs.targets }} | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Fetch labels | ||
id: fetch-labels | ||
shell: bash | ||
run: | | ||
echo "Labels retrieved below" | ||
echo "${{ inputs.labels }}" | ||
filtered_labels="$(echo ${{ inputs.labels }} | jq -c 'map(select(.name | startswith("${{ inputs.label-prefix }}")))')" | ||
echo "filtered_labels = ${filtered_labels}" | ||
echo "FILTERED_LABELS=${filtered_labels}" >> $GITHUB_ENV | ||
- name: Extract targets | ||
id: extract-targets | ||
shell: bash | ||
run: | | ||
targets="$(echo $FILTERED_LABELS | jq -c '[.[] | .name | sub("${{ inputs.label-prefix }}"; "")]')" | ||
echo "::set-output name=targets::$(echo $targets)" | ||
- name: Printing extracted targets | ||
shell: bash | ||
run: echo "Extracted target branches ${{ steps.extract-targets.outputs.targets }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |