Skip to content

+changelog-ignore: sync branch action #1

+changelog-ignore: sync branch action

+changelog-ignore: sync branch action #1

Workflow file for this run

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"