-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds workflow to automatically build and deploy documentation (#71)
- Loading branch information
Showing
3 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Builds and deploys the python documentation using sphinx. Live documentation | ||
# is available from the main Astro Data Lab website. | ||
name: Deploy Documentation | ||
|
||
env: | ||
# these are defaults in case these values do not get set at runtime | ||
PACKAGE_VERSION: latest | ||
RELEASE_NAME: latest | ||
EXCLUDE_PATTERNS: ../../dl/specClient.py | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
packageVersion: | ||
description: 'Package Version' | ||
required: true | ||
type: string | ||
commitSha: | ||
description: 'Commit SHA' | ||
required: true | ||
type: string | ||
release: | ||
types: [released] | ||
|
||
jobs: | ||
deploy-docs-html: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
# This step is here so that when running the workflow manually we can switch | ||
# to some specific ref that may not have a matching tag. We can rebuild the docs | ||
# with some commit and a version label eg. commitSha: 934812 packageVersion: 2.23.1 | ||
# and the version doesn't have to match an existing tag. | ||
- name: Changing commit to (defaults to event ref) ${{ github.event.inputs.commitSha }} | ||
run: | | ||
if [[ ! -z "${{ github.event.inputs.commitSha }}" ]]; then | ||
git checkout ${{ github.event.inputs.commitSha }} | ||
else | ||
echo "Already on default ref" | ||
fi | ||
# Here we either set the package version to the user provided input or the | ||
# tag. This way we can handle both a release trigger and manual trigger | ||
- name: Set package version | ||
run: | | ||
if [[ ! -z "${{ github.event.inputs.packageVersion }}" ]]; then | ||
echo PACKAGE_VERSION="${{ github.event.inputs.packageVersion }}" >> $GITHUB_ENV | ||
elif [[ "${{ github.ref_type }}" == "tag" ]]; then | ||
echo PACKAGE_VERSION="${{ github.ref_name }}" >> $GITHUB_ENV | ||
fi | ||
# We need to set some release name for our sphinx build, for now we keep it | ||
# the same as whatever the package version is | ||
- name: Set release name | ||
run: echo RELEASE_NAME="${{ env.PACKAGE_VERSION }}" >> $GITHUB_ENV | ||
|
||
# Install the deps and build the sphinx project | ||
- name: Install job dependencies | ||
run: pip install Sphinx==7.3.7 | ||
- name: Install astro-datalab dependencies | ||
run: pip install . | ||
- name: Create sphinx project | ||
working-directory: docs/sphinx | ||
run: | | ||
PACKAGE_VERSION=${{ env.PACKAGE_VERSION }} \ | ||
RELEASE_NAME=${{ env.RELEASE_NAME }} \ | ||
sphinx-apidoc -f -M -F -e \ | ||
--implicit-namespaces \ | ||
-d 3 \ | ||
-o ./_sphinx/ \ | ||
../../dl/ \ | ||
"${{ env.EXCLUDE_PATTERNS }}" | ||
# We need to tweak some things in the rst files and then run the html build. | ||
# Overwrite the conf.py file with the one from our repo and also replace any | ||
# instances of the text "dl's" with "astro-datalab's" (sphinx outputs the | ||
# name as "dl" and there is no config option for it) | ||
- name: Sync config file | ||
working-directory: docs/sphinx | ||
run: cp conf.py _sphinx/conf.py | ||
- name: Replace default text "dl's" with "astro-datalab's" in index.rst (toc) | ||
run: sed -i "s/dl's/astro-datalab's/g" docs/sphinx/_sphinx/index.rst | ||
- name: Generate html | ||
working-directory: docs/sphinx/_sphinx | ||
run: make html && ls _build/html | ||
|
||
# If we made it to this point we can upload the artifact and register the | ||
# artifact ID | ||
- uses: actions/upload-artifact@v4 | ||
id: upload-html | ||
with: | ||
name: api-docs-html-${{ env.PACKAGE_VERSION }} | ||
path: docs/sphinx/_sphinx/_build/html/ | ||
retention-days: 1 | ||
overwrite: true | ||
- name: Set artifact id | ||
run: echo ARTIFACT_ID="${{ steps.upload-html.outputs.artifact-id }}" >> $GITHUB_ENV | ||
|
||
# Prepare our hook data and send "deploy-docs" event | ||
- name: Set payload data | ||
run: echo HOOK_DATA='{"repository":{"name":"datalab"},"event":"deploy-docs","artifact_id":"${{ env.ARTIFACT_ID }}"}' >> $GITHUB_ENV | ||
- name: Generate signature | ||
run: | | ||
SIG=$(echo -n '${{ env.HOOK_DATA }}' | openssl dgst -sha256 -hmac "${{ secrets.APIDOCS_DEPLOY_KEY }}" -hex | sed s/.*\(stdin\)//g | sed s/=//g ) | ||
echo "::add-mask::$SIG" | ||
echo SIG=$SIG >> $GITHUB_ENV | ||
- name: Dispatch hook | ||
run: | | ||
curl --fail \ | ||
-d '${{ env.HOOK_DATA }}' \ | ||
-H "X-Hub-Signature-256: ${{ env.SIG }}" \ | ||
"${{ secrets.APIDOCS_HOOK_URL }}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ MANIFEST | |
_build | ||
_generated | ||
api | ||
docs/sphinx/_sphinx | ||
|
||
# Packages/installer info | ||
*.egg | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file only contains a selection of the most common options. For a full | ||
# list see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Path setup -------------------------------------------------------------- | ||
|
||
# If extensions (or modules to document with autodoc) are in another directory, | ||
# add these directories to sys.path here. If the directory is relative to the | ||
# documentation root, use os.path.abspath to make it absolute, like shown here. | ||
# | ||
# import os | ||
# import sys | ||
# sys.path.insert(0, os.path.abspath("../")) | ||
import os | ||
from datetime import datetime | ||
|
||
# -- Project information ----------------------------------------------------- | ||
|
||
project = 'astro-datalab' | ||
copyright = f'{datetime.now().year}, Association of Universities for Research in Astronomy, Inc. (AURA)' | ||
author = 'Astro Data Lab team' | ||
|
||
# The short X.Y version | ||
version = os.environ['PACKAGE_VERSION'] | ||
|
||
# The full version, including alpha/beta/rc tags | ||
release = os.environ['RELEASE_NAME'] | ||
|
||
|
||
# -- General configuration --------------------------------------------------- | ||
|
||
# Add any Sphinx extension module names here, as strings. They can be | ||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom | ||
# ones. | ||
extensions = [ | ||
'sphinx.ext.autodoc', | ||
'sphinx.ext.viewcode', | ||
'sphinx.ext.todo', | ||
'sphinx.ext.napoleon', | ||
] | ||
|
||
# The language for content autogenerated by Sphinx. Refer to documentation | ||
# for a list of supported languages. | ||
# | ||
# This is also used if you do content translation via gettext catalogs. | ||
# Usually you set "language" from the command line for these cases. | ||
language = 'en' | ||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
|
||
# The theme to use for HTML and HTML Help pages. See the documentation for | ||
# a list of builtin themes. | ||
# | ||
html_theme = 'classic' | ||
|
||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. | ||
# | ||
html_show_sphinx = False | ||
|
||
# The name of an image file (relative to this directory) to place at the top | ||
# of the sidebar. | ||
# | ||
html_logo = 'https://datalab.noirlab.edu/assets/shared/images/datalab-logo.jpg' | ||
|
||
# Add any paths that contain custom static files (such as style sheets) here, | ||
# relative to this directory. They are copied after the builtin static files, | ||
# so a file named "default.css" will overwrite the builtin "default.css". | ||
html_static_path = ['_static'] | ||
|
||
# See here for a full list of sidebar options https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars | ||
html_sidebars = { | ||
'**': [ | ||
'relations.html', | ||
'globaltoc.html', | ||
'sourcelink.html', | ||
'searchbox.html' | ||
], | ||
} | ||
|
||
# -- Extension configuration ------------------------------------------------- | ||
|
||
# -- Options for todo extension ---------------------------------------------- | ||
|
||
# If true, `todo` and `todoList` produce output, else they produce nothing. | ||
todo_include_todos = False |