|
1 | | -# api.md Workflow Helpers |
| 1 | +# API Review PR Helper |
2 | 2 |
|
3 | | -This folder contains the helper scripts used by the GitHub Actions workflows that validate and update `api.md` files for changed SDK packages. |
| 3 | +This folder contains the standalone Python helper used to create API review PRs from generated `api.md` files. |
4 | 4 |
|
5 | 5 | ## Purpose |
6 | 6 |
|
7 | | -The workflow validates that when a pull request changes one or more SDK packages, the committed `api.md` files are still up to date. |
8 | | -`api.md` content is diff-gated by this workflow, and `api.metadata.yml` must be committed alongside it. |
9 | | -The workflow also validates adapter-selected metadata fields, such as `apiMdSha256` and `parserVersion`, so metadata differences can affect pass/fail. |
| 7 | +`create_api_review_pr.py` compares a baseline package release tag with a target API surface, creates or reuses dedicated API review branches, and opens a draft PR that shows the `api.md` diff. |
10 | 8 |
|
11 | | -The logic is split between GitHub workflow YAML files and helper scripts in Python and JavaScript. |
| 9 | +The API consistency workflow helpers live under `.github/workflows/src/api-md-consistency`. |
12 | 10 |
|
13 | | -## Workflow Files |
| 11 | +## Usage |
14 | 12 |
|
15 | | -### `.github/workflows/api-consistency.yml` |
| 13 | +The script includes Python package discovery, version parsing, `api.md` generation, git branch orchestration, and GitHub PR creation in one file. |
16 | 14 |
|
17 | | -This is the main workflow. |
18 | | - |
19 | | -It runs on pull requests for changes under `sdk/**`. |
20 | | - |
21 | | -- Detects affected package directories from the PR diff. |
22 | | -- Regenerates `api.md` for those packages. |
23 | | -- Fails if the generated files differ from the committed files. |
24 | | -- Fails if an affected package does not have a committed `api.md`. |
25 | | -- Prints the mismatched or missing packages and the `azpysdk apistub --md --extract-metadata <package-name> --dest-dir .` command needed to regenerate each `api.md` file from the repository root. |
26 | | - |
27 | | -## Script Layout |
28 | | - |
29 | | -### `common.js` |
30 | | - |
31 | | -Shared helpers used by the other scripts: |
32 | | - |
33 | | -- repository root resolution |
34 | | -- subprocess execution |
35 | | -- reading/writing line-based artifact files |
36 | | -- writing GitHub Actions outputs |
37 | | -- GitHub REST API helpers for listing/updating comments |
38 | | - |
39 | | -### `find_affected.js` |
40 | | - |
41 | | -Used by the `consistency` job. |
42 | | - |
43 | | -Reads `API_MD_BASE_REF`, compares the PR branch to `origin/<base>`, and writes: |
44 | | - |
45 | | -- changed package directories to `API_MD_CHANGED_FILE` |
46 | | -- valid package roots to `API_MD_PACKAGES_FILE` |
47 | | - |
48 | | -Also writes `count=<n>` to `GITHUB_OUTPUT`. |
49 | | - |
50 | | -### `regenerate.js` |
51 | | - |
52 | | -Reads package directories from `API_MD_PACKAGES_FILE` and runs `azpysdk apistub --md --extract-metadata <package-name> --dest-dir <package-dir>` for each package from the repository root. |
53 | | - |
54 | | -This script is used by the consistency check. |
55 | | - |
56 | | -### `find_mismatches.js` |
57 | | - |
58 | | -Reads package directories from `API_MD_PACKAGES_FILE`, checks whether `<package>/api.md` is missing/untracked or differs from git, and writes: |
59 | | - |
60 | | -- mismatched files to `API_MD_MISMATCHES_FILE` |
61 | | -- missing files to `API_MD_MISSING_FILE` |
62 | | - |
63 | | -Also writes `mismatch_count=<n>`, `missing_count=<n>`, and `issue_count=<n>` to `GITHUB_OUTPUT`. |
64 | | - |
65 | | -`api.metadata.yml` is also required and selected metadata fields are mismatch-checked according to the active adapter. |
66 | | - |
67 | | -### `create_api_review_pr.js` and adapters |
68 | | - |
69 | | -API review PR creation now uses a shared JavaScript orchestrator with a language adapter boundary: |
70 | | - |
71 | | -- `create_api_review_pr.js`: shared git/branch/PR orchestration logic. |
72 | | -- `adapters/python.js`: Python-specific package discovery, version parsing, and `api.md` generation. |
73 | | - |
74 | | -This split allows the core workflow to be reused across other language repos while keeping generation behavior language-specific. |
75 | | - |
76 | | -`create_api_review_pr.js` compares a baseline package release tag with a target API surface. The target can be a package release tag, an `origin` branch, or an `owner:branch` fork reference. When the target is a tag, the generated PR body identifies it as a target tag instead of a working branch. |
| 15 | +`create_api_review_pr.py` compares a baseline package release tag with a target API surface. The target can be a package release tag, an `origin` branch, or an `owner:branch` fork reference. When the target is a tag, the generated PR body identifies it as a target tag instead of a working branch. |
77 | 16 |
|
78 | 17 | Example comparing two package release tags: |
79 | 18 |
|
80 | 19 | ```bash |
81 | | -node scripts/api_md_workflow/create_api_review_pr.js --package-name azure-ai-projects --base azure-ai-projects_2.1.0 --target azure-ai-projects_2.2.0 |
| 20 | +python scripts/api_md_workflow/create_api_review_pr.py --package-name azure-ai-projects --base azure-ai-projects_2.1.0 --target azure-ai-projects_2.2.0 |
82 | 21 | ``` |
83 | | - |
84 | | -### `api_md_workflow.config.json` |
85 | | - |
86 | | -Shared configuration for adapter selection across `api_md_workflow` scripts. |
87 | | - |
88 | | -- `adapter`: default adapter name (for this repo: `python`) |
89 | | - |
90 | | -Both `create_api_review_pr.js` and `find_affected.js` read this file for adapter selection. |
91 | | - |
92 | | -## Environment Variables Used |
93 | | - |
94 | | -The scripts are intentionally simple and read inputs from environment variables set by the workflow steps. |
95 | | - |
96 | | -Common variables include: |
97 | | - |
98 | | -- `API_MD_BASE_REF` |
99 | | -- `API_MD_PACKAGES_FILE` |
100 | | -- `API_MD_CHANGED_FILE` |
101 | | -- `API_MD_MISMATCHES_FILE` |
102 | | -- `API_MD_MISSING_FILE` |
103 | | - |
104 | | -## End-to-End Flow |
105 | | - |
106 | | -1. A PR changes files under `sdk/**`. |
107 | | -2. `consistency.yml` runs. |
108 | | -3. `find_affected.js` determines which packages were touched. |
109 | | -4. `regenerate.js` rebuilds `api.md` for those packages. |
110 | | -5. `find_mismatches.js` records any `api.md` drift, including missing or untracked `api.md` files. |
111 | | -6. If drift is found, the workflow fails and prints the affected packages plus the `azpysdk apistub --md --extract-metadata <package-name> --dest-dir .` command to regenerate each `api.md` file locally from the repository root. |
0 commit comments