Skip to content

Commit 07a4e11

Browse files
authored
Dev Experience (#2912)
1 parent eaa8ae7 commit 07a4e11

File tree

2 files changed

+60
-19
lines changed

2 files changed

+60
-19
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ N/A
2626

2727
## Backporting (check the box to trigger backport action)
2828
Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.
29-
[ ] This PR should be backported (make sure to check that the backport attempt succeeds)
29+
- [ ] This PR should be backported (make sure to check that the backport attempt succeeds)

.github/workflows/pr-backport-autotrigger.yml

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,84 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
1416

15-
- name: Check for Backport Checkbox
16-
id: checkbox-check
17+
- name: Set up Git
1718
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
2128
else
22-
echo "::set-output name=backport::false"
29+
echo "backport=false" >> $GITHUB_OUTPUT
2330
fi
2431
2532
- name: List and sort release branches
2633
id: list-branches
2734
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)
3036
BETA=$(echo "$BRANCHES" | head -n 1)
3137
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 }}"
3464
3565
- name: Trigger Backport
36-
if: steps.checkbox-check.outputs.backport == 'true'
66+
if: steps.check-label.outputs.backport == 'true'
3767
run: |
68+
set -e
3869
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
4170
# Checkout the beta branch
4271
git checkout ${{ steps.list-branches.outputs.beta }}
4372
# 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
4680
git push origin ${{ steps.list-branches.outputs.beta }}
81+
git push origin ${{ steps.list-branches.outputs.new_beta_tag }}
4782
# Checkout the stable branch
4883
git checkout ${{ steps.list-branches.outputs.stable }}
4984
# 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
5292
git push origin ${{ steps.list-branches.outputs.stable }}
93+
git push origin ${{ steps.list-branches.outputs.new_stable_tag }}

0 commit comments

Comments
 (0)