Upstream Sync #217
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: Upstream Sync | |
| on: | |
| schedule: | |
| - cron: '0 */4 * * *' # Run every 4 hours | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| check-and-create-pr: | |
| name: Check Upstream and Create PR | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required to fetch all history for commit comparison | |
| token: ${{ secrets.SWIFTLM_PR_TOKEN || secrets.GITHUB_TOKEN }} | |
| - name: Check for upstream changes and set up branch | |
| id: check_upstream | |
| run: | | |
| # Add the upstream repository | |
| git remote add upstream https://github.com/ml-explore/mlx-swift.git | |
| git fetch upstream main | |
| # Check how many commits upstream is ahead of our local main | |
| AHEAD=$(git rev-list --count HEAD..upstream/main) | |
| echo "Upstream is $AHEAD commits ahead." | |
| if [ "$AHEAD" -gt 0 ]; then | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| BRANCH_NAME="sync/upstream-latest" | |
| echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| # Checkout upstream main into the static sync branch (force reset if it exists) | |
| git checkout -B $BRANCH_NAME upstream/main | |
| git push --force origin $BRANCH_NAME | |
| else | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "No new commits to sync." | |
| fi | |
| - name: Create or Update Pull Request | |
| if: steps.check_upstream.outputs.has_changes == 'true' | |
| run: | | |
| # Check if a PR already exists for this branch | |
| PR_EXISTS=$(gh pr list HEAD --head ${{ steps.check_upstream.outputs.branch_name }} --json number --jq 'length') | |
| if [ "$PR_EXISTS" -eq "0" ]; then | |
| gh pr create \ | |
| --title "🔄 Auto-Sync: Upstream changes from ml-explore/mlx-swift" \ | |
| --body "Automated PR to sync the latest changes from upstream \`ml-explore/mlx-swift\`'s \`main\` branch. | |
| ### Merge Warnings | |
| * **Do NOT blind merge!** This repo contains custom SharpAI out-of-core SSD features. | |
| * Refer to the \`UPSTREAM_MERGE_PLAN.md\` file locally to check standard SharpAI metal optimization discrepancies. | |
| * Do **not** overwrite the submodule branch pointers under \`Package.swift\` without consultation." \ | |
| --base main \ | |
| --head ${{ steps.check_upstream.outputs.branch_name }} | |
| else | |
| echo "PR already exists. Force pushing to the branch updated the PR automatically." | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.SWIFTLM_PR_TOKEN || secrets.GITHUB_TOKEN }} |