Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ca6381a
[changed-files] decouple filters
mikeharder Jul 22, 2025
3315278
[swagger] remove duplicate example()
mikeharder Jul 22, 2025
bfb9bca
Add specification filter
mikeharder Jul 22, 2025
d0f7b63
[oav-runner] De-dup example() and swagger()
mikeharder Jul 22, 2025
8331bdc
Merge branch 'main' into changed-files-filter-refactor
mikeharder Jul 22, 2025
f4f61ee
fix filters cross-plat
mikeharder Jul 22, 2025
2a78e2b
specification() must normalize()
mikeharder Jul 22, 2025
50623ae
re-sort filters
mikeharder Jul 22, 2025
c1aa67a
sort
mikeharder Jul 22, 2025
60e64ef
sort
mikeharder Jul 22, 2025
e23259d
specification() throw on abs paths
mikeharder Jul 22, 2025
912c1e9
add tests for abs paths
mikeharder Jul 22, 2025
5c8da50
fix test error message
mikeharder Jul 22, 2025
567297c
100% codecov
mikeharder Jul 22, 2025
2ca6254
comment
mikeharder Jul 22, 2025
0a72649
fix tests x-plat
mikeharder Jul 22, 2025
5f1c090
Merge branch 'main' into changed-files-filter-refactor
mikeharder Jul 22, 2025
35a81b9
remove duplicate code
mikeharder Jul 22, 2025
a04e02f
Add options.paths to getChangedFiles(), remove specification filter
mikeharder Jul 22, 2025
91b49a3
Merge branch 'changed-files-filter-refactor' of https://github.com/mi…
mikeharder Jul 22, 2025
559b58f
comment
mikeharder Jul 22, 2025
09fb3dc
Add paths param to getChangedFilesStatuses()
mikeharder Jul 22, 2025
0193328
[lint-diff] Pass "specification" to getChangedFiles()
mikeharder Jul 22, 2025
dafb9fe
[oav-runner] Pass "specification" to getChangedFiles()
mikeharder Jul 22, 2025
e9c5c56
[openapi-diff-runner] Pass "specification" to getChangedFiles()
mikeharder Jul 22, 2025
fce1a3a
[sdk-suppressions] Pass "specification" to getChangedFiles()
mikeharder Jul 22, 2025
d86f20f
[summarize-impact] Add comment
mikeharder Jul 22, 2025
7d9b704
comments
mikeharder Jul 22, 2025
e9ba4fa
revert imports
mikeharder Jul 22, 2025
8e3f33e
comment
mikeharder Jul 22, 2025
48c2de5
revert imports
mikeharder Jul 22, 2025
c9a53db
revert imports
mikeharder Jul 22, 2025
dbb55df
revert imports
mikeharder Jul 22, 2025
af85325
remove spec() from typespec()
mikeharder Jul 22, 2025
bc8bd9e
[summarize-impact] Remove dep on specification() filter
mikeharder Jul 22, 2025
d8431c3
[changed-files] Use "--" to separate paths from revisions
mikeharder Jul 22, 2025
06772da
fix test
mikeharder Jul 22, 2025
ed9a32d
fix test
mikeharder Jul 22, 2025
17cef07
Add tests for filter "typespec"
mikeharder Jul 22, 2025
aee51f4
revert imports
mikeharder Jul 22, 2025
794ef8e
typo
mikeharder Jul 22, 2025
ad136d9
revert imports
mikeharder Jul 22, 2025
55c4d3a
[openapi-diff-runner] Remove unnecessary path mock
mikeharder Jul 23, 2025
e0ec519
Merge branch 'main' into changed-files-filter-refactor
mikeharder Jul 23, 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
16 changes: 7 additions & 9 deletions .github/shared/src/changed-files.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @ts-check

import debug from "debug";
import { normalize, sep } from "path";
import { simpleGit } from "simple-git";
import { includesFolder } from "./path.js";

// Enable simple-git debug logging to improve console output
debug.enable("simple-git");
Expand Down Expand Up @@ -158,7 +160,7 @@
*/
export function specification(file) {
// Folder name "specification" should match case, since it already exists in repo
return typeof file === "string" && file.startsWith("specification/");
return typeof file === "string" && normalize(file).split(sep)[0] === "specification";
}

/**
Expand All @@ -167,7 +169,7 @@
*/
export function dataPlane(file) {
// Folder name "data-plane" should match case for consistency across specs
return typeof file === "string" && specification(file) && file.includes("/data-plane/");
return typeof file === "string" && includesFolder(file, "data-plane");
Comment thread
mikeharder marked this conversation as resolved.
}

/**
Expand All @@ -176,7 +178,7 @@
*/
export function resourceManager(file) {
// Folder name "resource-manager" should match case for consistency across specs
return typeof file === "string" && specification(file) && file.includes("/resource-manager/");
return typeof file === "string" && includesFolder(file, "resource-manager");
}

/**
Expand All @@ -185,9 +187,7 @@
*/
export function example(file) {
// Folder name "examples" should match case for consistency across specs
return (
typeof file === "string" && json(file) && specification(file) && file.includes("/examples/")
);
return typeof file === "string" && json(file) && includesFolder(file, "examples");
}

/**
Expand All @@ -209,7 +209,5 @@
* @returns {boolean}
*/
export function scenario(file) {
return (
typeof file === "string" && json(file) && specification(file) && file.includes("/scenarios/")
);
return typeof file === "string" && json(file) && includesFolder(file, "scenarios");
}
22 changes: 1 addition & 21 deletions .github/shared/src/swagger.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-check

import $RefParser, { ResolverError } from "@apidevtools/json-schema-ref-parser";
import { readFile } from "fs/promises";
import { dirname, relative, resolve } from "path";
import { mapAsync } from "./array.js";
import { includesFolder } from "./path.js";
import { example } from "./changed-files.js";
Comment thread
mikeharder marked this conversation as resolved.
import { SpecModelError } from "./spec-model-error.js";

/**
Expand Down Expand Up @@ -222,26 +222,6 @@
}
}

// TODO: Remove duplication with changed-files.js (which currently requires paths relative to repo root)

/**
* @param {string} [file]
* @returns {boolean}
*/
function example(file) {
// Folder name "examples" should match case for consistency across specs
return typeof file === "string" && json(file) && includesFolder(file, "examples");
}

/**
* @param {string} [file]
* @returns {boolean}
*/
function json(file) {
// Extension "json" with any case is a valid JSON file
return typeof file === "string" && file.toLowerCase().endsWith(".json");
}

