-
Notifications
You must be signed in to change notification settings - Fork 102
#29 GitHub actions to automate documentation site build on new release #100
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
Merged
dylanbouchard
merged 43 commits into
cvs-health:develop
from
DTsapetis:29-github-actions-to-automate-documentation-site-build-on-new-release
Sep 12, 2025
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
8abd429
Add files via upload
dimtsap 1852f86
Create documentation.yaml
dimtsap c96b44e
Update documentation.yaml
dimtsap cb3a656
Update documentation.yaml
dimtsap b472920
Update documentation.yaml
dimtsap 420863f
Update documentation.yaml
dimtsap a9a3e37
Update documentation.yaml
dimtsap 0b00705
Update documentation.yaml
dimtsap dda7c39
Update documentation.yaml
dimtsap a8e3b26
Update documentation.yaml
dimtsap ba54ae8
Update documentation.yaml
dimtsap 384c1aa
Update conf.py
dimtsap f060edd
Moves docs/requirements to pyproject.toml
dimtsap c0097ab
Update documentation.yaml
dimtsap f9a35ff
Update documentation.yaml
dimtsap 050ed3f
Update documentation.yaml
dimtsap 98072e0
Update documentation.yaml
dimtsap bd83c9a
Update documentation.yaml
dimtsap 10c8075
Create update_version_json.py
dimtsap 1809a3a
Update documentation.yaml
dimtsap a9dd334
Update documentation.yaml
dimtsap 284c81b
Update documentation.yaml
dimtsap 0d6d8c1
Update update_version_json.py
dimtsap 1b421dd
Update documentation.yaml
dimtsap 245f067
Update documentation.yaml
dimtsap 1757175
Update documentation.yaml
dimtsap 8abca4c
Update documentation.yaml
dimtsap a312826
Update update_version_json.py
dimtsap 4e57fe5
Update update_version_json.py
dimtsap fdc0256
Update update_version_json.py
dimtsap 04595b9
Updates version.json file
dimtsap 57c8b70
Update documentation.yaml
dimtsap 85852bd
Update documentation.yaml
dimtsap a18b25a
Update update_version_json.py
dimtsap 02facb5
Sorts gh-pages folder chronologically
dimtsap fabc65d
Sorts gh-pages folders by parsing version number
dimtsap 989954f
Removes pandoc version
dimtsap b4805da
Update Makefile
dimtsap d32b2b4
Update documentation.yaml
dimtsap ae434f9
Deletes old contents of versioned and latest folders
dimtsap 0f79ca1
Update documentation.yaml
dimtsap 71cb8c6
Create faqs.rst
dimtsap 9bfd946
Update index.rst
dimtsap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# .github/workflows/docs.yml | ||
|
||
name: Build & Deploy Sphinx Docs | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
docs: | ||
runs-on: ubuntu-latest | ||
env: | ||
PANDOC_VERSION: ${{ vars.PANDOC_VERSION }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get tag name | ||
id: get_tag | ||
run: echo "tag=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT | ||
|
||
- name: Show tag | ||
run: | | ||
echo "Tag: ${{ steps.get_tag.outputs.tag }}" | ||
|
||
- name: Extract version without "v" | ||
id: version | ||
run: | | ||
RAW_TAG="${GITHUB_REF_NAME}" | ||
VERSION="${RAW_TAG#v}" | ||
VERSION="${VERSION%.*}" | ||
echo "clean_version=$VERSION" >> $GITHUB_OUTPUT | ||
echo $clean_version | ||
|
||
- name: Update conf.py release version | ||
run: | | ||
sed -i "s/^release = .*/release = '${{ steps.version.outputs.clean_version }}'/" docs/source/conf.py | ||
head -n 20 docs/source/conf.py | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.12 | ||
|
||
- name: Install Poetry | ||
run: | | ||
pip install poetry | ||
|
||
- name: Download and install Pandoc | ||
run: | | ||
FILE="pandoc-${PANDOC_VERSION}-1-amd64.deb" | ||
URL="https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/${FILE}" | ||
|
||
echo "Downloading $FILE..." | ||
curl -L -o pandoc.deb "$URL" | ||
|
||
echo "Installing Pandoc..." | ||
sudo dpkg -i pandoc.deb | ||
|
||
- name: Verify Pandoc version | ||
run: pandoc --version | ||
|
||
- name: Install dependencies | ||
run: | | ||
poetry lock | ||
poetry install --with docs | ||
eval $(poetry env activate) | ||
|
||
- name: Checkout gh-pages branch to get versions.json | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: gh-pages | ||
path: gh-pages | ||
|
||
- name: Update version.json | ||
run: | | ||
VERSION=${{ steps.version.outputs.clean_version }} | ||
python .github/workflows/update_version_json.py "$VERSION" "gh-pages" | ||
cat gh-pages/versions.json | ||
mkdir docsVersion | ||
cp gh-pages/versions.json docsVersion/versions.json | ||
|
||
- name: Build Sphinx docs | ||
run: | | ||
eval $(poetry env activate) | ||
make -C docs clean | ||
make -C docs html | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./docsVersion | ||
keep_files: true | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./docs/build/html | ||
destination_dir: v${{ steps.version.outputs.clean_version }} | ||
keep_files: true | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./docs/build/html | ||
destination_dir: latest | ||
keep_files: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import json | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
def rebuild_version_json(current_version, gh_pages_path, site_url="https://cvs-health.github.io/uqlm"): | ||
version_json_path = Path(gh_pages_path) / "versions.json" | ||
entries = [] | ||
|
||
# List only v* folders, ignore 'latest' | ||
folders = [ | ||
p for p in Path(gh_pages_path).iterdir() | ||
if p.is_dir() and p.name.startswith("v") | ||
] | ||
|
||
folders = sorted(folders, key=lambda f: tuple([ int(x) for x in f.name[1:].split('.')]), reverse=True) | ||
|
||
entries.append({ | ||
"name": f"v{current_version} (latest)", | ||
"version": current_version, | ||
"url": f"{site_url}/latest/" | ||
}) | ||
for folder in folders: | ||
version = folder.name[1:] # strip leading 'v' | ||
entry = { | ||
"name": f"v{version}", | ||
"version": version, | ||
"url": f"{site_url}/v{version}/" | ||
} | ||
|
||
entries.append(entry) | ||
|
||
# Save version.json | ||
with open(version_json_path, "w") as f: | ||
json.dump(entries, f, indent=4) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 3: | ||
print("Usage: python rebuild_version_json.py <current_version> <gh_pages_path>") | ||
sys.exit(1) | ||
|
||
current_version = sys.argv[1] | ||
gh_pages_path = sys.argv[2] | ||
rebuild_version_json(current_version, gh_pages_path) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = source | ||
BUILDDIR = build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
# Get the parent dir name which is this docs' version | ||
VERSION := $(notdir $(CURDIR)) | ||
|
||
github: | ||
@rm -rf build/html build/doctrees source/_autosummary/*.rst | ||
@cp -rf ../../assets/* source/_static/ | ||
@cp -rf ../../examples/* source/_notebooks/examples/ | ||
@make html | ||
@mkdir -p ../../docs/$(VERSION) | ||
@rm -rf ../../docs/$(VERSION)/* | ||
@cp -a build/html/. ../../docs/$(VERSION)/ | ||
@cp ../versions.json ../../docs/versions.json | ||
|
||
local: | ||
@python -m http.server --directory ../../docs/$(VERSION)/ 8080 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@ECHO OFF | ||
|
||
pushd %~dp0 | ||
|
||
REM Command file for Sphinx documentation | ||
|
||
if "%SPHINXBUILD%" == "" ( | ||
set SPHINXBUILD=sphinx-build | ||
) | ||
set SOURCEDIR=source | ||
set BUILDDIR=build | ||
|
||
%SPHINXBUILD% >NUL 2>NUL | ||
if errorlevel 9009 ( | ||
echo. | ||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx | ||
echo.installed, then set the SPHINXBUILD environment variable to point | ||
echo.to the full path of the 'sphinx-build' executable. Alternatively you | ||
echo.may add the Sphinx directory to PATH. | ||
echo. | ||
echo.If you don't have Sphinx installed, grab it from | ||
echo.https://www.sphinx-doc.org/ | ||
exit /b 1 | ||
) | ||
|
||
if "%1" == "" goto help | ||
|
||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
goto end | ||
|
||
:help | ||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% | ||
|
||
:end | ||
popd |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to pick out just major version strings like "v0.1", "v0.2" instead of v0.1.2, v0.2.1 from TAGs. I can imagine we could have a python script to filter them out and send to
$GITHUB_OUTPUT
variable but unsure if there is a better way. If we can handle this up in the front, I hope that the other steps should overwrite to same major release doc site folder when the minor release gets pushed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can define internally your version strategy for the documentation that would be really helpful. The initial issue stated that the documentation should be triggered on new releases, this is why I used the current approach. Please let me know which versions you want to display and how the gh-pages branch should behave (folder structure, file replacement etc) to adjust it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dimtsap Thank you for continuing to work on this! :) I think your current PR folder structure looks good; it's just that we want to track up to the minor releases for the documentation site, such as "v0.1", "v0.2", ..., "v0.#". I hope there is a way to overwrite the minor release folder whenever a patch tag is pushed.
I was thinking more along the following lines, but I'm unsure if it sounds possible to make it work:
v*
tags.Show tag
step runs as it is.Set up Python
step runs to set up the Python script executable environment.Extract version without "v"
step.Is it sounded possible?