Skip to content

Commit a2a2db4

Browse files
committed
Add workflow and script to auto-generate API docs
Add a GitHub Actions workflow (.github/workflows/api-docs.yml) that runs on pull requests to main when torch_rechub sources or the generator change. The workflow detects source changes, sets up Python, runs config/generate_api_md.py, and commits generated docs (docs/en/api/api.md and docs/zh/api/api.md) back to the PR branch. Add config/generate_api_md.py: a script that walks torch_rechub Python files (excluding __init__.py), extracts functions/classes via the AST, formats signatures and docstrings (with parsing for common sections like Parameters, Returns, Shape, Examples), and emits localized markdown API reference files for English and Chinese.
1 parent 4f8c2f0 commit a2a2db4

4 files changed

Lines changed: 11189 additions & 0 deletions

File tree

.github/workflows/api-docs.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: API Docs
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
paths:
7+
- 'torch_rechub/**'
8+
- 'config/generate_api_md.py'
9+
- '.github/workflows/api-docs.yml'
10+
11+
env:
12+
PYTHON_VERSION: '3.9'
13+
14+
jobs:
15+
api-docs:
16+
name: Auto Generate API Docs
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v6
22+
with:
23+
token: ${{ secrets.GITHUB_TOKEN }}
24+
fetch-depth: 0
25+
ref: ${{ github.head_ref }}
26+
27+
- name: Detect API source changes
28+
id: changed-files
29+
uses: dorny/paths-filter@v3
30+
with:
31+
filters: |
32+
torch_rechub:
33+
- 'torch_rechub/**'
34+
35+
- name: Set up Python
36+
if: steps.changed-files.outputs.torch_rechub == 'true'
37+
uses: actions/setup-python@v6
38+
with:
39+
python-version: ${{ env.PYTHON_VERSION }}
40+
41+
- name: Generate API docs
42+
if: steps.changed-files.outputs.torch_rechub == 'true'
43+
run: |
44+
python config/generate_api_md.py
45+
46+
- name: Commit generated API docs
47+
if: steps.changed-files.outputs.torch_rechub == 'true' && github.event.pull_request.head.repo.full_name == github.repository
48+
run: |
49+
git config user.name "github-actions[bot]"
50+
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
git add docs/en/api/api.md docs/zh/api/api.md
52+
if git diff --staged --quiet; then
53+
echo "No API doc changes to commit"
54+
else
55+
git commit -m "docs(api): auto-generate API docs [skip ci]"
56+
git push origin HEAD:${{ github.head_ref }}
57+
fi

0 commit comments

Comments
 (0)