@@ -10,43 +10,84 @@ jobs:
10
10
runs-on : ubuntu-latest
11
11
steps :
12
12
- name : Checkout code
13
- uses : actions/checkout@v2
13
+ uses : actions/checkout@v3
14
+ with :
15
+ fetch-depth : 0
14
16
15
- - name : Check for Backport Checkbox
16
- id : checkbox-check
17
+ - name : Set up Git
17
18
run : |
18
- PR_BODY="${{ github.event.pull_request.body }}"
19
- if [[ "$PR_BODY" == *"[x] This PR should be backported"* ]]; then
20
- echo "::set-output name=backport::true"
19
+ git config user.name "github-actions[bot]"
20
+ git config user.email "github-actions[bot]@users.noreply.github.com"
21
+
22
+ - name : Check for Backport Label
23
+ id : check-label
24
+ run : |
25
+ labels="${{ github.event.pull_request.labels.*.name }}"
26
+ if [[ "$labels" == *"backport"* ]]; then
27
+ echo "backport=true" >> $GITHUB_OUTPUT
21
28
else
22
- echo "::set-output name= backport:: false"
29
+ echo "backport= false" >> $GITHUB_OUTPUT
23
30
fi
24
31
25
32
- name : List and sort release branches
26
33
id : list-branches
27
34
run : |
28
- git fetch --all
29
- BRANCHES=$(git branch -r | grep 'origin/release/v' | sed 's|origin/release/v||' | sort -Vr)
35
+ BRANCHES=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin/release/* | sed 's|origin/release/||' | sort -Vr)
30
36
BETA=$(echo "$BRANCHES" | head -n 1)
31
37
STABLE=$(echo "$BRANCHES" | head -n 2 | tail -n 1)
32
- echo "::set-output name=beta::$BETA"
33
- echo "::set-output name=stable::$STABLE"
38
+ echo "beta=$BETA" >> $GITHUB_OUTPUT
39
+ echo "stable=$STABLE" >> $GITHUB_OUTPUT
40
+
41
+ # Fetch latest tags for beta and stable
42
+ # Beta tag is in the format vX.Y.Z-beta.W
43
+ # Stable tag is in the format vX.Y.Z
44
+ LATEST_BETA_TAG=$(git tag -l "v*.*.0-beta.*" | sort -Vr | head -n 1)
45
+ LATEST_STABLE_TAG=$(git tag -l "v*.*.*" | grep -v -- "-beta" | sort -Vr | head -n 1)
46
+
47
+ # Increment latest beta tag
48
+ NEW_BETA_TAG=$(echo $LATEST_BETA_TAG | awk -F '.' '{print $1 "." $2 ".0-beta." ($4+1)}')
49
+ # Increment latest stable tag
50
+ NEW_STABLE_TAG=$(echo $LATEST_STABLE_TAG | awk -F '.' '{print $1 "." $2 "." ($3+1)}')
51
+ echo "latest_beta_tag=$LATEST_BETA_TAG" >> $GITHUB_OUTPUT
52
+ echo "latest_stable_tag=$LATEST_STABLE_TAG" >> $GITHUB_OUTPUT
53
+ echo "new_beta_tag=$NEW_BETA_TAG" >> $GITHUB_OUTPUT
54
+ echo "new_stable_tag=$NEW_STABLE_TAG" >> $GITHUB_OUTPUT
55
+
56
+ - name : Echo branch and tag information
57
+ run : |
58
+ echo "Beta branch: ${{ steps.list-branches.outputs.beta }}"
59
+ echo "Stable branch: ${{ steps.list-branches.outputs.stable }}"
60
+ echo "Latest beta tag: ${{ steps.list-branches.outputs.latest_beta_tag }}"
61
+ echo "Latest stable tag: ${{ steps.list-branches.outputs.latest_stable_tag }}"
62
+ echo "New beta tag: ${{ steps.list-branches.outputs.new_beta_tag }}"
63
+ echo "New stable tag: ${{ steps.list-branches.outputs.new_stable_tag }}"
34
64
35
65
- name : Trigger Backport
36
- if : steps.checkbox- check.outputs.backport == 'true'
66
+ if : steps.check-label .outputs.backport == 'true'
37
67
run : |
68
+ set -e
38
69
echo "Backporting to beta ${{ steps.list-branches.outputs.beta }} and stable ${{ steps.list-branches.outputs.stable }}"
39
- # Fetch all history for all branches and tags
40
- git fetch --prune --unshallow
41
70
# Checkout the beta branch
42
71
git checkout ${{ steps.list-branches.outputs.beta }}
43
72
# Cherry-pick the last commit from the merged PR
44
- git cherry-pick ${{ github.event.pull_request.merge_commit_sha }}
45
- # Push the changes to the beta branch
73
+ git cherry-pick -m 1 ${{ github.event.pull_request.merge_commit_sha }} || {
74
+ echo "Cherry-pick to beta failed due to conflicts."
75
+ exit 1
76
+ }
77
+ # Create new beta tag
78
+ git tag ${{ steps.list-branches.outputs.new_beta_tag }}
79
+ # Push the changes and tag to the beta branch
46
80
git push origin ${{ steps.list-branches.outputs.beta }}
81
+ git push origin ${{ steps.list-branches.outputs.new_beta_tag }}
47
82
# Checkout the stable branch
48
83
git checkout ${{ steps.list-branches.outputs.stable }}
49
84
# Cherry-pick the last commit from the merged PR
50
- git cherry-pick ${{ github.event.pull_request.merge_commit_sha }}
51
- # Push the changes to the stable branch
85
+ git cherry-pick -m 1 ${{ github.event.pull_request.merge_commit_sha }} || {
86
+ echo "Cherry-pick to stable failed due to conflicts."
87
+ exit 1
88
+ }
89
+ # Create new stable tag
90
+ git tag ${{ steps.list-branches.outputs.new_stable_tag }}
91
+ # Push the changes and tag to the stable branch
52
92
git push origin ${{ steps.list-branches.outputs.stable }}
93
+ git push origin ${{ steps.list-branches.outputs.new_stable_tag }}
0 commit comments