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

Adds workflow to automatically build and deploy documentation #71

Merged
merged 35 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1b2930f
adds initial docs script and workflow
chaduhduh Jun 5, 2024
a48afe3
fixes package directory
chaduhduh Jun 5, 2024
c704de5
fixes artifact source location
chaduhduh Jun 5, 2024
912c9d3
updates upload-artifact version, retrieve artifact id
chaduhduh Jun 5, 2024
abaf7d4
adds explicit step id
chaduhduh Jun 5, 2024
1c94695
adds hook request
chaduhduh Jun 6, 2024
bc9030b
adjusts hook syntax
chaduhduh Jun 6, 2024
9be3f75
updates checkout version, adds missing quote
chaduhduh Jun 6, 2024
66fd42d
adjusts data argument
chaduhduh Jun 6, 2024
7546619
removes escaped chars from payload
chaduhduh Jun 6, 2024
50bfb7f
adjusts signature args
chaduhduh Jun 6, 2024
debfee8
test adding to secrets instead of env
chaduhduh Jun 6, 2024
84e1961
adds masking for signature
chaduhduh Jun 6, 2024
7304265
adds manual and release triggers, adds support for custom version and…
chaduhduh Jun 6, 2024
68697de
fixes invalid var name
chaduhduh Jun 6, 2024
555ab75
adds missing space
chaduhduh Jun 6, 2024
cc62b96
adds additional syntax fixes
chaduhduh Jun 6, 2024
2afe217
registers release name with environment
chaduhduh Jun 6, 2024
36955cd
adjusts env logic
chaduhduh Jun 6, 2024
721d251
temporarily set release name as package name
chaduhduh Jun 6, 2024
ed61bbb
fixes broken ref comparison
chaduhduh Jun 6, 2024
1baa754
adds various configuration updates
chaduhduh Jun 6, 2024
4cde337
restores deploy, updates default max depth
chaduhduh Jun 6, 2024
049e3e3
removes branch trigger, sets default versions to latest
chaduhduh Jun 6, 2024
4c7f89b
adds additional comments
chaduhduh Jun 6, 2024
1914bad
udpates comment
chaduhduh Jun 6, 2024
49ac8ed
removes local sidebar, removes unused exclude patterns, add exclude s…
chaduhduh Jun 7, 2024
e821a86
removes the directory jumps in favor of working-directory setting
chaduhduh Aug 29, 2024
88e58e3
restore artifact creation
chaduhduh Aug 29, 2024
9a1a5a6
testing old build version
chaduhduh Aug 29, 2024
6d58084
enable artifact
chaduhduh Aug 29, 2024
51d1eab
testing with version 2.23.1
chaduhduh Aug 29, 2024
07487ac
adds test trigger
chaduhduh Aug 29, 2024
64ed456
pin Sphinx version
chaduhduh Aug 29, 2024
99dbead
restores deploy, removes test trigger
chaduhduh Aug 29, 2024
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
113 changes: 113 additions & 0 deletions .github/workflows/generate_docs.yml
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 }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ MANIFEST
_build
_generated
api
docs/sphinx/_sphinx

# Packages/installer info
*.egg
Expand Down
87 changes: 87 additions & 0 deletions docs/sphinx/conf.py
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