Skip to content

Create Backport Branch #7

Create Backport Branch

Create Backport Branch #7

name: Create Backport Branch
on:
workflow_dispatch:
inputs:
last_release_version:
description: 'The version of the last release. Example: 1.2.3'
required: true
type: string
new_release_version:
description: 'The version of the new release. Example: 1.3.0'
required: true
type: string
last_release_git_tag:
description: 'The git tag of the last release. Defaults to `v{last_release_version}`. Example: v1.2.3'
required: false
default: ''
type: string
workflow_call:
inputs:
last_release_version:
description: 'The version of the last release. Example: 1.2.3'
required: true
type: string
new_release_version:
description: 'The version of the new release. Example: 1.3.0'
required: true
type: string
last_release_git_tag:
description: 'The git tag of the last release. Defaults to `v{last_release_version}`. Example: v1.2.3'
required: false
default: ''
type: string
jobs:
create_branch:
runs-on: ubuntu-latest
steps:
- name: Extract Last Release Major and Minor Versions
id: extract_last_versions
run: |
last_version='${{ inputs.last_release_version }}'
IFS='.' read -r last_major last_minor last_patch <<< "$last_version"
echo "last_major=$last_major" >> $GITHUB_OUTPUT
echo "last_minor=$last_minor" >> $GITHUB_OUTPUT
echo "last major: $last_major"
echo "last minor: $last_minor"
- name: Extract New Release Major and Minor Versions
id: extract_new_versions
run: |
new_version='${{ inputs.new_release_version }}'
IFS='.' read -r new_major new_minor new_patch <<< "$new_version"
echo "new_major=$new_major" >> $GITHUB_OUTPUT
echo "new_minor=$new_minor" >> $GITHUB_OUTPUT
echo "new major: $new_major"
echo "new minor: $new_minor"
- name: Determine Bump Type
id: determine_bump
run: |
new_major='${{ steps.extract_new_versions.outputs.new_major }}'
new_minor='${{ steps.extract_new_versions.outputs.new_minor }}'
last_major='${{ steps.extract_last_versions.outputs.last_major }}'
last_minor='${{ steps.extract_last_versions.outputs.last_minor }}'
if [ "$new_major" -gt "$last_major" ]; then
echo "bump_type=major" >> $GITHUB_OUTPUT
echo 'bump type is `major`'
elif [ "$new_major" -eq "$last_major" ] && [ "$new_minor" -gt "$last_minor" ]; then
echo "bump_type=minor" >> $GITHUB_OUTPUT
echo 'bump type is `minor`'
else
echo "bump_type=patch" >> $GITHUB_OUTPUT
echo 'bump type is `patch` or other'
fi
- name: Determine Branch Name
id: determine_branch_name
run: |
bump_type='${{ steps.determine_bump.outputs.bump_type }}'
last_major='${{ steps.extract_last_versions.outputs.last_major }}'
last_minor='${{ steps.extract_last_versions.outputs.last_minor }}'
if [ "$bump_type" = "major" ]; then
branch_name="${last_major}.x.x"
elif [ "$bump_type" = "minor" ]; then
branch_name="${last_major}.${last_minor}.x"
else
branch_name=""
fi
echo "branch_name=$branch_name" >> $GITHUB_OUTPUT
echo "branch name: $branch_name"
- name: Set Last Release Git Tag
id: set_git_tag
if: ${{ steps.determine_branch_name.outputs.branch_name != '' }}
run: |
if [ -z "${{ inputs.last_release_git_tag }}" ]; then
git_tag="v${{ inputs.last_release_version }}"
else
git_tag="${{ inputs.last_release_git_tag }}"
fi
echo "last_release_git_tag=${git_tag}" >> $GITHUB_OUTPUT
echo "last release git tag: ${git_tag}"
- name: Checkout Code
if: ${{ steps.determine_branch_name.outputs.branch_name != '' }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: true
token: ${{ secrets.CREATE_RELEASE }}
- name: Create Release Branch
if: ${{ steps.determine_branch_name.outputs.branch_name != '' }}
run: |
git fetch origin "refs/tags/${{ steps.set_git_tag.outputs.last_release_git_tag }}:refs/tags/${{ steps.set_git_tag.outputs.last_release_git_tag }}"
git checkout "${{ steps.set_git_tag.outputs.last_release_git_tag }}"
git checkout -b "${{ steps.determine_branch_name.outputs.branch_name }}"
git push origin "${{ steps.determine_branch_name.outputs.branch_name }}"
echo "branch created: ${{ steps.determine_branch_name.outputs.branch_name }}"