From 2c6a27627ec521578a0638795a87c9c12be16cad Mon Sep 17 00:00:00 2001 From: Nic Cope Date: Fri, 5 Jan 2024 13:06:12 -0800 Subject: [PATCH] Generate and publish API docs to GitHub pages 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 --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 3 +++ pyproject.toml | 16 ++++++++------ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5bbee4..d37f9c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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' @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 68bc17f..9527b70 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/pyproject.toml b/pyproject.toml index e8ca1b8..e25f4ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] @@ -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" @@ -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"]