Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 5 additions & 48 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,17 @@ on:

jobs:
backport:
if: >
github.event.action == 'labeled' &&
github.event.pull_request.merged == true &&
startsWith(github.event.label.name, 'backport ')
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

steps:
- name: Determine target branch
id: vars
run: |
label="${{ github.event.label.name }}"
target="${label#backport }"
echo "target=$target" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v 6.0.2

- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v 6.0.2
- name: Backport
uses: korthout/backport-action@4aaf0e03a94ff0a619c9a511b61aeb42adea5b02 # v4.2.0
with:
fetch-depth: 0

- name: Configure git
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"

- name: Cherry pick merge commit
env:
TARGET: ${{ steps.vars.outputs.target }}
PR: ${{ github.event.pull_request.number }}
run: |
MERGE_SHA=${{ github.event.pull_request.merge_commit_sha }}

BRANCH="backport/pr-${PR}-to-${TARGET}"

git fetch origin $TARGET
git checkout -b $BRANCH origin/$TARGET

git cherry-pick -x $MERGE_SHA

git push origin $BRANCH

- name: Create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET: ${{ steps.vars.outputs.target }}
PR: ${{ github.event.pull_request.number }}
run: |
BRANCH="backport/pr-${PR}-to-${TARGET}"

gh pr create \
--base $TARGET \
--head $BRANCH \
--title "Backport PR #$PR to $TARGET" \
--body "Automated backport of #$PR to \`$TARGET\`."
github_token: ${{ secrets.GITHUB_TOKEN }}