Skip to content

Commit c30705b

Browse files
authored
Merge branch 'main' into user/nabilat/face-v1.3-preview.1
2 parents 0ee1063 + e5234a6 commit c30705b

File tree

7 files changed

+100
-40
lines changed

7 files changed

+100
-40
lines changed

eng/common/pipelines/templates/archetype-typespec-emitter.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ extends:
241241
Paths:
242242
- "/*"
243243
- "!SessionRecords"
244+
245+
- task: UseNode@1
246+
displayName: 'Install Node.js'
247+
inputs:
248+
version: '22.x'
244249

245250
- download: current
246251
displayName: Download pipeline artifacts
@@ -313,6 +318,11 @@ extends:
313318
- "/*"
314319
- "!SessionRecords"
315320

321+
- task: UseNode@1
322+
displayName: 'Install Node.js'
323+
inputs:
324+
version: '22.x'
325+
316326
- download: current
317327
displayName: Download pipeline artifacts
318328

@@ -491,4 +501,4 @@ extends:
491501
scriptType: "bash"
492502
scriptLocation: "inlineScript"
493503
inlineScript: npx tsp-spector upload-coverage --coverageFile $(Build.ArtifactStagingDirectory)/tsp-spector-coverage-azure.json --generatorName @azure-typespec/$(SpectorName) --storageAccountName typespec --containerName coverages --generatorVersion $(node -p -e "require('./package.json').version") --generatorMode azure
494-
workingDirectory: $(Build.SourcesDirectory)/eng/packages/$(SpectorName)
504+
workingDirectory: $(Build.SourcesDirectory)/eng/packages/$(SpectorName)

eng/pipelines/templates/stages/archetype-spec-gen-sdk.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ extends:
279279
-PRBody "$(GeneratedSDKInformation)"
280280
-OpenAsDraft $true
281281
282-
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
283-
- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
284-
parameters:
285-
ArtifactPath: $(GeneratedSDK.StagedArtifactsFolder)
286-
ArtifactName: $(PipelineArtifactsName)
287-
RepoRoot: $(SdkRepoDirectory)
282+
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
283+
- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
284+
parameters:
285+
ArtifactPath: $(GeneratedSDK.StagedArtifactsFolder)
286+
ArtifactName: $(PipelineArtifactsName)
287+
RepoRoot: $(SdkRepoDirectory)

