Skip to content

Commit c997c55

Browse files
authored
add backport action (#46)
1 parent 50ac9f6 commit c997c55

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/backport-2.0.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Backport to solana-v2.0
2+
3+
on:
4+
pull_request:
5+
types:
6+
- labeled
7+
- closed
8+
9+
jobs:
10+
handle-backport:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Install GitHub CLI
17+
uses: actions/setup-node@v3
18+
19+
- name: Determine backport condition
20+
id: determine
21+
run: |
22+
if [[ "${{ github.event.pull_request.merged }}" == "true" ]] && [[ "${{ github.event.label.name }}" == "v2.0" ]]; then
23+
echo "create-backport=true" >> $GITHUB_ENV
24+
elif [[ "${{ github.event.label.name }}" == "v2.0" ]]; then
25+
echo "wait-for-merge=true" >> $GITHUB_ENV
26+
fi
27+
28+
- name: Backport changes
29+
if: ${{ env.create-backport == 'true' }}
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: |
33+
# Set up Git user
34+
git config user.name "github-actions[bot]"
35+
git config user.email "github-actions[bot]@users.noreply.github.com"
36+
37+
# Fetch all branches
38+
git fetch --all
39+
40+
# Create a new branch off solana-v2.0
41+
TARGET_BRANCH="solana-v2.0"
42+
BACKPORT_BRANCH="backport-${{ github.event.pull_request.number }}-to-v2.0"
43+
git checkout $TARGET_BRANCH
44+
git checkout -b $BACKPORT_BRANCH
45+
46+
# Cherry-pick all commits from the PR
47+
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
48+
git cherry-pick $(git log --reverse --format=%H origin/$PR_BRANCH) || (git cherry-pick --abort && exit 1)
49+
50+
# Push the new branch
51+
git push origin $BACKPORT_BRANCH
52+
53+
# Create a pull request
54+
gh pr create \
55+
--base $TARGET_BRANCH \
56+
--head $BACKPORT_BRANCH \
57+
--title "Backport PR #${{ github.event.pull_request.number }} to solana-v2.0" \
58+
--body "This is an automated backport of PR #${{ github.event.pull_request.number }} to the solana-v2.0 branch."

0 commit comments

Comments
 (0)