Merge pull request #19 from pablormier/dev #142
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: Build and Deploy Docs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| tags: | |
| - '*' | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Setup Graphviz | |
| uses: ts-graphviz/setup-graphviz@v2 | |
| - name: Cache Poetry packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/pypoetry | |
| key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} | |
| - name: Cache pip packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }} | |
| - name: Install Dependencies | |
| run: | | |
| set -e | |
| pip install poetry | |
| poetry install --with dev,docs | |
| - name: Build Docs | |
| run: | | |
| set -e | |
| poetry run sphinx-build -b html docs docs/_build/html | |
| - name: Determine doc version | |
| id: set_version | |
| run: | | |
| set -e | |
| case "${GITHUB_REF}" in | |
| refs/tags/*) | |
| version="${GITHUB_REF#refs/tags/}" | |
| ;; | |
| refs/heads/main) | |
| version="main" | |
| ;; | |
| refs/heads/dev) | |
| version="dev" | |
| ;; | |
| *) | |
| echo "Unexpected branch/ref: ${GITHUB_REF}" | |
| version="dev" | |
| ;; | |
| esac | |
| echo "doc_version=${version}" >> $GITHUB_OUTPUT | |
| - name: Generate switcher.json | |
| run: | | |
| set -e | |
| poetry run python docs/generate_switcher.py | |
| - name: Create root redirect to latest | |
| run: | | |
| set -e | |
| mkdir -p temp_root | |
| cp docs/switcher.json temp_root/switcher.json | |
| touch temp_root/.nojekyll | |
| if [ -f docs/custom-index.html ]; then | |
| echo "Found custom-index.html, using it…" | |
| cp docs/custom-index.html temp_root/index.html | |
| else | |
| echo "No custom-index.html, copying default-index.html…" | |
| cp docs/default-index.html temp_root/index.html | |
| fi | |
| - name: Deploy content to root | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./temp_root | |
| destination_dir: ./ | |
| keep_files: true | |
| - name: Deploy versioned docs | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./docs/_build/html | |
| destination_dir: ${{ steps.set_version.outputs.doc_version }} | |
| keep_files: true | |
| - name: Deploy latest docs to root | |
| if: ${{ steps.set_version.outputs.doc_version == 'latest' }} | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./docs/_build/html | |
| destination_dir: ./ | |
| keep_files: true | |
| - name: Clean up temporary files | |
| run: rm -rf temp_root |