[WiP] Docs restructuring, DisCoCirc material #155
Workflow file for this run
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: Build and deploy documentation | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'beta' | |
- 'release' | |
pull_request: | |
workflow_dispatch: | |
release: | |
types: | |
- released | |
# We need the following permission to upload the documentation as a release asset. | |
# and to be able to deploy to GH pages (https://docs.github.com/en/pages/getting-started-with-github-pages/using-custom-workflows-with-github-pages#deploying-github-pages-artifacts) | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
env: | |
WORKFLOWS_DIR: .github/workflows | |
DOCS_DIR: docs | |
DOCS_BUILD_DIR: build | |
jobs: | |
build: | |
name: Build documentation | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 # fetches tags, required for version info | |
- name: Set up uv | |
# Install a specific uv version using the installer | |
run: curl -LsSf https://astral.sh/uv/0.4.0/install.sh | sh | |
- name: Set up Python | |
run: uv python install 3.12 | |
- name: Install documentation dependencies | |
run: | | |
sudo apt-get install graphviz pandoc | |
uv sync --dev | |
- name: Locate bobcat pre-trained model cache | |
id: loc-bobcat-cache | |
run: echo "dir=$(echo 'from lambeq.text2diagram.model_downloader import ModelDownloader; print(ModelDownloader("bert").model_dir)' | uv run - )" >> $GITHUB_OUTPUT | |
- name: Restore bobcat pre-trained model from cache | |
id: bobcat-cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.loc-bobcat-cache.outputs.dir }} | |
key: ${{ runner.os }}-bobcat-bert-v1 | |
restore-keys: | | |
${{ runner.os }}-bobcat-bert-v1 | |
${{ runner.os }}- | |
- name: Download model on cache miss | |
id: download-bobcat-model | |
if: ${{ steps.bobcat-cache.outputs.cache-hit != 'true' }} | |
continue-on-error: true | |
run: echo "dir=$(echo 'from lambeq.text2diagram.model_downloader import ModelDownloader; md = ModelDownloader("bert"); md.download_model(verbose="suppress");' | uv run - )" | |
- name: Test example notebooks | |
env: | |
TEST_NOTEBOOKS: 1 | |
run: > | |
uv run pytest --nbmake ${{ env.DOCS_DIR }}/examples/ | |
--nbmake-timeout=60 | |
- name: Test tutorial notebooks | |
env: | |
TEST_NOTEBOOKS: 1 | |
run: > | |
uv run pytest --nbmake ${{ env.DOCS_DIR }}/tutorials/ | |
--nbmake-timeout=60 | |
--ignore ${{ env.DOCS_DIR }}/tutorials/code | |
- name: Build documentation | |
env: | |
BASE_PATH: '/lambeq' | |
run: uv run ./build-docs.sh | |
- name: Zip up documentation to store as release asset | |
if: ${{ github.event_name == 'release' }} | |
run: | | |
tar -cavf lambeq-docs-${{ github.event.release.tag_name }}.tar.gz -C ${{ env.DOCS_BUILD_DIR }} . | |
- name: Add documentation artifact as release asset | |
if: ${{ github.event_name == 'release' }} | |
run: gh release upload ${{ github.event.release.tag_name }} lambeq-docs-${{ github.event.release.tag_name }}.tar.gz --clobber | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
deploy-gh: | |
name: Deploy documentation to Github pages | |
if: ${{ github.event_name == 'push' && github.ref_name == 'release' }} | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
needs: build | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 # fetches tags, required for version info | |
- name: Set up uv | |
# Install a specific uv version using the installer | |
run: curl -LsSf https://astral.sh/uv/0.4.0/install.sh | sh | |
- name: Set up Python | |
run: uv python install 3.12 | |
- name: Install documentation dependencies | |
run: | | |
sudo apt-get install graphviz pandoc | |
uv sync --dev | |
- name: Clean notebooks | |
run: | | |
uv run scripts/clean_notebooks.py -p ${{ env.DOCS_DIR }} -s | |
- name: Build documentation | |
env: | |
BASE_PATH: '/lambeq-docs' | |
run: uv run ./build-docs.sh | |
- name: Setup pages | |
id: pages | |
uses: actions/configure-pages@v3 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v2 | |
with: | |
# upload build output | |
path: ${{ env.DOCS_BUILD_DIR }} | |
- name: Deploy artifact | |
id: deployment | |
uses: actions/deploy-pages@v2 |