Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fd2ab3d
Add generate_api_text.py script.
tjprescott May 28, 2026
ebb3870
Add PR creation script.
tjprescott May 29, 2026
2d24fa9
Review feedback.
tjprescott May 29, 2026
e4b2876
Add scripts for syncing api.md
tjprescott Jun 2, 2026
dd1b565
Refactor create_api_review_pr from Python to JS in a module way.
tjprescott Jun 2, 2026
688e16f
Remove update process and just have a consistency check.
tjprescott Jun 2, 2026
323d4f3
Add minor change to azure-template to test pipeline.
tjprescott Jun 2, 2026
93184af
Add API.md to test mismatch.
tjprescott Jun 2, 2026
7680ff6
Apply actual api.md
tjprescott Jun 2, 2026
33c39cf
Update GitHub Actions to latest major versions
Copilot Jun 3, 2026
15534d7
Add shared JS scripts from rest-api-specs repo.
tjprescott Jun 3, 2026
19f65ac
Refactor scripts to use shared code and simplify.
tjprescott Jun 3, 2026
9d0946e
Code review feedback.
tjprescott Jun 3, 2026
ec760b0
Add generated API.md for azure-template
Copilot Jun 3, 2026
d04b5db
Refactor to use `azpysdk apistub --md` command.
tjprescott Jun 3, 2026
825c684
Merge branch 'GenerateAPITextScript' of https://github.com/Azure/azur…
tjprescott Jun 3, 2026
7f8eeb5
Remove Python 3.10 limit on apistub.py.
tjprescott Jun 3, 2026
c75faac
Refactor `azpysdk apistub` command. Extract metadata from API.md.
tjprescott Jun 3, 2026
dfe985c
Add validation for select metadata fields.
tjprescott Jun 3, 2026
9d8137c
CI fixes.
tjprescott Jun 3, 2026
760fc63
Add skill for generating review PR.
tjprescott Jun 3, 2026
1517d58
Update review generation logic.
tjprescott Jun 3, 2026
258a36a
fix(python adapter): add shell:true on Windows for spawnSync
tjprescott Jun 3, 2026
89e6c98
fix(python adapter): pass --dest-dir so API.md lands in package dir
tjprescott Jun 3, 2026
62f81e3
fix(python adapter): skip _generated dirs in readVersion to avoid sta…
tjprescott Jun 3, 2026
92e0c92
Make script idempotent and reuse branches with the same API hash.
tjprescott Jun 4, 2026
bb253fa
Code review feedback.
tjprescott Jun 5, 2026
317bd4c
Updates.
tjprescott Jun 5, 2026
a82a7ee
Make review PR creation only work for updates, not new packages.
tjprescott Jun 5, 2026
8d07492
CI fixes.
tjprescott Jun 5, 2026
da6a96e
Use shared helper method.
tjprescott Jun 8, 2026
8fdfca0
Add metadata to review PRs.
tjprescott Jun 8, 2026
341ee63
Code review feedback.
tjprescott Jun 8, 2026
6c93b82
Add package-lock.json
tjprescott Jun 8, 2026
c7903bc
Merge branch 'main' into GenerateAPITextScript
tjprescott Jun 9, 2026
8859f30
Refactor to use simple-git and octokit
tjprescott Jun 9, 2026
7e82410
Code review feedback.
tjprescott Jun 9, 2026
3d207c2
Remove template APIs.
tjprescott Jun 9, 2026
650f534
Code review feedback.
tjprescott Jun 9, 2026
c151395
Refactor review create script to Python.
tjprescott Jun 10, 2026
a94221a
Test consistency refactor.
tjprescott Jun 10, 2026
109aec8
Improve failure logging. Fix CI
tjprescott Jun 10, 2026
58ff53e
Test resovling consistency
tjprescott Jun 10, 2026
a7cabe5
Script fixes.
tjprescott Jun 10, 2026
dd3e9d9
Tweaks and remove APIs (more testing)
tjprescott Jun 10, 2026
143033b
Code review feedback.
tjprescott Jun 10, 2026
75f904e
Consolidate package.json.
tjprescott Jun 10, 2026
094fedf
Code review feedback
tjprescott Jun 12, 2026
91e5d84
restore chronus
mikeharder Jun 12, 2026
223227e
remove .github/package.json
mikeharder Jun 12, 2026
fed552b
remove unnecessary shared src
mikeharder Jun 12, 2026
d993261
add readme with "copied from"
mikeharder Jun 12, 2026
0f28a92
Merge branch 'main' into GenerateAPITextScript
mikeharder Jun 12, 2026
edab959
Merge branch 'main' into GenerateAPITextScript
mikeharder Jun 12, 2026
414b967
Fix CI
tjprescott Jun 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `.github/shared`

