Develop #45
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
| # Generate Python API documentation using mkdocstrings | |
| # Outputs markdown files to docs/src/content/docs/api/python/ | |
| name: Generate Python Docs | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main, develop] | |
| workflow_dispatch: | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| python: ${{ steps.filter.outputs.python }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| filters: | | |
| python: | |
| - 'api/**/src/**/*.py' | |
| - '.github/workflows/generate-python-docs.yml' | |
| generate-docs: | |
| needs: changes | |
| if: needs.changes.outputs.python == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.13" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements-dev.txt | |
| pip install -e "api/shared[dev]" -e "api/db[dev]" -e "api/sso[dev]" \ | |
| -e "api/unidash[dev]" -e "api/admin[dev]" -e "api/backup[dev]" | |
| - name: Create output directory | |
| run: mkdir -p docs/src/content/docs/api/python | |
| - name: Generate Python documentation | |
| run: | | |
| cd docs | |
| # Generate markdown for each package | |
| python -c " | |
| from pathlib import Path | |
| import importlib | |
| import inspect | |
| packages = [ | |
| ('unidash_shared', 'shared'), | |
| ('unidash_db', 'db'), | |
| ('unidash_sso', 'sso'), | |
| ('unidash_api', 'unidash'), | |
| ('unidash_admin', 'admin'), | |
| ('unidash_backup', 'backup'), | |
| ] | |
| output_dir = Path('src/content/docs/api/python') | |
| output_dir.mkdir(parents=True, exist_ok=True) | |
| for package_name, doc_name in packages: | |
| try: | |
| module = importlib.import_module(package_name) | |
| doc = f'''--- | |
| title: {package_name} | |
| description: API reference for {package_name} | |
| --- | |
| # {package_name} | |
| ::: {package_name} | |
| ''' | |
| (output_dir / f'{doc_name}.md').write_text(doc) | |
| print(f'Generated {doc_name}.md') | |
| except ImportError as e: | |
| print(f'Skipping {package_name}: {e}') | |
| " | |
| - name: Upload generated docs | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: python-docs | |
| path: docs/src/content/docs/api/python/ | |
| retention-days: 7 | |
| generate-docs-skipped: | |
| needs: changes | |
| if: needs.changes.outputs.python != 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: echo "No Python source changes detected, skipping docs generation" |