name: atlas-python-docs
on:
workflow_dispatch:
inputs:
version:
description: "Docs version to publish (e.g. 1.2.3). Leave blank to publish as 'dev'."
required: false
type: string
alias:
description: "Alias to update (e.g. latest)."
required: false
default: dev
type: string
release:
types: [published]
push:
tags:
- "v*" permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Extract version
id: vars
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
INPUT_ALIAS: ${{ github.event.inputs.alias }}
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
# Tag push or release: refs/tags/v1.2.3 -> version=1.2.3, alias=latest
VERSION="${GITHUB_REF#refs/tags/v}"
ALIAS=latest
else
# Manual run: use provided inputs, falling back to 'dev'
VERSION="${INPUT_VERSION:-dev}"
ALIAS="${INPUT_ALIAS:-dev}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "alias=$ALIAS" >> $GITHUB_OUTPUT
- name: Show version
run: |
echo "Deploying docs version '${{ steps.vars.outputs.version }}' (alias '${{ steps.vars.outputs.alias }}')"
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: ~/.cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material mkdocstrings[python] mike
- run: pip install -e ./atlas-python
- env:
VERSION: ${{ steps.vars.outputs.version }}
ALIAS: ${{ steps.vars.outputs.alias }}
run: |
git fetch origin gh-pages --depth=1 || true
# mike rejects an alias identical to the version, so only pass it when it differs
if [[ "$ALIAS" == "$VERSION" ]]; then
mike deploy --push --update-aliases -F atlas-python/mkdocs.yml "$VERSION"
else
mike deploy --push --update-aliases -F atlas-python/mkdocs.yml "$VERSION" "$ALIAS"
fi
# The site root must always redirect to `latest`, so only (re)write the
# root index.html when this run deploys the `latest` alias (releases).
# Manual `dev` runs are published at /dev/ but never touch the root.
if [[ "$ALIAS" == "latest" ]]; then
mike set-default --push -F atlas-python/mkdocs.yml latest
fi