lobehub/.github/workflows/sync-main-to-dev.yaml
2026-02-08 23:02:49 +08:00

42 lines
1.2 KiB
YAML

name: 🔄 Branch Synchronization
on:
push:
branches:
- main
jobs:
sync-branches:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
- name: Prepare sync branch
id: branch
run: |
echo "SYNC_BRANCH_MAIN_DEV=sync/main-to-dev-$(date +'%Y%m%d')" >> $GITHUB_ENV
- name: Sync main to dev
if: github.ref == 'refs/heads/main'
run: |
# Sync main to dev
git checkout main
SYNC_BRANCH_DEV=${{ env.SYNC_BRANCH_MAIN_DEV }}
git checkout -B $SYNC_BRANCH_DEV
DIFF=$(git diff origin/dev...)
if [ -z "$DIFF" ]; then
echo "No changes to sync"
exit 0
fi
git push origin $SYNC_BRANCH_DEV -f
gh pr create --base dev --head $SYNC_BRANCH_DEV --title "Sync main branch to dev branch" --body "Automatic sync" || exit 0
env:
GH_TOKEN: ${{ github.token }}