eng/tools/lint-diff/src/correlateResults.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export async function correlateRuns(
1010
afterChecks: AutorestRunResult[],
1111
): Promise<Map<string, BeforeAfter>> {
1212
const runCorrelations = new Map<string, BeforeAfter>();
13+
console.log("\nCorrelating runs...");
1314
for (const results of afterChecks) {
1415
const { readme, tag } = results;
1516
const key = tag ? `${readme}#${tag}` : readme;
@@ -83,7 +84,7 @@ export function getViolations(
8384
const newViolations: LintDiffViolation[] = [];
8485
const existingViolations: LintDiffViolation[] = [];
8586

86-
for (const [runKey, { before, after }] of runCorrelations.entries()) {
87+
for (const [, { before, after }] of runCorrelations.entries()) {
8788
const beforeViolations = before
8889
? getLintDiffViolations(before).filter(
8990
(v) => (isFailure(v.level) || isWarning(v.level)) && v.source?.length > 0,
@@ -98,12 +99,12 @@ export function getViolations(
9899
affectedSwaggers.has(relativizePath(v.source[0].document).slice(1))),
99100
);
100101

101-
const [newitems, existingItems] = getNewItems(beforeViolations, afterViolations);
102-
console.log(`Correlated Run: ${runKey}`);
103-
console.log(`New violations: ${newitems.length}`);
104-
console.log(`Existing violations: ${existingItems.length}`);
102+
const [newItems, existingItems] = getNewItems(beforeViolations, afterViolations);
103+
console.log("Correlation:");
104+
console.log(`\tBefore: Readme: ${before?.readme} Tag: ${before?.tag}`);
105+
console.log(`\tAfter: Readme : ${after.readme} Tag: ${after.tag}`);
105106

106-
newViolations.push(...newitems);
107+
newViolations.push(...newItems);
107108
existingViolations.push(...existingItems);
108109
}
109110

eng/tools/lint-diff/src/generateReport.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export async function generateLintDiffReport(
2020
baseBranch: string,
2121
compareSha: string,
2222
): Promise<boolean> {
23+
24+
console.log("Generating LintDiff report...");
25+
2326
let pass = true;
2427
let outputMarkdown = "";
2528

@@ -34,7 +37,7 @@ export async function generateLintDiffReport(
3437
// Compared Specs | New Version | Base Version
3538
// <tag name> | link: readme.md#tag-<tag-name> | link: readme.md#tag-<tag-name>
3639
// ... | ... | ...
37-
for (const [_, { before, after }] of runCorrelations.entries()) {
40+
for (const [, { before, after }] of runCorrelations.entries()) {
3841
const afterName = getName(after);
3942
const beforeName = before ? getName(before) : "default";
4043
const afterPath = getPath(after);
@@ -47,7 +50,6 @@ export async function generateLintDiffReport(
4750

4851
const [newViolations, existingViolations] = getViolations(runCorrelations, affectedSwaggers);
4952

50-
console.log("Populating armRpcs for new violations");
5153
for (const newItem of newViolations) {
5254
// TODO: Potential performance issue, make parallel
5355
newItem.armRpcs = await getRelatedArmRpcFromDoc(newItem.code);
@@ -56,12 +58,7 @@ export async function generateLintDiffReport(
5658
newViolations.sort(compareLintDiffViolations);
5759
existingViolations.sort(compareLintDiffViolations);
5860

59-
if (newViolations.some((v) => isFailure(v.level))) {
60-
// New violations with level error or fatal fail the build. If all new
61-
// violations are warnings, the build passes.
62-
pass = false;
63-
}
64-
61+
console.log(`New violations: ${newViolations.length}`);
6562
if (newViolations.length > 0) {
6663
outputMarkdown += "**[must fix]The following errors/warnings are intorduced by current PR:**\n";
6764
if (newViolations.length > 50) {
@@ -76,11 +73,21 @@ export async function generateLintDiffReport(
7673
outputMarkdown += getNewViolationReportRow(violation, compareSha);
7774
}
7875

76+
if (newViolations.some((v) => isFailure(v.level))) {
77+
console.log("\t❌ At least one violation has error or fatal level. LintDiff will fail.");
78+
// New violations with level error or fatal fail the build. If all new
79+
// violations are warnings, the build passes.
80+
pass = false;
81+
} else {
82+
console.log("\t✅ No new violations with error or fatal level. LintDiff will pass.");
83+
}
84+
85+
LogViolations("New violations list", newViolations);
86+
7987
outputMarkdown += "\n";
8088
}
8189

82-
// The following errors/warnings exist before current PR submission
83-
// Rule | Message | Location (link to file, line # at SHA)
90+
console.log(`Existing violations: ${existingViolations.length}`);
8491
if (existingViolations.length > 0) {
8592
outputMarkdown += "**The following errors/warnings exist before current PR submission:**\n";
8693
if (existingViolations.length > 50) {
@@ -95,6 +102,8 @@ export async function generateLintDiffReport(
95102
outputMarkdown += `| ${iconFor(level)} [${code}](${getDocUrl(code)}) | ${message}<br />Location: [${getPathSegment(relativizePath(getFile(violation)))}#L${getLine(violation)}](${getFileLink(compareSha, relativizePath(getFile(violation)), getLine(violation))}) |\n`;
96103
}
97104

105+
LogViolations("Existing violations list", existingViolations);
106+
98107
outputMarkdown += `\n`;
99108
}
100109

@@ -104,6 +113,19 @@ export async function generateLintDiffReport(
104113
return pass;
105114
}
106115

116+
function LogViolations(heading: string, violations: LintDiffViolation[]) {
117+
console.log(`::group::${heading}`);
118+
for (const violation of violations) {
119+
const source = getFile(violation);
120+
const line = getLine(violation);
121+
console.log(`Violation: ${source}${line ? `:${line}` : ""}`);
122+
console.log(` Level: ${violation.level}`);
123+
console.log(` Code: ${violation.code}`);
124+
console.log(` Message: ${violation.message}`);
125+
}
126+
console.log("::endgroup::");
127+
}
128+
107129
export async function generateAutoRestErrorReport(
108130
autoRestErrors: { result: AutorestRunResult; errors: AutoRestMessage[] }[],
109131
outFile: string,

eng/tools/lint-diff/src/lint-diff.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ async function runLintDiff(
111111
changedFilesPath,
112112
);
113113

114+
if (beforeList.size === 0 && afterList.size === 0) {
115+
console.log("No changes found. Exiting.");
116+
return;
117+
}
118+
114119
// It may be possible to run these in parallel as they're running against
115120
// different directories.
116121
const beforeChecks = await runChecks(beforePath, beforeList);
@@ -145,4 +150,14 @@ async function runLintDiff(
145150
process.exitCode = 1;
146151
console.error(`Lint-diff failed. See workflow summary report in ${outFile} for details.`);
147152
}
153+
154+
if (
155+
process.env.GITHUB_SERVER_URL &&
156+
process.env.GITHUB_REPOSITORY &&
157+
process.env.GITHUB_RUN_ID
158+
) {
159+
console.log(
160+
`See workflow summary at: ${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
161+
);
162+
}
148163
}

eng/tools/lint-diff/src/processChanges.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ export async function getRunList(
4141
const [beforeState, _] = await buildState(changedSpecFiles, beforePath);
4242
const [afterState, afterSwaggers] = await buildState(changedSpecFiles, afterPath);
4343
const affectedSwaggers = new Set<string>(afterSwaggers);
44-
45-
console.log(`affected swaggers: ${[...affectedSwaggers].join(", ")}`);
4644
const [beforeTagMap, afterTagMap] = reconcileChangedFilesAndTags(beforeState, afterState);
4745

46+
47+
console.log("Before readme and tags:");
48+
console.table([...beforeTagMap].map(([readme, tags]) => ({ readme, tags })), ['readme', 'tags']);
49+
console.log("\n");
50+
51+
console.log("After readme and tags:");
52+
console.table([...afterTagMap].map(([readme, tags]) => ({ readme, tags })), ['readme', 'tags']);
53+
console.log("\n");
54+
55+
console.log("Affected swaggers:");
56+
console.table([...affectedSwaggers].map((swagger) => ({ swagger })), ['swagger']);
57+
console.log("\n");
58+
4859
return [beforeTagMap, afterTagMap, affectedSwaggers];
4960
}
5061

eng/tools/lint-diff/src/runChecks.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export async function runChecks(
2020

2121
for (const [readme, tags] of runList.entries()) {
2222
const changedFilePath = join(path, readme);
23-
console.log(`Linting ${changedFilePath}`);
2423

2524
// TODO: Move this into getRunList
2625
let openApiType = await getOpenapiType(changedFilePath);
@@ -51,8 +50,13 @@ export async function runChecks(
5150
`${tagArg} ` +
5251
`${changedFilePath}`;
5352

54-
console.log(`autorest command: ${autorestCommand}`);
53+
console.log(`::group::Autorest for type: ${openApiType} readme: ${readme} tag: ${tag}`);
54+
console.log(`\tAutorest command: ${autorestCommand}`);
55+
5556
const executionResult = await executeCommand(autorestCommand);
57+
58+
console.log(executionResult.stderr + executionResult.stdout);
59+
5660
const lintDiffResult = {
5761
autorestCommand,
5862
rootPath: path,
@@ -62,8 +66,10 @@ export async function runChecks(
6266
...executionResult,
6367
};
6468
logAutorestExecutionErrors(lintDiffResult);
69+
console.log("::endgroup::");
70+
6571
result.push(lintDiffResult);
66-
console.log("Lint diff result length:", lintDiffResult.stdout.length);
72+
console.log(`\tAutorest result length: ${lintDiffResult.stderr.length + lintDiffResult.stdout.length}\n`);
6773
}
6874
}
6975

@@ -109,19 +115,14 @@ export function logAutorestExecutionErrors(runResult: AutorestRunResult) {
109115
const stderrContainsLevelError = runResult.stderr.includes(`${autoRestPrefix}"level":"error"`);
110116
const stderrContainsLevelFatal = runResult.stderr.includes(`${autoRestPrefix}"level":"fatal"`);
111117

112-
// TODO: Clean up output formatting to be consistent with new output standards
113-
console.log(
114-
`Execution of AutoRest with LintDiff done. ` +
115-
`Error is not null: true, ` +
116-
`stdout contains AutoRest 'error': ${stdoutContainsLevelError}, ` +
117-
`stdout contains AutoRest 'fatal': ${stdoutContainsLevelFatal}, ` +
118-
`stderr contains AutoRest 'error': ${stderrContainsLevelError}, ` +
119-
`stderr contains AutoRest 'fatal': ${stderrContainsLevelFatal}`,
120-
);
121-
} else {
122-
// TODO: Include markdown type?
123118
console.log(
124-
`::debug:: Execution completed with no errors for tag: ${runResult.tag}, markdown: ${runResult.readme}, rootPath: ${runResult.rootPath}`,
119+
`\tAutorest completed with errors:
120+
\t\tExit code: ${runResult.error.code}
121+
\t\tError is not null: true,
122+
\t\tstdout contains AutoRest 'error': ${stdoutContainsLevelError}
123+
\t\tstdout contains AutoRest 'fatal': ${stdoutContainsLevelFatal}
124+
\t\tstderr contains AutoRest 'error': ${stderrContainsLevelError}
125+
\t\tstderr contains AutoRest 'fatal': ${stderrContainsLevelFatal}`,
125126
);
126127
}
127128
}

0 commit comments

Comments
 (0)