// API version lifecycle stages
export const API_VERSION_LIFECYCLE_STAGES = Object.freeze({
PREVIEW: "preview",
Expand Down
20 changes: 19 additions & 1 deletion .github/shared/test/changed-files.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// @ts-check

import { afterEach, describe, expect, it, vi } from "vitest";
Expand Down Expand Up @@ -46,6 +46,11 @@
"cspell.yaml",
"MixedCase.jSoN",
"README.MD",
"not-spec/contosowidgetmanager/data-plane/readme.md",
"not-spec/contosowidgetmanager/resource-manager/readme.md",
"not-spec/contosowidgetmanager/Contoso.Management/examples/2021-11-01/Employees_Get.json",
"not-spec/contosowidgetmanager/Contoso.Management/scenarios/2021-11-01/Employees_Get.json",
"not-spec/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/contoso.json",
"specification/contosowidgetmanager/data-plane/readme.md",
"specification/contosowidgetmanager/Contoso.Management/main.tsp",
"specification/contosowidgetmanager/Contoso.Management/examples/2021-11-01/Employees_Get.json",
Expand All @@ -59,6 +64,9 @@
const expected = [
"cspell.json",
"MixedCase.jSoN",
"not-spec/contosowidgetmanager/Contoso.Management/examples/2021-11-01/Employees_Get.json",
"not-spec/contosowidgetmanager/Contoso.Management/scenarios/2021-11-01/Employees_Get.json",
"not-spec/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/contoso.json",
"specification/contosowidgetmanager/Contoso.Management/examples/2021-11-01/Employees_Get.json",
"specification/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/contoso.json",
"specification/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/examples/Employees_Get.json",
Expand All @@ -71,6 +79,8 @@
it("filter:readme", () => {
const expected = [
"README.MD",
"not-spec/contosowidgetmanager/data-plane/readme.md",
"not-spec/contosowidgetmanager/resource-manager/readme.md",
"specification/contosowidgetmanager/data-plane/readme.md",
"specification/contosowidgetmanager/resource-manager/readme.md",
];
Expand All @@ -93,13 +103,18 @@
});

it("filter:data-plane", () => {
const expected = ["specification/contosowidgetmanager/data-plane/readme.md"];
const expected = [
"not-spec/contosowidgetmanager/data-plane/readme.md",
"specification/contosowidgetmanager/data-plane/readme.md",
];

expect(files.filter(dataPlane)).toEqual(expected);
});

it("filter:resource-manager", () => {
const expected = [
"not-spec/contosowidgetmanager/resource-manager/readme.md",
"not-spec/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/contoso.json",
"specification/contosowidgetmanager/resource-manager/readme.md",
"specification/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/contoso.json",
"specification/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/examples/Employees_Get.json",
Expand All @@ -110,6 +125,7 @@

it("filter:example", () => {
const expected = [
"not-spec/contosowidgetmanager/Contoso.Management/examples/2021-11-01/Employees_Get.json",
"specification/contosowidgetmanager/Contoso.Management/examples/2021-11-01/Employees_Get.json",
"specification/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/examples/Employees_Get.json",
];
Expand All @@ -119,6 +135,7 @@

it("filter:scenarios", () => {
const expected = [
"not-spec/contosowidgetmanager/Contoso.Management/scenarios/2021-11-01/Employees_Get.json",
"specification/contosowidgetmanager/Contoso.Management/scenarios/2021-11-01/Employees_Get.json",
];

Expand All @@ -127,6 +144,7 @@

it("filter:swagger", () => {
const expected = [
"not-spec/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/contoso.json",
"specification/contosowidgetmanager/resource-manager/Microsoft.Contoso/stable/2021-11-01/contoso.json",
];

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/src/arm-incremental-typespec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// @ts-check

// For now, treat all paths as posix, since this is the format returned from git commands
Expand All @@ -9,6 +9,7 @@
getChangedFiles,
readme,
resourceManager,
specification,
swagger,
} from "../../shared/src/changed-files.js";
import { Readme } from "../../shared/src/readme.js";
Expand All @@ -30,7 +31,7 @@
const changedFiles = await getChangedFiles(options);

// Includes swaggers, readmes, and examples
const changedRmFiles = changedFiles.filter(resourceManager);
const changedRmFiles = changedFiles.filter((f) => specification(f) && resourceManager(f));
Comment thread
mikeharder marked this conversation as resolved.
Outdated

if (changedRmFiles.length == 0) {
core.info("No changes to files containing path '/resource-manager/'");
Expand Down Expand Up @@ -128,7 +129,7 @@
changedSpecDir,
]);

// Filter files to only include RM swagger files
// Filter files to only include RM swagger files. Should already be filtered to files under "/specification".
const specRmSwaggerFilesBaseBranch = specFilesBaseBranch
.split("\n")
.filter((file) => resourceManager(file) && swagger(file));
Expand Down
23 changes: 2 additions & 21 deletions eng/tools/oav-runner/src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env node

import * as fs from "fs";
import * as oav from "oav";
import * as path from "path";
import * as fs from "fs";

import { example, getChangedFiles, swagger } from "@azure-tools/specs-shared/changed-files"; //getChangedFiles,
Comment thread
scbedd marked this conversation as resolved.
import { Swagger } from "@azure-tools/specs-shared/swagger";
import { includesFolder } from "@azure-tools/specs-shared/path";
import { getChangedFiles } from "@azure-tools/specs-shared/changed-files"; //getChangedFiles,
import { ReportableOavError } from "./formatting.js";

export async function preCheckFiltering(
Expand Down Expand Up @@ -125,24 +124,6 @@
.filter((d) => d.includes("specification" + path.sep));
}

function example(file: string): boolean {
return (
typeof file === "string" &&
file.toLowerCase().endsWith(".json") &&
includesFolder(file, "examples")
);
}

function swagger(file: string): boolean {
return (
typeof file === "string" &&
file.toLowerCase().endsWith(".json") &&
(includesFolder(file, "data-plane") || includesFolder(file, "resource-manager")) &&
includesFolder(file, "specification") &&
!includesFolder(file, "examples")
);
}

export async function processFilesToSpecificationList(
rootDirectory: string,
files: string[],
Expand Down
Loading