Skip to content

Commit 5af6e38

Browse files
committed
[#2871] Auto-rebase WIP on push
WIP branches will be rebased on the latest changes when there's a push on the corresponding stable branch.
1 parent 34638a0 commit 5af6e38

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Auto-rebase WIP branches
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- '4.2'
8+
- '3.3'
9+
- '3.2'
10+
- '2.4'
11+
12+
jobs:
13+
rebase-wip:
14+
name: Rebase WIP branch
15+
runs-on: ubuntu-latest
16+
# Only run on the upstream repository, not on forks
17+
if: github.repository == 'hibernate/hibernate-reactive'
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
22+
with:
23+
fetch-depth: 0 # Fetch all history for rebasing
24+
25+
- name: Configure Git
26+
run: |
27+
git config user.name "Auto-rebase Action
28+
git config user.email "autorebase@users.noreply.github.com"
29+
30+
- name: Determine WIP branch name
31+
id: wip-branch
32+
run: |
33+
BASE_BRANCH="${{ github.ref_name }}"
34+
35+
if [ "$BASE_BRANCH" = "main" ]; then
36+
WIP_BRANCH="wip/4.3"
37+
else
38+
WIP_BRANCH="wip/$BASE_BRANCH"
39+
fi
40+
41+
echo "wip_branch=$WIP_BRANCH" >> $GITHUB_OUTPUT
42+
echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT
43+
44+
- name: Fetch and rebase WIP branch
45+
env:
46+
WIP_BRANCH: ${{ steps.wip-branch.outputs.wip_branch }}
47+
BASE_BRANCH: ${{ steps.wip-branch.outputs.base_branch }}
48+
run: |
49+
# Fetch the WIP branch
50+
git fetch origin "$WIP_BRANCH"
51+
52+
# Check if WIP branch exists
53+
if ! git rev-parse --verify "origin/$WIP_BRANCH" > /dev/null 2>&1; then
54+
echo "WIP branch $WIP_BRANCH does not exist, skipping rebase"
55+
exit 0
56+
fi
57+
58+
# Checkout the WIP branch
59+
git checkout -b "$WIP_BRANCH" "origin/$WIP_BRANCH"
60+
61+
# Attempt rebase
62+
if git rebase "origin/$BASE_BRANCH"; then
63+
echo "✅ Rebase successful: $WIP_BRANCH rebased onto $BASE_BRANCH"
64+
echo "rebase_status=success" >> $GITHUB_ENV
65+
else
66+
echo "❌ Rebase failed with conflicts"
67+
echo "rebase_status=conflict" >> $GITHUB_ENV
68+
git rebase --abort
69+
exit 1
70+
fi
71+
72+
- name: Push rebased WIP branch
73+
if: env.rebase_status == 'success'
74+
env:
75+
WIP_BRANCH: ${{ steps.wip-branch.outputs.wip_branch }}
76+
run: |
77+
git push origin "$WIP_BRANCH" --force-with-lease
78+
echo "✅ Successfully pushed rebased $WIP_BRANCH"

0 commit comments

Comments
 (0)