Merge branch 'main' into dev #656
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: Docs (GitHub Pages) CI | |
| on: | |
| push: | |
| branches: [documentation, dev, main] | |
| tags: ['v*'] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: docs-pages-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # Gate: for tag pushes, skip the whole pipeline if the commit is not on main. | |
| # Branch pushes always pass through. | |
| gate: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_build: ${{ steps.check.outputs.should_build }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check whether docs should build | |
| id: check | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| git fetch origin main | |
| TAG_COMMIT="$(git rev-list -n 1 "${{ github.ref }}")" | |
| IS_ON_MAIN=$(git merge-base --is-ancestor "${TAG_COMMIT}" origin/main \ | |
| && echo "true" || echo "false") | |
| echo "should_build=${IS_ON_MAIN}" >> $GITHUB_OUTPUT | |
| echo "Tag on main: ${IS_ON_MAIN}" | |
| else | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| fi | |
| build: | |
| needs: gate | |
| if: ${{ needs.gate.outputs.should_build == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install docs dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install -r docs/requirements.txt | |
| python -m pip install numpy pandas tqdm PyYAML | |
| - name: Build Sphinx multiversion docs | |
| run: sphinx-multiversion docs docs/_build/html | |
| - name: Prepare latest alias and versions manifest | |
| shell: bash | |
| run: | | |
| python - <<'PY' | |
| import json | |
| import re | |
| import shutil | |
| from pathlib import Path | |
| root = Path("docs/_build/html") | |
| main_dir = root / "main" | |
| latest_dir = root / "latest" | |
| if main_dir.exists(): | |
| shutil.copytree(main_dir, latest_dir, dirs_exist_ok=True) | |
| versions = [] | |
| semver = re.compile(r"^v(\d+)\.(\d+)\.(\d+)$") | |
| for d in root.iterdir(): | |
| if not d.is_dir() or not (d / "index.html").exists(): | |
| continue | |
| name = d.name | |
| if name not in {"latest", "documentation", "dev"} and not semver.match(name): | |
| continue | |
| if name == "latest": | |
| rank = (0, 0, 0, 0) | |
| label = "latest" | |
| elif name == "dev": | |
| rank = (1, 0, 0, 0) | |
| label = "dev" | |
| elif name == "documentation": | |
| rank = (2, 0, 0, 0) | |
| label = "documentation" | |
| else: | |
| m = semver.match(name) | |
| rank = (3, -int(m.group(1)), -int(m.group(2)), -int(m.group(3))) | |
| label = name | |
| versions.append({"name": name, "label": label, "rank": rank}) | |
| versions.sort(key=lambda v: v["rank"]) | |
| payload = [{"name": v["name"], "label": v["label"]} for v in versions] | |
| (root / "versions.json").write_text(json.dumps(payload, indent=2), encoding="utf-8") | |
| for v in payload: | |
| (root / v["name"] / "versions.json").write_text(json.dumps(payload, indent=2), encoding="utf-8") | |
| if payload: | |
| default_name = payload[0]["name"] | |
| redirect = f"""<!doctype html> | |
| <html><head> | |
| <meta charset=\"utf-8\" /> | |
| <meta http-equiv=\"refresh\" content=\"0; url=./{default_name}/index.html\" /> | |
| <title>WeightsLab Docs</title> | |
| </head><body> | |
| Redirecting to <a href=\"./{default_name}/index.html\">{default_name}</a>. | |
| </body></html> | |
| """ | |
| (root / "index.html").write_text(redirect, encoding="utf-8") | |
| PY | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: docs/_build/html | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: [gate, build] | |
| if: ${{ needs.gate.outputs.should_build == 'true' }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |