Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
88d53d5
working through initial setup of actions and package installation. ju…
scbedd May 15, 2025
99b550c
Add oav-runner to eng/tools/package.json
mikeharder May 15, 2025
c1230fb
[eng/tools/tsconfig.json] Add oav-runner, formatting
mikeharder May 15, 2025
dd67632
much further along in the journey. have it factored closer to what i …
scbedd May 20, 2025
74d2d13
tests properly running
scbedd May 20, 2025
5e4ce29
further updates around calling properly. I really need to clean up th…
scbedd May 23, 2025
1e819ae
adding nice error reporting. working on summary files
scbedd May 23, 2025
c81d71c
make necessary changes to package-lock and other files
scbedd May 23, 2025
5e26c3e
more updates + updating workflow invocation
scbedd May 23, 2025
ce6255b
strictly miming lint-diff to try to figure out why my bin isn't build…
scbedd May 23, 2025
247d942
update specs to call properly
scbedd May 23, 2025
5fa8eaf
update to package-lock.json
scbedd May 23, 2025
0a811b5
fix error-reporting
scbedd May 23, 2025
895ca4b
further refinements
scbedd May 23, 2025
1f92197
fix npm build error
scbedd May 23, 2025
aff13eb
properly setting the exit code when there are actually errors
scbedd May 23, 2025
493f335
update the success summary!
scbedd May 23, 2025
c56eeb9
should be able to run either specs or examples properly now
scbedd May 24, 2025
3609afa
cleanup commit
scbedd May 24, 2025
52bed60
formatting the project properly now
scbedd May 24, 2025
d471af6
rename our specs etc
scbedd May 27, 2025
6b55122
add a test case for an example scenario that absolutely exists
scbedd May 27, 2025
ff4acba
populate more tests
scbedd May 27, 2025
1196a2d
pretty
scbedd May 27, 2025
a4bf7bb
skin out the associatedswaggers and find related to example changes
scbedd May 28, 2025
e840c18
going to need to get rid of all the .filter() or .foreach() as they d…
scbedd May 28, 2025
2029387
cleanup and finishing up the tests. update the summary to output the …
scbedd May 29, 2025
0c5a642
Apply suggestions from code review
scbedd May 29, 2025
31de60f
PR feedback. removing prettierrc. renaming test job. renaming checks
scbedd May 29, 2025
9314de6
refactor the refs usage
scbedd May 29, 2025
912d5bf
Apply suggestions from code review
scbedd May 30, 2025
f37ba49
update getRefs and getExamples to use a common property function
scbedd May 30, 2025
7ce114a
finish rename standardization of the PR. update cli to allow optional…
scbedd May 30, 2025
519423f
honor the new os.cwd usage
scbedd May 30, 2025
92a59db
Apply suggestions from code review
scbedd May 30, 2025
55f9283
commit my package lock. need to do a merge from main now
scbedd May 30, 2025
0ce1c41
git merge main. now need to fix swagger.js
scbedd May 30, 2025
d59f135
merge main
scbedd May 30, 2025
8d08617
remove usage of consolelogger. update from main. update package lock.…
scbedd May 30, 2025
3239dd1
remove the vitest fie
scbedd May 30, 2025
bc8ec0a
Merge branch 'main' into add-model/semantic-gitvalidation
mikeharder May 30, 2025
3422037
switch to local files instead of forcing a huge copy
scbedd Jun 2, 2025
48ec587
remove debug output
scbedd Jun 2, 2025
c33a994
Merge branch 'main' into add-model/semantic-gitvalidation
mikeharder Jun 2, 2025
0fbb537
remove unused var
mikeharder Jun 2, 2025
637ba58
prettier
mikeharder Jun 2, 2025
431c768
Add helper path.includesFolder()
mikeharder Jun 2, 2025
52cacc3
this should be it for crossplat I hope
scbedd Jun 3, 2025
e222d8e
add error reporting tests
scbedd Jun 3, 2025
45ff0b7
remove debug log lines
scbedd Jun 3, 2025
c781fe3
[error-reporting.test] Convert to async, remove empty catch
mikeharder Jun 3, 2025
ee14479
prettier
mikeharder Jun 3, 2025
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
Prev Previous commit
Next Next commit
much further along in the journey. have it factored closer to what i …
…want, but am spending a bunch of time on getting debugging working the way I want it
  • Loading branch information
scbedd committed May 20, 2025
commit dd67632f247b9b419c9e5fe4b62e3e1b71d9afdc
4 changes: 4 additions & 0 deletions eng/tools/oav-runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# `oav-runner`

