Sync docs & regenerate references #83
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 & regenerate references | |
| # Polls zenstackhq/zenstack-docs on a schedule and regenerates references/ | |
| # ONLY when the docs repo's top-level `docs/` folder changed since the commit | |
| # our submodule is currently pinned to (changes to blog/, src/, etc. are | |
| # ignored). Also runnable manually from the Actions tab. | |
| on: | |
| schedule: | |
| - cron: '0 */6 * * *' # every 6 hours (UTC) — adjust as desired | |
| workflow_dispatch: | |
| # Never let two syncs race on the same branch. | |
| concurrency: | |
| group: sync-docs | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # the `docs` submodule is handled explicitly below | |
| - name: Check for docs/ changes upstream | |
| id: check | |
| run: | | |
| git submodule sync docs | |
| git submodule update --init docs | |
| old="$(git -C docs rev-parse HEAD)" | |
| git -C docs fetch --quiet origin main | |
| new="$(git -C docs rev-parse origin/main)" | |
| echo "new=$new" >> "$GITHUB_OUTPUT" | |
| if [ "$old" = "$new" ]; then | |
| echo "docs main unchanged ($old) — nothing to do." | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| elif git -C docs diff --quiet "$old" "$new" -- docs; then | |
| echo "docs main moved ${old:0:7} -> ${new:0:7} but the docs/ folder is unchanged — skipping." | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "docs/ folder changed (${old:0:7} -> ${new:0:7}) — regenerating." | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Update docs submodule to latest main | |
| if: steps.check.outputs.changed == 'true' | |
| run: | | |
| git -C docs checkout --quiet "${{ steps.check.outputs.new }}" | |
| # populate docs' own nested submodules (code-repos/*) at the | |
| # commits pinned by the updated docs | |
| git -C docs submodule update --init --recursive | |
| - name: Setup Node.js | |
| if: steps.check.outputs.changed == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install dependencies | |
| if: steps.check.outputs.changed == 'true' | |
| run: npm ci | |
| - name: Generate references | |
| if: steps.check.outputs.changed == 'true' | |
| run: npm run generate:references | |
| - name: Commit & push changes | |
| if: steps.check.outputs.changed == 'true' | |
| run: | | |
| git config user.name 'github-actions[bot]' | |
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No file changes after regeneration." | |
| exit 0 | |
| fi | |
| docs_sha="$(git -C docs rev-parse --short HEAD)" | |
| git commit -m "chore: sync docs (${docs_sha}) and regenerate references" | |
| git push |