Sync with upstream #136
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: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 6 * * *' | |
| jobs: | |
| repo-sync: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 # Fetch all history to access all branches | |
| - name: Get current upstream-main commit | |
| id: before_sync | |
| run: | | |
| # Check if upstream-main branch exists on remote and get its commit hash | |
| if git ls-remote --exit-code --heads origin upstream-main > /dev/null 2>&1; then | |
| BEFORE_COMMIT=$(git ls-remote origin upstream-main | cut -f1) | |
| echo "before_commit=$BEFORE_COMMIT" >> $GITHUB_OUTPUT | |
| echo "upstream-main commit before sync: $BEFORE_COMMIT" | |
| else | |
| echo "before_commit=" >> $GITHUB_OUTPUT | |
| echo "upstream-main branch does not exist yet" | |
| fi | |
| - name: repo-sync | |
| id: sync | |
| uses: repo-sync/github-sync@7c8493e95237362ad417495e8512c37e78d25f19 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.UNITY_PAT }} | |
| with: | |
| source_repo: "https://github.com/supabase/realtime" | |
| source_branch: "main" | |
| destination_branch: "upstream-main" | |
| sync_tags: "" | |
| github_token: ${{ secrets.UNITY_PAT }} | |
| - name: Check for changes in upstream-main | |
| id: check_changes | |
| run: | | |
| # Fetch all branches to ensure we have the latest upstream-main | |
| git fetch origin | |
| # Get the commit hash of upstream-main after sync | |
| AFTER_COMMIT=$(git rev-parse origin/upstream-main) | |
| echo "after_commit=$AFTER_COMMIT" >> $GITHUB_OUTPUT | |
| echo "upstream-main commit after sync: $AFTER_COMMIT" | |
| # Compare with the commit before sync | |
| BEFORE_COMMIT="${{ steps.before_sync.outputs.before_commit }}" | |
| echo "upstream-main commit before sync: $BEFORE_COMMIT" | |
| if [ "$BEFORE_COMMIT" = "$AFTER_COMMIT" ] && [ -n "$BEFORE_COMMIT" ]; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "No changes in upstream-main - commits are identical" | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| echo "Changes detected in upstream-main - commits are different or this is the first sync" | |
| fi | |
| - name: Create Pull Request from console | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.UNITY_PAT }} | |
| run: | | |
| # Check if PR already exists with this title | |
| PR_TITLE="🔄 Sync with upstream changes" | |
| EXISTING_PR=$(gh pr list --base main --state open --json title --jq ".[] | select(.title == \"$PR_TITLE\") | .title") | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "PR with title '$PR_TITLE' already exists. Skipping PR creation." | |
| else | |
| echo "No existing PR found. Creating new PR..." | |
| # Create PR body | |
| PR_BODY="## Upstream Sync | |
| This PR contains the latest changes from the upstream repository. | |
| **Changes included:** | |
| - Synced from upstream/main | |
| - Auto-generated by upstream sync workflow | |
| **Review checklist:** | |
| - [ ] Review the changes for any breaking changes | |
| - [ ] Check for conflicts with local modifications | |
| - [ ] Verify tests pass (if applicable) | |
| --- | |
| *This PR was automatically created by the upstream sync workflow*" | |
| gh pr create \ | |
| --base main \ | |
| --head upstream-main \ | |
| --title "$PR_TITLE" \ | |
| --body "$PR_BODY" | |
| fi |