Sync Docs #15
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 Docs | |
| on: | |
| schedule: | |
| - cron: '0 18 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| env: | |
| TARGET_BRANCH: gh-pages | |
| jobs: | |
| sync-and-commit: | |
| name: Sync and commit (Ubuntu 24.04) | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Generate app token | |
| id: app-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| app-id: ${{ secrets.MIRROR_APP_ID }} | |
| private-key: ${{ secrets.MIRROR_APP_PRIVATE_KEY }} | |
| repositories: | | |
| api | |
| api-mirror | |
| - name: Checkout boatraceopenapi/api-mirror | |
| uses: actions/checkout@v7 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| ref: gh-pages | |
| - name: Checkout boatraceopenapi/api | |
| uses: actions/checkout@v7 | |
| with: | |
| repository: boatraceopenapi/api | |
| path: _api_repo | |
| token: ${{ steps.app-token.outputs.token }} | |
| ref: gh-pages | |
| - name: Sync docs | |
| run: | | |
| if [ ! -d "_api_repo/docs" ]; then | |
| echo "::error::_api_repo/docs not found" | |
| exit 1 | |
| fi | |
| rm -rf docs | |
| mkdir -p docs | |
| cp -r _api_repo/docs/. docs/ | |
| rm -rf _api_repo | |
| - name: Deploy docs | |
| run: | | |
| git config --global user.name "${{ steps.app-token.outputs.app-slug }}[bot]" | |
| git config --global user.email "${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" | |
| git add docs | |
| git commit -m "chore: sync docs from boatraceopenapi/api ($(date -u +%Y-%m-%d))" || { | |
| echo "Nothing to commit." | |
| exit 0 | |
| } | |
| git push origin HEAD:"${TARGET_BRANCH}" || (git pull --rebase origin "${TARGET_BRANCH}" && git push origin HEAD:"${TARGET_BRANCH}") |