Fix publish workflow #67
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: MkDocs | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- "v*" | |
pull_request: | |
types: # Add closed type | |
- opened | |
- reopened | |
- synchronize | |
- closed # to delete the PR preview | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
PYTHON_VERSION: "3.14" | |
jobs: | |
deploy-docs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
# Fetch the entire git history (all branches + tags) | |
# We do this because the docs use git describe, which requires having all | |
# the commits up to the latest version tag. | |
# We also need the gh-pages branch to push the docs to. | |
fetch-depth: 0 | |
- name: Setup uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
version: "latest" | |
python-version: ${{ env.PYTHON_VERSION }} | |
enable-cache: true | |
cache-suffix: "docs-py${{ env.python-version }}" | |
- name: Install dependencies | |
run: | | |
uv sync --no-default-groups --group docs | |
- name: Build the documentation (mkdocs - PR preview) | |
if: ${{ github.event_name == 'pull_request' }} | |
run: mkdocs build | |
- name: Setup git config | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Deploy docs - PR preview | |
if: ${{ github.event_name == 'pull_request' }} | |
uses: rossjrw/pr-preview-action@v1 | |
with: | |
source-dir: ./site | |
preview-branch: gh-pages | |
umbrella-dir: pr-preview | |
token: ${{ github.token }} | |
- name: Build the documentation (mike / latest) | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
run: mike deploy latest | |
- name: Build the documentation (mike / release tag) | |
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
run: mike deploy --update-aliases "$(git describe)" release | |
- name: Deploy docs - latest | |
if: ${{ github.event_name == 'push' }} | |
run: | | |
# Make sure we fetch first, as another mkdocs ci may have finished | |
# ahead of this one (can happen during releases, when mkdocs workflow | |
# runs for both version tags and latest main releases concurrently) | |
# Conflicts shouldn't occur here, these just create new dirs, version | |
# tags will modify versions.json, but this shouln't conflict as latest | |
# push builds don't modify it and we shouldn't ever see two version | |
# tags running concurrently (even if, git might be smart enough to | |
# handle that without a conflict, but I haven't tested it). | |
git fetch origin gh-pages | |
git checkout gh-pages | |
git branch --set-upstream-to=origin/gh-pages gh-pages | |
git pull --rebase || { echo "Conflict detected, stopping."; exit 1; } | |
git push |