-
Notifications
You must be signed in to change notification settings - Fork 16
121 lines (111 loc) · 4.77 KB
/
create-backport-branch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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 }}"