Skip to content

Commit 2479a94

Browse files
committed
Make review PR creation only work for updates, not new packages.
1 parent 317bd4c commit 2479a94

7 files changed

Lines changed: 35 additions & 82 deletions

File tree

.github/skills/create-api-review-pr/SKILL.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ description: Create a GitHub PR for API review by comparing a baseline API surfa
77

88
Creates a dedicated API review PR that shows the diff between a baseline release and a target branch's API surface using `scripts/api_md_workflow/create_api_review_pr.js`.
99

10+
## Unsupported Requests
11+
12+
If the user asks to create an API review PR for a new package, explain that new packages do not use API review PRs and stop. Do not gather script inputs or run `create_api_review_pr.js` for new packages.
13+
1014
## Prerequisites
1115

1216
1. The user must have `gh` CLI authenticated (`gh auth login`).
@@ -21,11 +25,10 @@ Ask the user for the following using `vscode_askQuestions`:
2125
### 1. Package Name (required)
2226
The Azure SDK package name (e.g. `azure-storage-blob`, `azure-ai-projects`).
2327

24-
### 2. Baseline (optional)
28+
### 2. Baseline (required)
2529
The release tag to use as the baseline for comparison. Tags follow the format `<package-name>_<version>` (e.g. `azure-storage-blob_12.29.0`).
2630

2731
- If the user provides a package name and version separately, construct the tag as `<package-name>_<version>`.
28-
- If this is a **new package** with no prior release, the baseline should be omitted (the script handles this as an empty baseline).
2932

3033
### 3. Target (optional)
3134
The branch or PR to generate the "current" API surface from. Can be:
@@ -38,15 +41,15 @@ The branch or PR to generate the "current" API surface from. Can be:
3841
Before running the script:
3942

4043
1. **Validate the package exists**: Confirm a directory matching `sdk/*/<package-name>` exists with a `pyproject.toml` or `setup.py`.
41-
2. **Validate the baseline tag** (if provided): Run `git tag -l "<tag>"` to confirm the tag exists. If the user provided a version like `12.29.0`, construct the full tag as `<package-name>_<version>` and validate that.
44+
2. **Validate the baseline tag**: Run `git tag -l "<tag>"` to confirm the tag exists. If the user provided a version like `12.29.0`, construct the full tag as `<package-name>_<version>` and validate that.
4245
3. **Confirm the working tree is clean**: Run `git status --porcelain` and warn if there are uncommitted changes.
4346

4447
## Execution
4548

4649
Run the following command from the repository root:
4750

4851
```bash
49-
node scripts/api_md_workflow/create_api_review_pr.js --package-name <package-name> [--base <tag>] [--target <target>]
52+
node scripts/api_md_workflow/create_api_review_pr.js --package-name <package-name> --base <tag> [--target <target>]
5053
```
5154

