Sync with Upstream #2627
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 with Upstream | |
| on: | |
| schedule: | |
| # Run every hour | |
| - cron: "0 * * * *" | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Add upstream remote | |
| run: git remote add upstream https://github.com/sst/opencode.git | |
| - name: Fetch upstream | |
| run: git fetch upstream | |
| - name: Pre-sync validation | |
| run: | | |
| # Check if we have any uncommitted changes | |
| if ! git diff --quiet || ! git diff --cached --quiet; then | |
| echo "::error::Working directory not clean" | |
| exit 1 | |
| fi | |
| # Show what we're about to sync | |
| echo "π Sync summary:" | |
| echo "Commits behind upstream/dev:" | |
| git log --oneline origin/dev..upstream/dev | head -10 || echo "No commits behind" | |
| echo "Commits ahead of upstream/dev:" | |
| git log --oneline upstream/dev..origin/dev | head -10 || echo "No commits ahead" | |
| - name: Sync dev branch safely | |
| run: | | |
| # Create/reset local dev to match origin/dev first | |
| git checkout -B dev origin/dev | |
| # Try to merge upstream changes | |
| if git merge upstream/dev --no-edit; then | |
| echo "β Clean merge from upstream to dev" | |
| git push origin dev | |
| echo "DEV_SYNC=success" >> $GITHUB_ENV | |
| else | |
| echo "β Merge conflicts detected in dev sync" | |
| git merge --abort | |
| echo "DEV_SYNC=conflict" >> $GITHUB_ENV | |
| fi | |
| - name: Try auto-merge into epicenter | |
| if: env.DEV_SYNC == 'success' | |
| run: | | |
| git checkout epicenter | |
| # Try to merge dev into epicenter | |
| if git merge dev --no-edit; then | |
| echo "β Clean merge successful, pushing to epicenter" | |
| git push origin epicenter | |
| echo "EPICENTER_MERGE=success" >> $GITHUB_ENV | |
| else | |
| echo "β Merge conflicts detected, will create issue for manual resolution" | |
| git merge --abort | |
| echo "EPICENTER_MERGE=conflict" >> $GITHUB_ENV | |
| fi | |
| - name: Create issue for dev sync conflict | |
| if: env.DEV_SYNC == 'conflict' | |
| run: | | |
| gh issue create \ | |
| --title "Upstream sync conflict in dev branch ($(date +%Y-%m-%d))" \ | |
| --body "Auto-sync failed due to merge conflicts when merging upstream/dev into origin/dev. Manual intervention required: | |
| 1. \`git checkout dev\` | |
| 2. \`git merge upstream/dev\` | |
| 3. Resolve conflicts and commit | |
| 4. \`git push origin dev\` | |
| After resolving dev conflicts, you may also need to merge dev into epicenter." \ | |
| --label "sync-conflict,priority-high" || echo "Issue might already exist" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create issue for epicenter merge conflict | |
| if: env.DEV_SYNC == 'success' && env.EPICENTER_MERGE == 'conflict' | |
| run: | | |
| gh issue create \ | |
| --title "Sync conflict: Manual merge needed for epicenter ($(date +%Y-%m-%d))" \ | |
| --body "Auto-sync successfully updated dev branch, but failed to merge dev into epicenter due to conflicts. Manual resolution needed: | |
| 1. \`git checkout epicenter\` | |
| 2. \`git merge dev\` | |
| 3. Resolve conflicts and commit | |
| 4. \`git push origin epicenter\`" \ | |
| --label "sync-conflict" || echo "Issue might already exist" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Summary | |
| run: | | |
| echo "π Sync Summary:" | |
| if [ "$DEV_SYNC" = "success" ]; then | |
| echo "β Dev branch synced successfully" | |
| if [ "$EPICENTER_MERGE" = "success" ]; then | |
| echo "β Epicenter merge completed successfully" | |
| echo "π Full sync completed!" | |
| elif [ "$EPICENTER_MERGE" = "conflict" ]; then | |
| echo "β Epicenter merge failed - issue created" | |
| fi | |
| else | |
| echo "β Dev sync failed - issue created" | |
| echo "βΈοΈ Epicenter merge skipped" | |
| fi |