Skip to content

Commit d880151

Browse files
pshao25Pan Shao
andauthored
Add github summary report (#36422)
* Add to github summary * Add test file * update * update * update * test * update * update * update * update --------- Co-authored-by: Pan Shao <[email protected]>
1 parent eb75e08 commit d880151

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

.github/workflows/typespec-migration-validation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ jobs:
2323

2424
- name: Run TypeSpec Migration Validation
2525
run: |
26-
./eng/tools/typespec-migration-validation/scripts/download-main.ps1 -Verbose -callValidation $true
26+
./eng/tools/typespec-migration-validation/scripts/download-main.ps1 -Verbose -reportFile $env:GITHUB_STEP_SUMMARY
2727
shell: pwsh

eng/tools/typespec-migration-validation/scripts/download-main.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
param(
22
[string]$swaggerPath,
3-
[string]$callValidation = $false
3+
[string]$reportFile = $null
44
)
55

66
. $PSScriptRoot/../../../scripts/ChangedFiles-Functions.ps1
@@ -95,11 +95,11 @@ if ($swaggerPath.StartsWith("specification")) {
9595
$swaggerPath = Join-Path $repoRoot $swaggerPath
9696
}
9797

98-
if ($callValidation -eq $true) {
99-
Write-Host "Executing TypeSpec migration validation..."
100-
npx tsmv $swaggerInMain $swaggerPath
98+
if ([string]::IsNullOrEmpty($reportFile)) {
99+
Write-Host "Your next command: npx tsmv $swaggerInMain $swaggerPath --outputFolder {outputFolder}"
101100
}
102-
else {
103-
Write-Host "Your next command: npx tsmv $swaggerInMain $swaggerPath {outputFolder}"
101+
else {
102+
Write-Host "Executing TypeSpec migration validation..."
103+
npx tsmv $swaggerInMain $swaggerPath --reportFile $reportFile
104104
}
105105

eng/tools/typespec-migration-validation/src/compare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ function comparePaths(oldDocument: OpenAPI2Document, newDocument: OpenAPI2Docume
4646
level: "error"
4747
});
4848
}
49-
pathDiffs.push(...compareOperation(oldOperations[operationId][1], newOperations[operationId][1], operationId));
49+
else {
50+
pathDiffs.push(...compareOperation(oldOperations[operationId][1], newOperations[operationId][1], operationId));
51+
}
5052
}
5153
for (const operationId in newOperations) {
5254
if (!oldOperations[operationId]) {

eng/tools/typespec-migration-validation/src/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
formatModifiedValuesReport,
2020
} from "./summary.js";
2121
import { compareDocuments, printPathDiff } from "./compare.js";
22+
import { writeFile } from "fs/promises";
2223

2324
function parseArguments() {
2425
return yargs(hideBin(process.argv))
@@ -50,6 +51,14 @@ function parseArguments() {
5051
"Compare two swagger specs",
5152
)
5253
.example("$0 oldSpecPath newSpecPath", "Compare using positional arguments")
54+
.example(
55+
"$0 --oldPath ./old-spec --newPath ./new-spec --reportFile ./custom-report.md",
56+
"Compare specs with custom report file",
57+
)
58+
.example(
59+
"$0 --oldPath ./old-spec --newPath ./new-spec --outputFolder ./validation-results",
60+
"Compare specs with custom output folder",
61+
)
5362
.example(
5463
"$0 add-ignore --path \"paths['/api/resource'].put.parameters[0].required__added\" --outputFolder ./results",
5564
"Add a path to ignore file",
@@ -68,6 +77,11 @@ function parseArguments() {
6877
alias: "out",
6978
describe: "Output folder for analysis results",
7079
type: "string",
80+
})
81+
.option("reportFile", {
82+
alias: "r",
83+
describe: "Path to the report file",
84+
type: "string",
7185
})
7286
.option("ignoreDescription", {
7387
description: "Ignore description differences",
@@ -95,9 +109,6 @@ function parseArguments() {
95109
if (!argv.newPath && positional.length > 1) {
96110
argv.newPath = positional[1]!.toString();
97111
}
98-
if (!argv.outputFolder && positional.length > 2) {
99-
argv.outputFolder = positional[2]!.toString();
100-
}
101112

102113
if (!argv.oldPath || !argv.newPath) {
103114
throw new Error("Both oldPath and newPath are required");
@@ -155,7 +166,7 @@ export async function main() {
155166

156167
// If using add-ignore command, the command handler will exit the process
157168

158-
const { oldPath, newPath, outputFolder, ignoreDescription, ignorePathCase } = args;
169+
const { oldPath, newPath, reportFile, outputFolder, ignoreDescription, ignorePathCase } = args;
159170
configuration.ignoreDescription = ignoreDescription;
160171
if (ignorePathCase !== undefined) {
161172
configuration.ignorePathCase = ignorePathCase;
@@ -261,7 +272,10 @@ export async function main() {
261272
);
262273
}
263274
}
264-
else {
275+
else if (reportFile) {
276+
if (compareResult.length > 0) {
277+
await writeFile(reportFile, outputMarkdown);
278+
}
265279
if (compareResult.filter((x) => x.level === "error").length > 0) {
266280
logError("Differences found. Please fix the issues before proceeding.");
267281
process.exit(1);

0 commit comments

Comments
 (0)