Skip to content

Commit

Permalink
+changelog-ignore: sync branches
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdcdev committed Jun 6, 2024
1 parent 3b21790 commit fa1f52e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/sync-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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"

0 comments on commit fa1f52e

Please sign in to comment.