Auto Sync with Upstream #127
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 with Upstream | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # daily | |
| workflow_dispatch: | |
| env: | |
| SYNC_BRANCH: master # Change to main if your repo uses main | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up git user | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| - name: Add upstream remote and fetch | |
| run: | | |
| git remote | grep -q upstream || git remote add upstream https://github.com/jhlywa/chess.js.git | |
| git fetch upstream | |
| - name: Show pre-merge status | |
| run: git status | |
| - name: Merge upstream changes | |
| run: | | |
| git checkout ${{ env.SYNC_BRANCH }} | |
| git merge upstream/${{ env.SYNC_BRANCH }} --allow-unrelated-histories || true | |
| - name: Show post-merge status | |
| run: git status | |
| - name: Push changes if any | |
| env: | |
| GH_TOKEN: ${{ secrets.AUTO_SYNC }} | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }} ${{ env.SYNC_BRANCH }} | |
| else | |
| echo "No changes to push." | |
| fi |