|
| 1 | +name: Backport |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [closed, labeled] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + backport: |
| 13 | + name: Backport |
| 14 | + runs-on: ubuntu-latest |
| 15 | + # Fire on merge (for PRs already labeled) and on labels added after merge. |
| 16 | + if: | |
| 17 | + github.event.pull_request.merged == true && ( |
| 18 | + (github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'backport')) || |
| 19 | + (github.event.action == 'labeled' && github.event.label.name == 'backport') |
| 20 | + ) |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Resolve patch-release branch from latest release tag |
| 27 | + id: resolve |
| 28 | + run: | |
| 29 | + # Highest release tag, including pre-releases. The maintainer decides |
| 30 | + # at dispatch time whether to cut a `release` or `pre-release` from |
| 31 | + # the resulting `patch-release/v<version>` branch. |
| 32 | + last_tag="$(git tag --sort=-v:refname --list 'v*' | head -1)" |
| 33 | + if [ -z "$last_tag" ]; then |
| 34 | + echo "No release tags found." >&2 |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + target="patch-release/$last_tag" |
| 38 | + echo "last_tag=$last_tag" >> "$GITHUB_OUTPUT" |
| 39 | + echo "target=$target" >> "$GITHUB_OUTPUT" |
| 40 | +
|
| 41 | + - name: Ensure patch-release branch exists |
| 42 | + run: | |
| 43 | + target="${{ steps.resolve.outputs.target }}" |
| 44 | + last_tag="${{ steps.resolve.outputs.last_tag }}" |
| 45 | + if git ls-remote --exit-code --heads origin "$target" >/dev/null; then |
| 46 | + echo "Branch $target already exists." |
| 47 | + else |
| 48 | + echo "Creating $target from $last_tag." |
| 49 | + git push origin "refs/tags/$last_tag:refs/heads/$target" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Create backport PR |
| 53 | + uses: korthout/backport-action@v3 |
| 54 | + with: |
| 55 | + target_branches: ${{ steps.resolve.outputs.target }} |
| 56 | + copy_labels_pattern: '.*' |
| 57 | + cherry_picking: 'auto' |
| 58 | + merge_commits: 'skip' |
| 59 | + pull_description: |- |
| 60 | + Backport of #${pull_number} to `${target_branch}`. |
| 61 | +
|
| 62 | + Cherry-picked from ${source_sha} (via `git cherry-pick -x`). |
0 commit comments