Skip to content

Publish Sphinx Docs to GitHub Pages #903

Publish Sphinx Docs to GitHub Pages

Publish Sphinx Docs to GitHub Pages #903

Workflow file for this run

name: Publish Sphinx Docs to GitHub Pages
on:
# Build the docs on pushes to main branch, PRs to main branch, and new tags.
# Publish only on demand.
push:
branches:
- main
tags:
- '*' # all tags
pull_request:
branches:
- main
workflow_dispatch: # allow manual triggering
inputs:
deploy:
description: 'Deploy documentation'
type: boolean
required: true
default: false
defaults:
run:
shell: bash -l {0}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
docs:
name: Publish documentation
runs-on: ubuntu-latest
steps:
- name: Deploy Information
if: ${{ github.event.inputs.deploy }}
run: |
echo "The docs will be published from this workflow run."
- name: Set timezone
uses: szenius/[email protected]
with:
timezoneLinux: "America/Chicago"
- name: Make Temporary Directory for Sphinx content
run: |
echo "SRC_DIR=$(pwd)" >> ${GITHUB_ENV}
echo "TMP_DIR=$(mktemp -d)" >> ${GITHUB_ENV}
- name: install pandoc in the OS
run: |
set -vxeuo pipefail
sudo apt-get update && \
sudo apt-get -y install pandoc
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install our package and its requirements
run: pip install -e .[doc] -vv
- name: Show Environment variables
run: |
echo "SRC_DIR=${SRC_DIR}"
echo "TMP_DIR=${TMP_DIR}"
- name: Sphinx
run: sphinx-build -M html ./docs/source "${TMP_DIR}/build"
- name: Define ... HTML_DIR
run: echo "HTML_DIR=${TMP_DIR}/build/html" >> ${GITHUB_ENV}
- name: Diagnostics
run: ls -lAFghR "${HTML_DIR}"
- name: Upload Docs ZIP file as artifact
uses: actions/upload-artifact@v6
with:
name: hklpy2-docs
path: ${{ env.HTML_DIR }}
- name: Deploy (to gh-pages branch) only on demand
uses: peaceiris/actions-gh-pages@v4
if: ${{ github.event.inputs.deploy }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ${{ env.HTML_DIR }}