-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (54 loc) · 1.82 KB
/
sync-branches.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
name: 🔃 Sync branches
on:
push:
branches:
- 'v*'
workflow_dispatch:
jobs:
check-branch:
runs-on: ubuntu-latest
outputs:
is-valid-branch: ${{ steps.branch_check.outputs.is-valid-branch }}
steps:
- name: Check if branch name starts with 'v'
id: branch_check
run: |
BRANCH_NAME=${{ github.ref }}
if [[ $BRANCH_NAME =~ refs/heads/v.* ]]; then
VALID=true
else
VALID=false
fi
echo "is-valid-branch=$VALID" >> $GITHUB_OUTPUT
merge-branches:
needs: check-branch
permissions:
contents: write
if: needs.check-branch.outputs.is-valid-branch == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Merge into dev/v**
run: |
# Extract the version number from the branch name
VERSION=$(echo "${GITHUB_REF}" | sed -n 's#refs/heads/v\([0-9]\+\)#\1#p')
SOURCE_BRANCH="v${VERSION}"
TARGET_BRANCH="dev/v${VERSION}"
# Set git config
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
echo "Merging $SOURCE_BRANCH into $TARGET_BRANCH"
# Checkout the source branch
git checkout $SOURCE_BRANCH
git pull origin $SOURCE_BRANCH
echo "Pulled latest for $SOURCE_BRANCH"
# Merge into the target branch
git checkout $TARGET_BRANCH
git merge --no-ff $SOURCE_BRANCH -m "Merge v$VERSION into dev/v$VERSION"
echo "Merged $SOURCE_BRANCH into $TARGET_BRANCH"
# Push changes
git push origin $TARGET_BRANCH
echo "Pushed changes to $TARGET_BRANCH"