Edge types #283
Workflow file for this run
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: Deploy Docs to GitHub Pages | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ["v*"] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python 3.11 | |
| uses: astral-sh/setup-uv@v7 | |
| with: | |
| python-version: '3.11' | |
| enable-cache: true | |
| - name: Determine docs version label | |
| id: docs-version | |
| run: | | |
| if [[ "$GITHUB_REF" == refs/tags/v* ]]; then | |
| echo "label=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "label=main" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Build documentation | |
| run: uv run sphinx-build docs/source docs/build/html -W -b html | |
| env: | |
| DOCS_VERSION: ${{ steps.docs-version.outputs.label }} | |
| - name: Bundle versions.json into build output | |
| run: | | |
| curl -sSf https://funkelab.github.io/motile/versions.json \ | |
| -o docs/build/html/versions.json \ | |
| || echo '[{"name": "main", "url": "/motile/main/"}]' > docs/build/html/versions.json | |
| - name: Upload docs artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: docs-html | |
| path: docs/build/html | |
| retention-days: 7 | |
| deploy: | |
| if: github.event_name != 'pull_request' | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download docs artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: docs-html | |
| path: docs/build/html | |
| - name: Determine destination directory | |
| id: dest | |
| run: | | |
| if [[ "$GITHUB_REF" == refs/tags/v* ]]; then | |
| VERSION="${GITHUB_REF#refs/tags/}" | |
| echo "dir=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "is_tag=true" >> "$GITHUB_OUTPUT" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "dir=main" >> "$GITHUB_OUTPUT" | |
| echo "is_tag=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Deploy docs to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_branch: docs | |
| publish_dir: docs/build/html | |
| destination_dir: docs/${{ steps.dest.outputs.dir }} | |
| keep_files: true | |
| - name: Generate versions.json and redirects | |
| run: | | |
| IS_TAG="${{ steps.dest.outputs.is_tag }}" | |
| VERSION="${{ steps.dest.outputs.version }}" | |
| # Clone the docs branch to read existing version directories | |
| git clone --branch docs --single-branch --depth 1 \ | |
| "https://github.com/${{ github.repository }}.git" docs-branch | |
| cd docs-branch/docs | |
| # Find all version directories (v*) | |
| VERSIONS=$(ls -d v*/ 2>/dev/null | sed 's|/||' | sort -V -r || true) | |
| # Determine the latest tag version | |
| if [ "$IS_TAG" = "true" ]; then | |
| LATEST="$VERSION" | |
| elif [ -n "$VERSIONS" ]; then | |
| LATEST=$(echo "$VERSIONS" | head -1) | |
| else | |
| LATEST="" | |
| fi | |
| cd "$GITHUB_WORKSPACE" | |
| mkdir -p extra-pages/stable | |
| # Generate versions.json | |
| python3 -c " | |
| import json | |
| versions = '${VERSIONS}'.split() | |
| latest = '${LATEST}' | |
| result = [{'name': 'main', 'url': '/motile/main/'}] | |
| for v in versions: | |
| entry = {'name': v, 'url': f'/motile/{v}/'} | |
| if v == latest: | |
| entry['latest'] = True | |
| result.append(entry) | |
| with open('extra-pages/versions.json', 'w') as f: | |
| json.dump(result, f, indent=2) | |
| " | |
| # Generate stable redirect (points to latest tag or main) | |
| if [ -n "$LATEST" ]; then | |
| TARGET="/motile/${LATEST}/" | |
| else | |
| TARGET="/motile/main/" | |
| fi | |
| cat > extra-pages/stable/index.html << STABLEEOF | |
| <!DOCTYPE html> | |
| <html> | |
| <head><meta http-equiv="refresh" content="0; url=${TARGET}"></head> | |
| <body><p>Redirecting to <a href="${TARGET}">${TARGET}</a>...</p></body> | |
| </html> | |
| STABLEEOF | |
| - name: Deploy versions.json and redirects | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_branch: docs | |
| publish_dir: extra-pages | |
| destination_dir: docs | |
| keep_files: true |