Sync Mirror Repos #666
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 React Mirror | |
| on: | |
| schedule: | |
| # Run every 30 minutes | |
| - cron: '*/30 * * * *' | |
| workflow_dispatch: | |
| # Allow manual trigger | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout sync repo | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Clone react-mirror | |
| run: | | |
| git clone https://x-access-token:${{ secrets.MIRROR_PAT }}@github.com/greptileai/react-mirror.git mirror | |
| cd mirror | |
| git remote add upstream https://github.com/facebook/react.git | |
| git fetch upstream --tags --prune | |
| - name: Configure Git | |
| working-directory: mirror | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Sync all branches | |
| working-directory: mirror | |
| run: | | |
| # Sync all branches from upstream | |
| git fetch upstream '+refs/heads/*:refs/remotes/upstream/*' --prune | |
| # Push each upstream branch to origin | |
| for branch in $(git branch -r | grep 'upstream/' | grep -v HEAD | sed 's|upstream/||'); do | |
| echo "Syncing branch: $branch" | |
| git checkout -B "$branch" "upstream/$branch" | |
| git push origin "$branch" --force | |
| done | |
| # Return to main | |
| git checkout main | |
| - name: Sync tags | |
| working-directory: mirror | |
| run: | | |
| git push origin --tags --force | |
| - name: Sync labels | |
| env: | |
| GH_TOKEN: ${{ secrets.MIRROR_PAT }} | |
| run: | | |
| echo "Syncing labels from upstream..." | |
| gh label list --repo facebook/react --json name,color,description --limit 200 | \ | |
| jq -c '.[]' | while read label; do | |
| name=$(echo "$label" | jq -r '.name') | |
| color=$(echo "$label" | jq -r '.color') | |
| desc=$(echo "$label" | jq -r '.description // empty') | |
| if [ -n "$desc" ]; then | |
| gh label create "$name" --repo greptileai/react-mirror --color "$color" --description "$desc" --force 2>/dev/null || true | |
| else | |
| gh label create "$name" --repo greptileai/react-mirror --color "$color" --force 2>/dev/null || true | |
| fi | |
| done | |
| echo "Labels synced." | |
| - name: Sync PRs | |
| working-directory: mirror | |
| env: | |
| GH_TOKEN: ${{ secrets.MIRROR_PAT }} | |
| run: | | |
| python ${{ github.workspace }}/scripts/sync_mirror.py |