name: 🔄 Branch Synchronization on: push: branches: - main jobs: sync-branches: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 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 }}