This is a simple wrapper script around the `oav` tool. It utilizes shared js code code modules from `.github/shared` to
determine a list of swagger specs that should be processed.
11 changes: 6 additions & 5 deletions eng/tools/oav-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
"version": "1.0.0",
"scripts": {
"build": "tsc -p tsconfig.json",
"test": "vitest"
"test": "vitest --run"
},
"bin": {
"invoke-oav": "dist/main.js"
"invoke-oav": "dist/cli.js"
},
"dependencies": {
"oav": "3.5.1",
"@azure-tools/specs-shared": "file:../../../.github/shared",
"js-yaml": "^4.1.0",
"oav": "3.5.1",
"simple-git": "^3.27.0"
},
"devDependencies": {
"vitest": "^3.0.7",
"@types/glob": "^8.1.0",
"@types/node": "~20.11.0",
"typescript": "~5.8.2",
"@types/node": "~20.11.0"
"vitest": "^3.0.7"
},
"engines": {
"node": ">=20.0.0",
Expand Down
2 changes: 1 addition & 1 deletion eng/tools/oav-runner/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ if (!targetDir) {
process.exit(1);
}
else {
await main(targetDir);
console.log(`Running oav-runner on ${targetDir}`);
await main(targetDir);
}
133 changes: 107 additions & 26 deletions eng/tools/oav-runner/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,116 @@
// The original ordering of this code is pulled directly from the original at
// openapi-alps#public/rest-api-specs-scripts/src/modelValidationPipeline.ts
import * as oav from 'oav';
import * as path from 'path';
// import * as glob from 'glob';
import * as fs from 'fs';

// use ,specification, example to filter the changed files to just specs and examples
import { getChangedFiles } from "@azure-tools/specs-shared/changed-files";
import { getChangedFiles, swagger } from "@azure-tools/specs-shared/changed-files";

export async function main(rootDirectory: string): Promise<Number> {
let errors: Array<string> = [];

console.log(`Executing checks in ${rootDirectory}`);

const changedFiles = await getChangedFiles({
cwd: rootDirectory
})

const swaggerFiles = await processFilesToSpecificationList(rootDirectory, changedFiles);

// todo: this will have to be hardened a bit. targeting the swagger file selection first
// as it is an easily testable operation.
for (const swaggerFile of swaggerFiles) {
try {
oav.validateSpec(swaggerFile, {});
}
catch (e) {
// todo: add error handling beyond logging
console.log(e);
}
}

if (errors){
return 1;
}
return 0;
}


export async function processFilesToSpecificationList(rootDirectory: string, files: string[]): Promise<Array<string>> {
// this is implemented in existing example and spec validation pipeline simply by pulling _all_ of the swagger files
// and then filtering them down to just the ones that are in the changed files list.

// we might have to do that, but as far as I can tell, the "pull everything" approach only works for the nonPR. If its PR
// it literally never uses the total result.
return files.filter((file) => {
if (
file.match(/.*\/cadl-project.yaml$/gi) !== null ||
file.match(/.*\/package.json$/gi) !== null ||
file.match(/.*\/sdk-suppressions.yaml$/gi) !== null ||
file.match(/.*\/suppressions.yaml$/gi) !== null ||
file.match(/.*\/tspconfig.yaml$/gi) !== null ||
file.match(/.*\/cspell.yaml$/gi) !== null
) {
return false;
}
if (file.match(/.*\/scenarios\/*/gi) !== null) {
return false;
}
if (
file.match(/.*(json|yaml)$/gi) == null ||
file.match(/.*specification\/.*/gi) == null
) {
return false;
}
if (file.match(/.*\/examples\/*/gi) !== null) {
return false;
}
if (file.match(/.*\/quickstart-templates\/*/gi) !== null) {
return false;
}

let swaggerResult = swagger(file);

// if it's a swagger file, we should check to see if it exists
// as a deleted file will also show up in the changed files list
if (swaggerResult && fs.existsSync(path.join(rootDirectory, file))) {
return true
}
return false;
});
}


// keep these around for now, but they are not used in the current implementation
// the biggest thing is that I'm uncertain if I will need to keep some sort of this globbing around to support when _only_ examples
// are changed, for instance.

// export const getSwaggers = () => {
// const getGlobPath = () =>
// path.join(__dirname, "../", "../", "/specification/**/*.json");
// return glob.sync(getGlobPath(), {
// ignore: [
// "**/scenarios/**/*.json",
// "**/examples/**/*.json",
// "**/quickstart-templates/*.json",
// "**/schema/*.json",
// ],
// });
// };

// export const getExamples = () => {
// const exampleGlobPath = path.join(
// __dirname,
// "../",
// "../",
// "/specification/**/examples/**/*.json"
// );
// return glob.sync(exampleGlobPath);
// };

// this is some code from modelValidationPipeline.ts that is not used in the current implementation
// import jsYaml from 'js-yaml';

// // type ErrorType = "error" | "warning";
Expand Down Expand Up @@ -36,28 +142,3 @@ import { getChangedFiles } from "@azure-tools/specs-shared/changed-files";
// // }
// // }
// // }

export function greet(name: string): string {
return `Hello, ${name}!`;
}

export async function main(rootDirectory: string): Promise<Number> {
let errors: Array<string> = [];

const oavType = new oav.LiveValidator({}, undefined);
console.log(oavType);
console.log(rootDirectory);

let results = await getChangedFiles({
cwd: rootDirectory
})

for (const result of results) {
console.log(result);
}

if (errors){
return 1;
}
return 0;
}
38 changes: 33 additions & 5 deletions eng/tools/oav-runner/test/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
import { describe, it, expect } from 'vitest';
import { greet } from '../src/main.js';
import { processFilesToSpecificationList } from '../src/main.js';
import path from 'path';

const ROOT = path.resolve(__dirname, '../../../../')

describe('file processing', () => {
it('should process a basic set of files and return a list of swagger files only', async () =>{
const changedFiles = [
'specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2025-06-01/workspaceRP.json',
'specification/machinelearningservices/resource-manager/readme.md'
]

const result = await processFilesToSpecificationList(ROOT, changedFiles);
const expected = [
'specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2025-06-01/workspaceRP.json'
]

expect(result).toEqual(expected);
});

it('should process a large set of files and return a list of swagger files only', () => {

});

it('should process the correct swagger file given only changed example files', () => {

});

it('should process the correct swagger file given only changed readme file', () => {

})

it('should handle deleted files without error', () => {

describe('greet', () => {
it('should return greeting message', () => {
const result = greet('World');
expect(result).toBe('Hello, World!');
});
});
11 changes: 7 additions & 4 deletions eng/tools/oav-runner/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { defineConfig } from 'vitest/config';
import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['test/**/*.{test,spec}.{js,ts}'],
...configDefaults,
testTimeout: 20000,
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
},
},
});