|
| 1 | +name: Update Python API reference |
| 2 | + |
| 3 | +# Regenerates src/content/docs/reference/python-api/*.md from the python-sdk |
| 4 | +# release and opens a PR when anything changed. This keeps the *source-controlled* |
| 5 | +# API reference matched to the SDK; the deploy workflow regenerates the same docs |
| 6 | +# ephemerally for the published build, but never commits them back. |
| 7 | +# |
| 8 | +# Triggers: |
| 9 | +# - repository_dispatch (sdk-release): fired by python-sdk's release workflow. |
| 10 | +# Send the released ref in client_payload.ref, e.g. from python-sdk: |
| 11 | +# - uses: peter-evans/repository-dispatch@v3 |
| 12 | +# with: |
| 13 | +# token: ${{ secrets.DOCS_DISPATCH_TOKEN }} # PAT with repo scope on the docs repo |
| 14 | +# repository: codellm-devkit/docs |
| 15 | +# event-type: sdk-release |
| 16 | +# client-payload: '{"ref": "${{ github.ref_name }}"}' |
| 17 | +# - workflow_dispatch: manual run, with an optional ref (tag/branch/sha). |
| 18 | +# - schedule: weekly safety net in case a release dispatch is ever missed. |
| 19 | + |
| 20 | +on: |
| 21 | + repository_dispatch: |
| 22 | + types: [sdk-release] |
| 23 | + workflow_dispatch: |
| 24 | + inputs: |
| 25 | + ref: |
| 26 | + description: "python-sdk ref to generate from (tag/branch/sha). Defaults to the latest release tag." |
| 27 | + required: false |
| 28 | + default: "" |
| 29 | + schedule: |
| 30 | + - cron: "0 6 * * 1" # Mondays 06:00 UTC |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: write |
| 34 | + pull-requests: write |
| 35 | + |
| 36 | +concurrency: |
| 37 | + group: update-api-docs |
| 38 | + cancel-in-progress: true |
| 39 | + |
| 40 | +jobs: |
| 41 | + regenerate: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - name: Checkout docs |
| 45 | + uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + ref: astro |
| 48 | + |
| 49 | + - name: Set up Python |
| 50 | + uses: actions/setup-python@v5 |
| 51 | + with: |
| 52 | + python-version: "3.12" |
| 53 | + |
| 54 | + - name: Clone python-sdk at the target ref |
| 55 | + id: sdk |
| 56 | + run: | |
| 57 | + set -euo pipefail |
| 58 | + git clone https://github.com/codellm-devkit/python-sdk.git ../python-sdk |
| 59 | + cd ../python-sdk |
| 60 | + # Precedence: repository_dispatch payload > workflow_dispatch input > latest release tag. |
| 61 | + REF="${{ github.event.client_payload.ref || github.event.inputs.ref }}" |
| 62 | + if [ -z "${REF}" ]; then |
| 63 | + REF=$(git tag --sort=-v:refname | head -n1) |
| 64 | + fi |
| 65 | + echo "Generating API reference from python-sdk ref: ${REF}" |
| 66 | + git checkout "${REF}" |
| 67 | + SDK_VERSION=$(python -c "import tomllib,pathlib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version'])") |
| 68 | + echo "ref=${REF}" >> "$GITHUB_OUTPUT" |
| 69 | + echo "version=${SDK_VERSION}" >> "$GITHUB_OUTPUT" |
| 70 | +
|
| 71 | + - name: Install the SDK and the generator deps |
| 72 | + run: | |
| 73 | + set -euo pipefail |
| 74 | + python -m pip install --upgrade pip |
| 75 | + # Installing cldk pulls in the codeanalyzer-* backends whose models the |
| 76 | + # schema pages re-export (needed for griffe alias resolution). |
| 77 | + pip install -e ../python-sdk |
| 78 | + pip install -r scripts/requirements.txt |
| 79 | +
|
| 80 | + - name: Regenerate API reference markdown |
| 81 | + run: python scripts/gen_api_docs.py |
| 82 | + |
| 83 | + - name: Open a PR if the reference changed |
| 84 | + uses: peter-evans/create-pull-request@v6 |
| 85 | + with: |
| 86 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + base: astro |
| 88 | + branch: auto/api-docs |
| 89 | + add-paths: src/content/docs/reference/python-api/** |
| 90 | + commit-message: "docs(api): sync Python API reference to python-sdk ${{ steps.sdk.outputs.version }}" |
| 91 | + title: "docs(api): sync Python API reference to python-sdk ${{ steps.sdk.outputs.version }}" |
| 92 | + body: | |
| 93 | + Automated regeneration of the Python API reference from |
| 94 | + [`python-sdk`](https://github.com/codellm-devkit/python-sdk) ref |
| 95 | + `${{ steps.sdk.outputs.ref }}` (version `${{ steps.sdk.outputs.version }}`). |
| 96 | +
|
| 97 | + Generated by `scripts/gen_api_docs.py` (griffe). Authored intros above the |
| 98 | + `CLDK:API:START` markers are preserved; only the generated symbol |
| 99 | + reference changed. Review the diff and merge to ship. |
| 100 | + labels: documentation, automated |
| 101 | + delete-branch: true |
0 commit comments