-
Notifications
You must be signed in to change notification settings - Fork 1
feat(template): CLI auto-doc pipeline + working docs build #17
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
Open
xaviedoanhduy
wants to merge
2
commits into
main
Choose a base branch
from
feat/cli-auto-doc-backport
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,7 @@ venv.bak/ | |
|
|
||
| # mkdocs documentation | ||
| /site | ||
| /site-docs/site | ||
|
|
||
| # mypy | ||
| .mypy_cache/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
template/{% if enable_docs_site %}.github{% endif%}/workflows/docs.yaml.jinja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: Documentation | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
| pull_request: | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: read | ||
| concurrency: | ||
| group: pages | ||
| cancel-in-progress: false | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: 3.x | ||
| - uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 | ||
| - run: uv sync --frozen | ||
| {%- if project_type == 'cli' %} | ||
| - run: uv run python scripts/gen_cli_reference.py | ||
| {%- endif %} | ||
| - run: uv run zensical build --clean -f site-docs/zensical.toml | ||
| - uses: actions/upload-pages-artifact@v5 | ||
| with: | ||
| path: site-docs/site | ||
|
|
||
| deploy: | ||
| needs: build | ||
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pages: write | ||
| id-token: write | ||
| environment: | ||
| name: github-pages | ||
| url: {{ '${{ steps.deployment.outputs.page_url }}' }} | ||
| steps: | ||
| - uses: actions/configure-pages@v6 | ||
| - uses: actions/deploy-pages@v5 | ||
| id: deployment | ||
29 changes: 0 additions & 29 deletions
29
template/{% if enable_docs_site %}.github{% endif%}/workflows/docs.yml
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...}site-docs{% endif%}/docs/{% if project_type == 'cli' %}cli-reference.md{% endif %}.jinja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| icon: lucide/book | ||
| description: Complete reference for every {{ project_name }} command, auto-generated from --help. | ||
| tags: | ||
| - reference | ||
| - cli | ||
| --- | ||
|
|
||
| !!! info "Auto-generated" | ||
| This page is regenerated from `{{ project_name }} --help` by `make cli-docs`. | ||
| Run `make docs` (or `make cli-docs`) to populate it. Do not edit by hand — | ||
| your changes will be overwritten on the next build. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...roject_type == 'cli' and enable_docs_site %}scripts{% endif %}/gen_cli_reference.py.jinja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Regenerate site-docs/docs/cli-reference.md from the Typer app. | ||
|
|
||
| Invoked by `make cli-docs` (and transitively `make docs`). Keeps the public | ||
| docs site in sync with whatever flags/commands exist in {{ package_name }}.main | ||
| without manual edits — add a flag, run `make docs`, commit the diff. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| OUT = Path(__file__).resolve().parent.parent / "site-docs" / "docs" / "cli-reference.md" | ||
|
|
||
| HEADER = """--- | ||
| icon: lucide/book | ||
| description: Complete reference for every {{ project_name }} command, auto-generated from --help. | ||
| tags: | ||
| - reference | ||
| - cli | ||
| --- | ||
|
|
||
| !!! info "Auto-generated" | ||
| This page is regenerated from `{{ project_name }} --help` by `make cli-docs`. | ||
| Do not edit by hand — your changes will be overwritten on the next build. | ||
|
|
||
| """ | ||
|
|
||
|
|
||
| def main() -> None: | ||
| # `uv` is on PATH in the dev (`make`) and CI (`setup-uv`) environments. | ||
| body = subprocess.check_output( | ||
| ["uv", "run", "typer", "{{ package_name }}.main", "utils", "docs", "--name", "{{ project_name }}"], # noqa: S607 | ||
| text=True, | ||
| ) | ||
| # Typer emits `[default: X]`, `[required]`, etc. which Zensical/Markdown | ||
| # parses as link references. Escape the brackets so they render literally. | ||
| body = re.sub( | ||
| r"\[(default|env var|required)([^\]]*)\]", | ||
| lambda m: rf"\[{m.group(1)}{m.group(2)}\]", | ||
| body, | ||
| ) | ||
| OUT.write_text(HEADER + body) | ||
| try: | ||
| rel = OUT.relative_to(Path.cwd()) | ||
| except ValueError: | ||
| rel = OUT | ||
| print(f"Wrote {rel} ({len(body.splitlines())} lines from typer)") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.