|
| 1 | +# .github/workflows/sync-main-to-development.yml |
| 2 | +name: Sync Main to Development |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v3 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + - name: Configure Git |
| 24 | + run: | |
| 25 | + git config user.name "github-actions[bot]" |
| 26 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 27 | + |
| 28 | + - name: Check if Development Needs Sync |
| 29 | + id: check |
| 30 | + run: | |
| 31 | + git fetch origin development |
| 32 | + |
| 33 | + # Check if main has commits that development doesn't |
| 34 | + COMMITS_AHEAD=$(git rev-list origin/development..origin/main --count) |
| 35 | + |
| 36 | + echo "Main is $COMMITS_AHEAD commits ahead of development" |
| 37 | + |
| 38 | + if [ "$COMMITS_AHEAD" -eq 0 ]; then |
| 39 | + echo "needs_sync=false" >> $GITHUB_OUTPUT |
| 40 | + else |
| 41 | + echo "needs_sync=true" >> $GITHUB_OUTPUT |
| 42 | + fi |
| 43 | + |
| 44 | + - name: Sync Main to Development |
| 45 | + if: steps.check.outputs.needs_sync == 'true' |
| 46 | + run: | |
| 47 | + git checkout development |
| 48 | + git pull origin development |
| 49 | + |
| 50 | + # Try fast-forward first |
| 51 | + if git merge origin/main --ff-only 2>/dev/null; then |
| 52 | + echo "✅ Fast-forward merge successful" |
| 53 | + else |
| 54 | + # If fast-forward fails, use regular merge |
| 55 | + echo "Fast-forward not possible, using regular merge..." |
| 56 | + git merge origin/main -m "Sync main → development (auto-merge conflict fixes)" |
| 57 | + fi |
| 58 | + |
| 59 | + git push origin development |
| 60 | + echo "✅ Development synced with main" |
0 commit comments