|
| 1 | +# Requires |
| 2 | +# - pyproject.toml with a group called "docs" |
| 3 | +# - docs directory in the project root |
| 4 | +# - A __PKG_VERSION__ string in the JupyterBook _config.yml which |
| 5 | +# is used to replace the with the package version derived from the |
| 6 | +# python package defined in the pyproject.toml |
| 7 | +# |
| 8 | +name: Documentation workflow for tskit-dev |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_call: |
| 12 | + inputs: |
| 13 | + pyproject-directory: |
| 14 | + description: 'Directory to find pyproject.toml' |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + default: '.' |
| 18 | + |
| 19 | +jobs: |
| 20 | + Docs: |
| 21 | + runs-on: ubuntu-24.04 |
| 22 | + steps: |
| 23 | + - uses: styfle/cancel-workflow-action@0.12.1 |
| 24 | + with: |
| 25 | + access_token: ${{ github.token }} |
| 26 | + |
| 27 | + - uses: actions/checkout@v4.2.2 |
| 28 | + with: |
| 29 | + submodules: true |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - uses: actions/setup-python@v5.4.0 |
| 33 | + with: |
| 34 | + python-version: '3.11' |
| 35 | + |
| 36 | + - name: Install doxygen |
| 37 | + # We don't need this for every repo so could make it optional |
| 38 | + run: sudo apt-get update && sudo apt-get install -y doxygen |
| 39 | + |
| 40 | + - name: Install uv |
| 41 | + uses: astral-sh/setup-uv@v6 |
| 42 | + with: |
| 43 | + version: "0.8.15" |
| 44 | + |
| 45 | + - name: Install doc deps |
| 46 | + run: uv sync --project=${{ inputs.pyproject-directory }} --locked --group docs |
| 47 | + |
| 48 | + # This is complicated. We run an embedded python script using uv which |
| 49 | + # reads the project name from pyproject.toml, and then uses python's |
| 50 | + # importlib to determine the version number. This should be robust to |
| 51 | + # version numbers being set in a number of ways. |
| 52 | + - name: Set build version |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + export PROJECT_DIR="${{ inputs.pyproject-directory }}" |
| 57 | + PKG_VERSION="$( |
| 58 | + uv run --project "$PROJECT_DIR" python - <<PY |
| 59 | + import os |
| 60 | + import tomllib |
| 61 | + import pathlib |
| 62 | + import importlib.metadata as m |
| 63 | +
|
| 64 | + project_dir = pathlib.Path(os.environ['PROJECT_DIR']) |
| 65 | + data = tomllib.loads((project_dir / 'pyproject.toml').read_text()) |
| 66 | + name = data['project']['name'] |
| 67 | + print(m.version(name)) |
| 68 | + PY |
| 69 | + )" |
| 70 | + echo "PKG_VERSION=$PKG_VERSION" |
| 71 | + sed -i s/__PKG_VERSION__/${PKG_VERSION}/g docs/_config.yml |
| 72 | +
|
| 73 | + - name: Build documentation |
| 74 | + run: uv run --project=${{ inputs.pyproject-directory }} jupyter-book build -nW docs/ |
| 75 | + |
| 76 | + - name: Trigger tskit-site rebuild |
| 77 | + if: github.ref == 'refs/heads/main' |
| 78 | + run: | |
| 79 | + curl -X POST https://api.github.com/repos/tskit-dev/tskit-site/dispatches \ |
| 80 | + -H 'Accept: application/vnd.github.everest-preview+json' \ |
| 81 | + -u AdminBot-tskit:${{ secrets.ADMINBOT_TOKEN }} \ |
| 82 | + --data '{"event_type":"build-docs"}' |
0 commit comments