Copied from https://github.com/Azure/azure-rest-api-specs/tree/main/.github/shared
61 changes: 61 additions & 0 deletions .github/shared/src/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Caches values in memory with a single key of any type.
*
* @template K, V
*/
export class KeyedCache {
/** @type {Map<K, V>} */
#map = new Map();

/**
* Returns cached value, initializing if necessary
*
* @param {K} key
* @param {() => V} factory
* @returns {V} cached value
*
* @example
* const result = cache.getOrCreate(42, async () => await doWork(42));
*/
getOrCreate(key, factory) {
let value = this.#map.get(key);

if (value === undefined) {
value = factory();
this.#map.set(key, value);
}

return value;
}
}

/**
* Caches values in memory with an ordered pair of keys of any types.
*
* @template K1, K2, V
*/
export class KeyedPairCache {
// Two-layer nested cache
/** @type {KeyedCache<K1, KeyedCache<K2, V>>} */
#cache1 = new KeyedCache();

/**
* Returns cached value, initializing if necessary.
* Keys are ordered, so (key1, key2) != (key2, key1).
*
* @param {K1} key1
* @param {K2} key2
* @param {() => V} factory
* @returns {V} cached value
*
* @example
* const result = cache.getOrCreate(42, 7, async () => await doWork(42, 7));
*/
Comment thread
tjprescott marked this conversation as resolved.
getOrCreate(key1, key2, factory) {
// key1 => cache for the next layer
const cache2 = this.#cache1.getOrCreate(key1, () => new KeyedCache());

// key2 => final value
return cache2.getOrCreate(key2, factory);
}
}
152 changes: 152 additions & 0 deletions .github/shared/src/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import child_process from "child_process";
import { dirname, join } from "path";
import { promisify } from "util";
const execFileImpl = promisify(child_process.execFile);

/**
* @typedef {Object} ExecOptions
* @property {string} [cwd] Current working directory. Default: process.cwd().
* @property {import('./logger.js').ILogger} [logger]
* @property {boolean} [logOutput] Log captured stdout/stderr at info level. Default: false.
* @property {number} [maxBuffer] Max bytes allowed on stdout or stderr. Default: 16 * 1024 * 1024.
*/

/**
* @typedef {Object} NpmPrefixOptions
* @property {string} [prefix] Prefix to pass to npm via "--prefix".
*/

/**
* @typedef {ExecOptions & NpmPrefixOptions} ExecNpmOptions
*/

/**
* @typedef {Object} ExecResult
* @property {string} stdout
* @property {string} stderr
*/

/**
* @typedef {Error & { stdout?: string, stderr?: string, code?: number }} ExecError
*/

/**
* Checks whether an unknown error object is an ExecError.
* @param {unknown} error
* @returns {error is ExecError}
*/
export function isExecError(error) {
if (!(error instanceof Error)) return false;

const e = /** @type {ExecError} */ (error);
return typeof e.stdout === "string" || typeof e.stderr === "string";
}

/**
* Wraps `child_process.execFile()`, adding logging and a larger default maxBuffer.
*
* @param {string} file
* @param {string[]} [args]
* @param {ExecOptions} [options]
* @returns {Promise<ExecResult>}
* @throws {ExecError}
*/
export async function execFile(file, args, options = {}) {
const {
cwd,
logger,
logOutput = false,
// Node default is 1024 * 1024, which is too small for some git commands returning many entities or large file content.
// To support "git show", should be larger than the largest swagger file in the repo (2.5 MB as of 2/28/2025).
maxBuffer = 16 * 1024 * 1024,
} = options;

logger?.info(`execFile("${file}", ${JSON.stringify(args)})`);

try {
// execFile(file, args) is more secure than exec(cmd), since the latter is vulnerable to shell injection
const result = await execFileImpl(file, args, {
cwd,
maxBuffer,
});

logger?.debug(`stdout: '${result.stdout}'`);
logger?.debug(`stderr: '${result.stderr}'`);
if (logOutput) {
if (result.stdout) {
logger?.info(result.stdout.trimEnd());
}
if (result.stderr) {
logger?.info(result.stderr.trimEnd());
}
}

return result;
} catch (error) {
/* v8 ignore next */
logger?.debug(`error: '${JSON.stringify(error)}'`);
if (logOutput && isExecError(error)) {
if (error.stdout) {
logger?.info(error.stdout.trimEnd());
}
if (error.stderr) {
logger?.info(error.stderr.trimEnd());
}
}

throw error;
}
}

