Merge pull request #192 from nyjc-computing/draft #75
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Branches with Main | |
| on: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| branch: [draft, intake] # Add new branches here | |
| steps: | |
| - name: Checkout Main Branch | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Git User | |
| run: | | |
| git config user.name "GitHub Action" | |
| git config user.email "action@github.com" | |
| - name: Sync with ${{ matrix.branch }} | |
| run: | | |
| TARGET_BRANCH="${{ matrix.branch }}" | |
| git checkout $TARGET_BRANCH | |
| git pull origin $TARGET_BRANCH || echo "No changes to pull for $TARGET_BRANCH" | |
| # Try fast-forward merge first (only if target is ancestor of main) | |
| if git merge-base --is-ancestor $TARGET_BRANCH origin/main 2>/dev/null; then | |
| git merge --ff-only origin/main && git push origin $TARGET_BRANCH | |
| else | |
| # Branch has diverged - rebase target branch onto main | |
| git rebase origin/main | |
| git push origin $TARGET_BRANCH --force-with-lease | |
| fi |