Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(hugr-py): build and publish docs #1253

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and publish docs

on:
workflow_dispatch:
push:
branches:
- main
# only run if there are changes in the hugr-py directory
paths:
- 'hugr-py/**'

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run
# in-progress and latest queued.
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
build:
name: Build docs.
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./hugr-py
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this all be happening in the hugr-py directory? Does on>push>paths do that for us?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooooh yes good catch

- name: Set up Python '3.10'
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: "poetry"
- name: Install HUGR
run: poetry install --with docs
- name: Build docs
run: |
cd docs
./build.sh
- name: Upload artifact.
uses: actions/upload-pages-artifact@v3
with:
path: ./hugr-py/docs/build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default directory is ./hugr-py, I think this is just ./docs/build?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default only applies for run steps


publish:
name: Publish docs.
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Deploy to GitHub Pages.
id: deployment
uses: actions/deploy-pages@v4
9 changes: 9 additions & 0 deletions hugr-py/docs/_static/_redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Redirecting to main branch</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./main/index.html">
<link rel="canonical" href="https://cqcl.github.io/hugr/main/index.html">
</head>
</html>
8 changes: 8 additions & 0 deletions hugr-py/docs/api-docs/_templates/versioning.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% if versions %}
<h3>{{ _('Versions') }}</h3>
<ul>
{%- for item in versions %}
<li><a href="{{ item.url }}">{{ item.name }}</a></li>
{%- endfor %}
</ul>
{% endif %}
13 changes: 13 additions & 0 deletions hugr-py/docs/api-docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"sphinx.ext.autosummary",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
"sphinx_multiversion",
]

html_theme = "sphinx_book_theme"
Expand All @@ -36,6 +37,18 @@

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "conftest.py"]
html_sidebars = {
"**": [
"navbar-logo.html",
"icon-links.html",
"search-button-field.html",
"sbt-sidebar-nav.html",
croyzor marked this conversation as resolved.
Show resolved Hide resolved
"versioning.html",
],
}

smv_branch_whitelist = "main"
smv_tag_whitelist = r"^hugr-py-.*$"

intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
Expand Down
5 changes: 3 additions & 2 deletions hugr-py/docs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
mkdir build

touch build/.nojekyll # Disable jekyll to keep files starting with underscores

sphinx-build -b html ./api-docs ./build/api-docs
# copy redirect file
cp ./_static/_redirect.html ./build/index.html
sphinx-multiversion ./api-docs ./build
16 changes: 15 additions & 1 deletion hugr-py/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hugr-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ optional = true
[tool.poetry.group.docs.dependencies]
sphinx = "^7.2.6"
sphinx-book-theme = "^1.1.2"
sphinx-multiversion = "^0.2.4"

[build-system]
requires = ["poetry-core"]
Expand Down
Loading