/**
* Calls `execFile()` with appropriate arguments to run `npm` on all platforms
*
* @param {string[]} args
* @param {ExecNpmOptions} [options]
* @returns {Promise<ExecResult>}
* @throws {ExecError}
*/
export async function execNpm(args, options = {}) {
const { prefix } = options;

// Exclude platform-specific code from coverage
/* v8 ignore start */
const { file, defaultArgs } =
process.platform === "win32"
? {
// Only way I could find to run "npm" on Windows, without using the shell (e.g. "cmd /c npm ...")
//
// "node.exe", ["--", "npm-cli.js", ...args]
//
// The "--" MUST come BEFORE "npm-cli.js", to ensure args are sent to the script unchanged.
// If the "--" comes after "npm-cli.js", the args sent to the script will be ["--", ...args],
// which is NOT equivalent, and can break if args itself contains another "--".

// example: "C:\Program Files\nodejs\node.exe"
file: process.execPath,

// example: "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
defaultArgs: [
"--",
join(dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js"),
],
}
: { file: "npm", defaultArgs: [] };
/* v8 ignore stop */

const prefixArgs = prefix ? ["--prefix", prefix] : [];

return await execFile(file, [...defaultArgs, ...prefixArgs, ...args], options);
}

/**
* Calls `execNpm()` with arguments ["exec", "--no", "--"] prepended.
*
* @param {string[]} args
* @param {ExecNpmOptions} [options]
* @returns {Promise<ExecResult>}
* @throws {ExecError}
*/
export async function execNpmExec(args, options = {}) {
return await execNpm(["exec", "--no", "--", ...args], options);
}
64 changes: 64 additions & 0 deletions .github/shared/src/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @typedef {Object} ILogger
* @property {(message:string) => void} debug
* @property {(message:string) => void} error
* @property {(message:string) => void} info
* @property {(message:string) => void} warning
* @property {() => boolean} isDebug
*/

/**
* @implements {ILogger}
*/
export class ConsoleLogger {
/** @type {boolean} */
#isDebug;

/**
* @param {boolean} [isDebug] - If true, debug logs will be printed. Default: false.
*/
constructor(isDebug = false) {
this.#isDebug = isDebug;
}

/**
* @param {string} message
*/
debug(message) {
if (this.isDebug()) {
console.debug(message);
}
}

/**
* @param {string} message
*/
error(message) {
console.error(message);
}

/**
* @param {string} message
*/
info(message) {
console.log(message);
}

/**
* @returns {boolean}
*/
isDebug() {
return this.#isDebug;
}

/**
* @param {string} message
*/
warning(message) {
console.warn(message);
}
}

// Singleton loggers
export const defaultLogger = new ConsoleLogger();
export const debugLogger = new ConsoleLogger(/*isDebug*/ true);
104 changes: 104 additions & 0 deletions .github/shared/src/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { basename, dirname, resolve } from "path";

import { KeyedCache, KeyedPairCache } from "./cache.js";

/** @type {KeyedCache<string, string>} */
const resolveCache = new KeyedCache();

/** @type {KeyedPairCache<string, string, string>} */
const resolvePairCache = new KeyedPairCache();

/**
*
* @param {string} path Absolute or relative path
* @param {string} segment File or folder
* @returns {boolean} True if resolved path contains segment
*
* @example
* includesSegment("stable/2025-01-01/examples/foo.json", "examples")
* // -> true
*/
export function includesSegment(path, segment) {
return untilLastSegment(path, segment) !== "";
}

/**
* Wraps `path.resolve(path)` with a cache to improve performance
*
* @param {string} path
* @returns {string}
*/
export function resolveCached(path) {
return resolveCache.getOrCreate(path, () => resolve(path));
}

/**
* Wraps `path.resolve(from, to)` with a cache to improve performance

* @param {string} from
* @param {string} to
* @returns {string}
*/
export function resolvePairCached(from, to) {
return resolvePairCache.getOrCreate(from, to, () => resolve(from, to));
}

/**
* @param {string} path Absolute or relative path
* @param {string} segment File or folder
* @returns {string} Portion of resolved path up to (and including) the last occurrence of segment
*
* @example
* untilLastSegment("stable/2025-01-01/examples/foo.json", "examples")
* // -> "{cwd}/stable/2025-01-01/examples"
*/
export function untilLastSegment(path, segment) {
// Shares code with `untilLastSegmentWithParent()`, but not worth refactoring yet

let current = resolveCached(path);

while (true) {
const parent = dirname(current);

if (basename(current) === segment) {
// Found the target folder. Return it.
return current;
} else if (parent === current) {
// Reached the filesystem root (folder not found). Return empty string.
return "";
} else {
// Keep walking upward
current = parent;
}
}
}

/**
* @param {string} path Absolute or relative path
* @param {string} segment File or folder
* @returns {string} Portion of resolved path up to (and including) the last segment with the specified parent
*
* @example
* untilLastSegmentWithParent("specification/foo/data-plane/stable/2025-01-01/foo.json", "specification")
* // -> "{cwd}/specification/foo"
*/
export function untilLastSegmentWithParent(path, segment) {
// Shares code with `untilLastSegment()`, but not worth refactoring yet

let current = resolveCached(path);

while (true) {
const parent = dirname(current);

if (basename(parent) === segment) {
// Found the target parent. Return current;
return current;
} else if (parent === current) {
// Reached the filesystem root (folder not found). Return empty string.
return "";
} else {
// Keep walking upward
current = parent;
}
}
}
Loading
Loading