π Auto-Sync Upstream #137
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: π Auto-Sync Upstream | |
| on: | |
| schedule: | |
| - cron: '0 4 * * *' # Every day at 4:00 AM UTC | |
| workflow_dispatch: # Enable manual triggers | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Add Upstream Remote | |
| run: git remote add upstream https://github.com/ml-explore/mlx-swift.git | |
| - name: Fetch Upstream | |
| run: git fetch upstream | |
| - name: Create or Update Sync Branch | |
| run: | | |
| git checkout -B sync/upstream-latest origin/main | |
| git checkout upstream/main -- . | |
| # GITHUB_TOKEN can never push a commit that touches .github/workflows/*, | |
| # regardless of the permissions: block above. `rm -rf` before restoring | |
| # is required, not optional: `git checkout <ref> -- .github/workflows` | |
| # only overwrites paths that already exist in <ref> β a file upstream | |
| # just added there (which origin/main never had) would sit in the | |
| # working tree/index untouched, and the push would get rejected for | |
| # that new file. This repo hasn't hit it yet only because upstream | |
| # mlx-swift hasn't added a new workflow file recently; mlx-swift-lm's | |
| # sibling sync did hit it, verified locally, and this mirrors the fix. | |
| rm -rf .github/workflows | |
| git checkout origin/main -- .github/workflows | |
| git add -A .github/workflows | |
| git commit -m "chore: sync with upstream/main" || true | |
| git push -f origin sync/upstream-latest | |
| - name: Create Pull Request to Main | |
| env: | |
| GH_TOKEN: ${{ secrets.SWIFTLM_PR_TOKEN || secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh pr create --base main --head sync/upstream-latest \ | |
| --title "π Auto-Sync: Apple Upstream Repository" \ | |
| --body "Automated PR to synchronize SharpAI fork with Apple mlx-swift upstream repository. Please review merge conflicts (if any) and verify CI pipelines." || echo "PR already exists or no changes" |