Skip to content

Commit

Permalink
Generate and publish API docs to GitHub pages
Browse files Browse the repository at this point in the history
I suspect we'll need a more actively maintained docs tool that supports
versions etc in future. Unfortunately Sphinx and Pydoc both seem more
heavyweight than I'd like right now, and I can't find any other great
options.

Signed-off-by: Nic Cope <[email protected]>
  • Loading branch information
negz committed Jan 5, 2024
1 parent 4569ef1 commit 2c6a276
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ on:
description: PyPI project version (e.g. v0.1.0)
required: false

# 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. However, do NOT cancel in-progress runs as we
# want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

env:
# Common versions
PYTHON_VERSION: '3.11.5'
Expand Down Expand Up @@ -113,3 +126,36 @@ jobs:
# be enabled, which makes sharing the account hard. We're waiting for
# a crossplane org to be approved.
password: ${{ secrets.PYPI_API_TOKEN }}


docs:
# The simple docs tool we're using doesn't support versions, so our docs
# will only reflect what's in main.
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Setup Hatch
run: pipx install hatch==1.7.0

- name: Build Documentation
run: hatch run docs:pdoc -d google crossplane/function -o docs

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# We don't commit our docs - instead we generate them and upload to GitHub pages.
docs
16 changes: 10 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
]

dependencies = [
"grpcio==1.*",
"grpcio-reflection==1.*",
"structlog==23.*",
]
dependencies = ["grpcio==1.*", "grpcio-reflection==1.*", "structlog==23.*"]

dynamic = ["version"]

Expand All @@ -31,7 +27,7 @@ Source = "https://github.com/crossplane/function-sdk-python"

[tool.hatch.version]
path = "crossplane/function/__version__.py"
validate-bump = false # Allow going from 0.0.0.dev0+x to 0.0.0.dev0+y.
validate-bump = false # Allow going from 0.0.0.dev0+x to 0.0.0.dev0+y.

[tool.hatch.envs.default]
type = "virtual"
Expand Down Expand Up @@ -63,6 +59,14 @@ path = ".venv-test"
[tool.hatch.envs.test.scripts]
unit = "python -m unittest tests/*.py"

[tool.hatch.envs.docs]
type = "virtual"
path = ".venv-docs"
dependencies = ["pdoc"]

[tool.hatch.envs.docs.scripts]
generate = "pdoc -m google crossplane/function -o docs"

[tool.hatch.build.targets.wheel]
packages = ["crossplane"]

Expand Down

0 comments on commit 2c6a276

Please sign in to comment.