5255
### Examples
@@ -61,16 +64,11 @@ node scripts/api_md_workflow/create_api_review_pr.js --package-name azure-storag
6164
node scripts/api_md_workflow/create_api_review_pr.js --package-name azure-cosmos --base azure-cosmos_4.14.0
6265
```
6366

64-
**New package (no baseline):**
65-
```bash
66-
node scripts/api_md_workflow/create_api_review_pr.js --package-name azure-keyvault-secrets --target main
67-
```
68-
6967
## Post-Execution
7068

7169
The script will:
7270
1. Generate `API.md` for both baseline and target
73-
2. Push `base_<package>_<version>` and `review_<package>_<version>` branches
71+
2. Push `apireview/base_<package>_<version>` and `apireview/review_<package>_<version>` branches
7472
3. Open a draft PR (or print a compare URL if `gh pr create` fails)
7573

7674
Report the PR URL to the user when complete.

.github/workflows/src/api-md-consistency/api-md-consistency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function formatIssueSection(title, apiFiles) {
4444
const packageName = path.basename(packageDir);
4545
lines.push(`- ${packageDir}`);
4646
lines.push(` API file: ${apiFile}`);
47-
lines.push(` Regenerate: azpysdk apistub --md --extract-metadata ${packageName} --dest-dir ${packageDir}`);
47+
lines.push(` Regenerate: azpysdk apistub --md --extract-metadata ${packageName} --dest-dir .`);
4848
}
4949
lines.push("");
5050
return lines.join("\n");

scripts/api_md_workflow/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ It runs on pull requests for changes under `sdk/**`.
2222
- Regenerates `api.md` for those packages.
2323
- Fails if the generated files differ from the committed files.
2424
- 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 <package-dir>` command needed to regenerate each `api.md` file.
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.
2626

2727
## Script Layout
2828

@@ -49,7 +49,7 @@ Also writes `count=<n>` to `GITHUB_OUTPUT`.
4949

5050
### `regenerate.js`
5151

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.
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.
5353

5454
This script is used by the consistency check.
5555

@@ -100,4 +100,4 @@ Common variables include:
100100
3. `find_affected.js` determines which packages were touched.
101101
4. `regenerate.js` rebuilds `api.md` for those packages.
102102
5. `find_mismatches.js` records any `api.md` drift, including missing or untracked `api.md` files.
103-
6. If drift is found, the workflow fails and prints the affected packages plus the `azpysdk apistub --md --extract-metadata <package-name> --dest-dir <package-dir>` command to regenerate each `api.md` file locally.
103+
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.

scripts/api_md_workflow/create_api_review_pr.js

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ function parseArgs(argv) {
6969
throw new Error("Missing required --package-name");
7070
}
7171

72+
if (!args.base) {
73+
throw new Error("Missing required --base");
74+
}
75+
7276
return args;
7377
}
7478

@@ -833,28 +837,22 @@ async function main() {
833837

834838
git(["fetch", REMOTE, "main"]);
835839

836-
let baseVersion = "none";
837-
if (args.base) {
838-
baseVersion = validateBaseTag(args.packageName, args.base);
839-
}
840+
const baseVersion = validateBaseTag(args.packageName, args.base);
840841

841842
const targetRef = args.target ? resolveTargetRef(args.target) : MAIN_REF;
842843

843844
try {
844-
let baseResult = null;
845-
if (args.base) {
846-
logInfo(`\n=== Capturing baseline api.md from tag ${args.base} ===`);
847-
baseResult = await generateApiBytesForRef({
848-
adapter,
849-
repoRoot: REPO_ROOT,
850-
packageName: args.packageName,
851-
packageDir,
852-
runtimeExecutable: args.runtimeExecutable,
853-
ref: args.base,
854-
refLabel: args.base,
855-
logger,
856-
});
857-
}
845+
logInfo(`\n=== Capturing baseline api.md from tag ${args.base} ===`);
846+
const baseResult = await generateApiBytesForRef({
847+
adapter,
848+
repoRoot: REPO_ROOT,
849+
packageName: args.packageName,
850+
packageDir,
851+
runtimeExecutable: args.runtimeExecutable,
852+
ref: args.base,
853+
refLabel: args.base,
854+
logger,
855+
});
858856

859857
logInfo(`\n=== Capturing target api.md from ${targetRef} ===`);
860858
const targetResult = await generateApiBytesForRef({
@@ -893,41 +891,13 @@ async function main() {
893891
} else {
894892
logInfo(`\n=== Creating base branch ${baseBranch} ===`);
895893
git(["checkout", "-B", baseBranch, MAIN_REF]);
896-
897-
if (baseResult !== null) {
898-
writeBytes(apiPath, baseResult.apiMd);
899-
git(["add", apiRelative]);
900-
if (baseResult.metadata) {
901-
writeBytes(metaFilePath, baseResult.metadata);
902-
git(["add", metaRelative]);
903-
}
904-
git(["commit", "-m", `[API Review] Baseline api.md for ${args.packageName} ${baseVersion}`]);
905-
} else {
906-
const tracked = git(["ls-files", "--error-unmatch", apiRelative], {
907-
capture: true,
908-
check: false,
909-
});
910-
911-
if (tracked.status === 0) {
912-
git(["rm", apiRelative]);
913-
const metaTracked = git(["ls-files", "--error-unmatch", metaRelative], {
914-
capture: true,
915-
check: false,
916-
});
917-
if (metaTracked.status === 0) {
918-
git(["rm", metaRelative]);
919-
}
920-
git(["commit", "-m", `[API Review] Remove api.md for ${args.packageName} (empty baseline)`]);
921-
} else {
922-
if (fs.existsSync(apiPath)) {
923-
fs.unlinkSync(apiPath);
924-
}
925-
if (fs.existsSync(metaFilePath)) {
926-
fs.unlinkSync(metaFilePath);
927-
}
928-
git(["commit", "--allow-empty", "-m", `[API Review] Empty baseline for ${args.packageName}`]);
929-
}
894+
writeBytes(apiPath, baseResult.apiMd);
895+
git(["add", apiRelative]);
896+
if (baseResult.metadata) {
897+
writeBytes(metaFilePath, baseResult.metadata);
898+
git(["add", metaRelative]);
930899
}
900+
git(["commit", "-m", `[API Review] Baseline api.md for ${args.packageName} ${baseVersion}`]);
931901

932902
git(["push", "--force-with-lease", REMOTE, baseBranch]);
933903
}

sdk/template/azure-template/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ namespace azure.template.template_code
99
def azure.template.template_code.template_main() -> bool: ...
1010

1111

12-
```
12+
```

sdk/template/azure-template/sdk/template/azure-template/api.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

sdk/template/azure-template/sdk/template/azure-template/api.metadata.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)