Separate latest/
and versions/
subdirectories for docs
#673
This file contains 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: docs | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
release: | |
types: [created] | |
workflow_dispatch: | |
jobs: | |
docs: | |
runs-on: ubuntu-latest | |
steps: | |
# Check out source. | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v1 | |
with: | |
python-version: "3.10" | |
- name: Set up dependencies | |
run: | | |
pip install uv | |
uv pip install --system -e ".[dev]" | |
uv pip install --system -r docs/requirements.txt | |
# Hack to overwrite version. | |
- name: Set version to 'latest' for pushes (this will appear in the doc banner) | |
run: | | |
python -c "import toml; conf = toml.load('pyproject.toml'); conf['project']['version'] = 'latest'; toml.dump(conf, open('pyproject.toml', 'w'))" | |
if: github.event_name == 'push' | |
# Build documentation. | |
- name: Building documentation | |
run: | | |
sphinx-build docs/source docs/build -b dirhtml | |
# Get version from pyproject.toml. | |
- name: Get version + subdirectory | |
run: | | |
VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") | |
echo "DOCS_SUBDIR=versions/$VERSION" >> $GITHUB_ENV | |
# Get version from pyproject.toml. | |
- name: Override subdirectory to `latest/` for pushes | |
run: | | |
echo "DOCS_SUBDIR=latest" >> $GITHUB_ENV | |
if: github.event_name == 'push' | |
# Deploy to version-dependent subdirectory. | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./docs/build | |
destination_dir: ${{ env.DOCS_SUBDIR }} | |
keep_files: false # This will only erase the destination subdirectory. | |
cname: viser.studio | |
if: github.event_name != 'pull_request' |