Skip to content

[tools] console log issue from filter log #33075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
69 changes: 65 additions & 4 deletions eng/tools/spec-gen-sdk-runner/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "node:fs";

Check failure on line 1 in eng/tools/spec-gen-sdk-runner/src/commands.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/spec-gen-sdk-runner/src/commands.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
Expand All @@ -8,14 +8,14 @@
getAllTypeSpecPaths,
resetGitRepo,
} from "./utils.js";
import { LogLevel, logMessage, vsoAddAttachment } from "./log.js";
import { SpecGenSdkCmdInput } from "./types.js";
import { LogLevel, logMessage, vsoAddAttachment, vsoLogIssue } from "./log.js";
import { CommandLog, SpecGenSdkCmdInput } from "./types.js";
import { detectChangedSpecConfigFiles } from "./change-files.js";

export async function generateSdkForSingleSpec(): Promise<number> {
// Parse the arguments
const commandInput: SpecGenSdkCmdInput = parseArguments();
const specConfigPath = commandInput.tspConfigPath ?? commandInput.readmePath;
const specConfigPath = `${commandInput.tspConfigPath} ${commandInput.readmePath}`;
// Construct the spec-gen-sdk command
const specGenSdkCommand = prepareSpecGenSdkCommand(commandInput);
logMessage(`Generating SDK from ${specConfigPath}`, LogLevel.Group);
Expand Down Expand Up @@ -43,6 +43,9 @@
statusCode = 1;
}
logMessage("ending group logging", LogLevel.EndGroup);

logIssuesToPipeline(commandInput, specConfigPath);

return statusCode;
}

Expand Down Expand Up @@ -71,7 +74,7 @@
specGenSdkCommand.push("--readme-relative-path", changedSpec.readmeMd);
pushedSpecConfigCount++;
}
const changedSpecPath = changedSpec.typespecProject ?? changedSpec.readmeMd;
const changedSpecPath = `${changedSpec.typespecProject} ${changedSpec.readmeMd}`;
logMessage(`Generating SDK from ${changedSpecPath}`, LogLevel.Group);
logMessage(`Command:${specGenSdkCommand.join(" ")}`);

Expand Down Expand Up @@ -105,6 +108,8 @@
statusCode = 1;
}
logMessage("ending group logging", LogLevel.EndGroup);

logIssuesToPipeline(commandInput, changedSpecPath);
}
return statusCode;
}
Expand Down Expand Up @@ -180,6 +185,8 @@
statusCode = 1;
}
logMessage("ending group logging", LogLevel.EndGroup);

logIssuesToPipeline(commandInput, specConfigPath || '');
}
if (failedCount > 0) {
markdownContent += `${failedContent}\n`;
Expand Down Expand Up @@ -325,3 +332,57 @@
}
return specConfigPaths;
}

/**
* Extract and format the prefix from tspConfigPath or readmePath.
* This function is copied from 'spec-gen-sdk'.
* Source code: [Azure SDK Tools - spec-gen-sdk](https://github.com/Azure/azure-sdk-tools/blob/main/tools/spec-gen-sdk/src/utils/utils.ts#L171)
* @param {string | undefined} tspConfigPath The tspConfigPath to extract the prefix from.
* @param {string | undefined} readmePath The readmePath to extract the prefix from.
* @returns {string} The formatted prefix.
*/
function extractPathFromSpecConfig(tspConfigPath: string | undefined, readmePath: string | undefined): string {
let prefix = '';
if (tspConfigPath) {
const regex = /specification\/(.+)\/tspconfig\.yaml$/
const match = regex.exec(tspConfigPath);
if (match) {
const segments = match[1].split('/');
prefix = segments.join('-').toLowerCase().replaceAll('.', '-');
}
} else if (readmePath) {
const regex = /specification\/(.+?)\/readme\.md$/i
const match = regex.exec(readmePath);
if (match) {
const segments = match[1].split('/');
prefix = segments.join('-').toLowerCase().replaceAll('.', '-');
}
}
return prefix;
}

/**
* Logs SDK generation issues to Azure DevOps (ADO)
* @param commandInput
* @param specConfigPath
*/
function logIssuesToPipeline(commandInput: SpecGenSdkCmdInput, specConfigPath: string): void {
const fileNamePrefix = extractPathFromSpecConfig(commandInput.tspConfigPath, commandInput.readmePath)
const logFolder = path.join(commandInput.workingFolder, 'out/logs');
const logPath = path.join(logFolder, `${fileNamePrefix}-filtered.log`);
let logIssues:CommandLog[] = []
try {
const log = JSON.parse(fs.readFileSync(logPath, "utf8"));
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
logIssues = log.logIssues;
} catch (error) {
logMessage(`Error reading log at ${logPath}:${error}`, LogLevel.Error);
}

if(logIssues.length > 0) {
logMessage(`Error generating SDK from ${specConfigPath}`, LogLevel.Group);
const logIssuesList = logIssues.flatMap(entry => [`Get log issues from script ${entry.command} `, ...entry.logIssues]);;
vsoLogIssue(logIssuesList.join('%0D%0A'));
logMessage("ending group logging", LogLevel.EndGroup);
}
}
5 changes: 5 additions & 0 deletions eng/tools/spec-gen-sdk-runner/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in eng/tools/spec-gen-sdk-runner/src/types.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/spec-gen-sdk-runner/src/types.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
* Represents the input parameters required for spec-gen-sdk command execution.
*/
export interface SpecGenSdkCmdInput {
Expand All @@ -16,3 +16,8 @@
headRepoHttpsUrl?: string;
headBranch?: string;
}

export type CommandLog = {
command: string;
logIssues: string[];
};
Loading