in eng/tools/lint-diff/src/processChanges.ts [301:341]
export async function getAffectedReadmes(
changedFiles: string[],
repoRoot: string,
): Promise<string[]> {
// OK to use / because changedFiles comes from git which always uses /
const changedFilesInSpecDir = changedFiles.filter((file) => file.startsWith(`specification/`));
const changedReadmeFiles = [];
for (const file of changedFilesInSpecDir) {
if (file.toLowerCase().endsWith(`/readme.md`) && (await pathExists(join(repoRoot, file)))) {
changedReadmeFiles.push(file);
}
}
const changedSpecFiles = changedFilesInSpecDir.filter((f) =>
[".md", ".json", ".yaml", ".yml"].some((p) => f.toLowerCase().endsWith(p)),
);
const readmeFiles = new Set<string>(changedReadmeFiles);
const visitedFolders = new Set<string>();
// For each changed spec file, walk up the directory tree collecting readme
// files until reaching the "specification/" directory (already filtered in
// changedFilesInSpecDir)
for (const specFile of changedSpecFiles) {
let dir = dirname(specFile);
// Exclude '.' as it is outside the specification folder for purposes of
// this function (avoid including root readme.md file)
while (!visitedFolders.has(dir) && dir !== "specification") {
visitedFolders.add(dir);
// TODO: Case sensitivity??
const readmeFile = join(repoRoot, dir, "readme.md");
if (await pathExists(readmeFile)) {
readmeFiles.add(join(dir, "readme.md"));
}
dir = dirname(dir);
}
}
return [...readmeFiles];
}