in eng/tools/spec-gen-sdk-runner/src/commands.ts [71:157]
export async function generateSdkForSpecPr(): Promise<number> {
// Parse the arguments
const commandInput: SpecGenSdkCmdInput = parseArguments();
// Construct the spec-gen-sdk command
const specGenSdkCommand = prepareSpecGenSdkCommand(commandInput);
// Get the spec paths from the changed files
const changedSpecs = detectChangedSpecConfigFiles(commandInput);
let statusCode = 0;
let pushedSpecConfigCount;
let breakingChangeLabel = "";
let executionReport;
let changedSpecPathText = "";
let hasManagementPlaneSpecs = false;
let overallRunHasBreakingChange = false;
let currentRunHasBreakingChange = false;
let overallExecutionResult = "";
let currentExecutionResult = "";
for (const changedSpec of changedSpecs) {
if (!changedSpec.typespecProject && !changedSpec.readmeMd) {
logMessage("Runner: no spec config file found in the changed files", LogLevel.Warn);
continue;
}
pushedSpecConfigCount = 0;
changedSpecPathText = "";
if (changedSpec.typespecProject) {
specGenSdkCommand.push("--tsp-config-relative-path", changedSpec.typespecProject);
changedSpecPathText = changedSpec.typespecProject;
pushedSpecConfigCount++;
if (changedSpec.typespecProject.includes(".Management")) {
hasManagementPlaneSpecs = true;
}
}
if (changedSpec.readmeMd) {
specGenSdkCommand.push("--readme-relative-path", changedSpec.readmeMd);
changedSpecPathText = changedSpecPathText + " " + changedSpec.readmeMd;
pushedSpecConfigCount++;
if (changedSpec.readmeMd.includes("resource-manager")) {
hasManagementPlaneSpecs = true;
}
}
logMessage(`Generating SDK from ${changedSpecPathText}`, LogLevel.Group);
logMessage(`Runner command:${specGenSdkCommand.join(" ")}`);
try {
await resetGitRepo(commandInput.localSdkRepoPath);
await runSpecGenSdkCommand(specGenSdkCommand);
logMessage("Runner command executed successfully");
} catch (error) {
logMessage(`Runner: error executing command:${error}`, LogLevel.Error);
statusCode = 1;
}
// Pop the spec config path from specGenSdkCommand
for (let index = 0; index < pushedSpecConfigCount * 2; index++) {
specGenSdkCommand.pop();
}
try {
// Read the execution report to aggreate the generation results
executionReport = getExecutionReport(commandInput);
currentExecutionResult = executionReport.executionResult;
if (overallExecutionResult !== "failed") {
overallExecutionResult = currentExecutionResult;
}
[currentRunHasBreakingChange, breakingChangeLabel] = getBreakingChangeInfo(executionReport);
overallRunHasBreakingChange = overallRunHasBreakingChange || currentRunHasBreakingChange;
logMessage(`Runner command execution result:${currentExecutionResult}`);
} catch (error) {
logMessage(`Runner: error reading execution-report.json:${error}`, LogLevel.Error);
statusCode = 1;
overallExecutionResult = "failed";
}
logMessage("ending group logging", LogLevel.EndGroup);
logIssuesToPipeline(executionReport?.vsoLogPath, changedSpecPathText);
}
// Process the spec-gen-sdk artifacts
statusCode =
generateArtifact(
commandInput,
overallExecutionResult,
breakingChangeLabel,
overallRunHasBreakingChange,
hasManagementPlaneSpecs,
) || statusCode;
return statusCode;
}