|
| 1 | +name: Refresh built site on master/main |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master", "main" ] |
| 6 | + # Avoid infinite loops when the workflow commits only `site/` updates |
| 7 | + paths-ignore: |
| 8 | + - 'site/**' |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: refresh-site-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + refresh-site: |
| 19 | + if: github.actor != 'github-actions[bot]' |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Setup Python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: '3.x' |
| 32 | + |
| 33 | + - name: Install MkDocs and theme |
| 34 | + run: | |
| 35 | + python -m pip install --upgrade pip |
| 36 | + pip install mkdocs mkdocs-material pymdown-extensions |
| 37 | +
|
| 38 | + - name: Build docs to temporary directory |
| 39 | + run: | |
| 40 | + mkdocs --version |
| 41 | + # Build to a separate directory so we can rsync into site/ |
| 42 | + mkdocs build --strict --site-dir site-build |
| 43 | +
|
| 44 | + - name: Atomically refresh site directory |
| 45 | + run: | |
| 46 | + # Ensure site directory exists |
| 47 | + mkdir -p site |
| 48 | + # Use rsync with --delete to remove stale files and copy only changes |
| 49 | + rsync -a --delete site-build/ site/ |
| 50 | + rm -rf site-build |
| 51 | +
|
| 52 | + - name: Commit and push if site changed |
| 53 | + env: |
| 54 | + GIT_AUTHOR_NAME: github-actions[bot] |
| 55 | + GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com |
| 56 | + GIT_COMMITTER_NAME: github-actions[bot] |
| 57 | + GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com |
| 58 | + run: | |
| 59 | + set -e |
| 60 | + git add -A site |
| 61 | + if git diff --staged --quiet; then |
| 62 | + echo "No changes in site/, skipping commit." |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | + git commit -m "chore(docs): refresh built site [skip ci]" |
| 66 | + git push |
0 commit comments