Merge pull request #23 from pablormier/dev #147
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 | |
| fetch-tags: true # for dynamic versioning | |
| - 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 | |
| env: | |
| # enable version injection | |
| POETRY_DYNAMIC_VERSIONING_COMMANDS: install,build | |
| run: | | |
| set -e | |
| pip install poetry | |
| poetry self add "poetry-dynamic-versioning[plugin]" | |
| poetry install --with dev,docs | |
| - name: Verify Version | |
| run: | | |
| poetry version | |
| echo "CORNETO version" | |
| poetry run python -c "import corneto; print(f'Imported __version__: {corneto.__version__}')" | |
| - 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: Get GitHub Pages URL via GH CLI | |
| id: pages | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "GH CLI version: $(gh --version)" | |
| echo "Fetching Pages URL for ${{ github.repository }}…" | |
| page_url=$(gh api \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| /repos/${{ github.repository }}/pages \ | |
| --jq .html_url \ | |
| ) | |
| echo "Retrieved page_url: $page_url" | |
| # Export it so later steps see it: | |
| echo "PAGE_URL=${page_url:-}" >> $GITHUB_ENV | |
| echo "Exported PAGE_URL=${page_url:-}" | |
| - 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 |