|
| 1 | +name: Core / Check API reference changes |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "integrations/**/*.py" |
| 7 | + - "integrations/**/config_docusaurus.yml" |
| 8 | + |
| 9 | +jobs: |
| 10 | + test-api-reference-build: |
| 11 | + runs-on: ubuntu-slim |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v6 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + |
| 17 | + - name: Set up Python |
| 18 | + uses: actions/setup-python@v6 |
| 19 | + with: |
| 20 | + python-version: "3.13" |
| 21 | + |
| 22 | + - name: Detect integrations with API reference changes |
| 23 | + id: changed |
| 24 | + shell: python |
| 25 | + run: | |
| 26 | + import json |
| 27 | + import os |
| 28 | + import subprocess |
| 29 | + import sys |
| 30 | + from pathlib import Path |
| 31 | +
|
| 32 | + sys.path.insert(0, ".github/utils") |
| 33 | + from docstrings_checksum import docstrings_checksum |
| 34 | +
|
| 35 | + def git(*args): |
| 36 | + result = subprocess.run(["git", *args], capture_output=True, text=True) |
| 37 | + return result.stdout.strip(), result.returncode |
| 38 | +
|
| 39 | + runner_temp = os.environ["RUNNER_TEMP"] |
| 40 | + base_sha, _ = git("rev-parse", "HEAD^1") |
| 41 | +
|
| 42 | + # Get all changed files |
| 43 | + diff_output, _ = git( |
| 44 | + "diff", "--name-only", f"{base_sha}...HEAD", "--", "integrations" |
| 45 | + ) |
| 46 | + changed_files = set(diff_output.splitlines()) |
| 47 | +
|
| 48 | + # Extract integration names |
| 49 | + candidates = sorted({ |
| 50 | + Path(p).parts[1] |
| 51 | + for p in changed_files |
| 52 | + if p.startswith("integrations/") and len(Path(p).parts) > 1 |
| 53 | + }) |
| 54 | +
|
| 55 | + # Create base worktree for docstring comparison |
| 56 | + base_worktree = os.path.join(runner_temp, "base") |
| 57 | + _, return_code = git("worktree", "add", base_worktree, base_sha) |
| 58 | + has_worktree = return_code == 0 |
| 59 | +
|
| 60 | + changed_integrations = [] |
| 61 | +
|
| 62 | + for integration in candidates: |
| 63 | + # If pydoc config changed, always include |
| 64 | + if f"integrations/{integration}/pydoc/config_docusaurus.yml" in changed_files: |
| 65 | + changed_integrations.append(integration) |
| 66 | + continue |
| 67 | +
|
| 68 | + # Otherwise, check if docstrings changed |
| 69 | + pr_docstrings_checksum = docstrings_checksum(Path(".").glob(f"integrations/{integration}/**/*.py")) |
| 70 | + base_docstrings_checksum = "" |
| 71 | + if has_worktree: |
| 72 | + base_docstrings_checksum = docstrings_checksum(Path(base_worktree).glob(f"integrations/{integration}/**/*.py")) |
| 73 | +
|
| 74 | + if base_docstrings_checksum != pr_docstrings_checksum: |
| 75 | + changed_integrations.append(integration) |
| 76 | +
|
| 77 | + print(f"Integrations with API reference changes: {json.dumps(changed_integrations)}") |
| 78 | +
|
| 79 | + with open(os.environ["GITHUB_OUTPUT"], "a") as f: |
| 80 | + f.write(f"integrations={json.dumps(changed_integrations)}\n") |
| 81 | +
|
| 82 | + - name: Install Hatch |
| 83 | + if: steps.changed.outputs.integrations != '[]' |
| 84 | + run: pip install --upgrade hatch |
| 85 | + |
| 86 | + - name: Generate API references |
| 87 | + if: steps.changed.outputs.integrations != '[]' |
| 88 | + env: |
| 89 | + INTEGRATIONS: ${{ steps.changed.outputs.integrations }} |
| 90 | + run: | |
| 91 | + mkdir -p website |
| 92 | + for integration in $(echo "$INTEGRATIONS" | jq -r '.[]'); do |
| 93 | + echo "" |
| 94 | + echo "--- Generating API reference for $integration ---" |
| 95 | + cd "integrations/$integration" |
| 96 | + hatch run docs |
| 97 | + # Move the generated file to a 'website' folder for testing |
| 98 | + mv "$integration.md" ../../website/ |
| 99 | + cd ../.. |
| 100 | + done |
| 101 | +
|
| 102 | + - name: Set up Node.js |
| 103 | + if: steps.changed.outputs.integrations != '[]' |
| 104 | + uses: actions/setup-node@v6 |
| 105 | + with: |
| 106 | + node-version: "22" |
| 107 | + |
| 108 | + - name: Run Docusaurus md/mdx checker |
| 109 | + if: steps.changed.outputs.integrations != '[]' |
| 110 | + working-directory: website |
| 111 | + run: | |
| 112 | + npx docusaurus-mdx-checker -v || { |
| 113 | + echo "" |
| 114 | + echo "For common MDX problems, see https://docusaurus.io/blog/preparing-your-site-for-docusaurus-v3#common-mdx-problems" |
| 115 | + exit 1 |
| 116 | + } |
0 commit comments