export async function runChecks()

in eng/tools/lint-diff/src/runChecks.ts [14:77]


export async function runChecks(
  path: string,
  runList: Map<string, string[]>,
): Promise<AutorestRunResult[]> {
  const dependenciesDir = await getPathToDependency("@microsoft.azure/openapi-validator");
  const result: AutorestRunResult[] = [];

  for (const [readme, tags] of runList.entries()) {
    const changedFilePath = join(path, readme);

    // TODO: Move this into getRunList
    let openApiType = await getOpenapiType(changedFilePath);

    // From momentOfTruth.ts:executeAutoRestWithLintDiff
    // This is a quick workaround for https://github.com/Azure/azure-sdk-tools/issues/6549
    // We override the openapi-subtype with the value of openapi-type,
    // to prevent LintDiff from reading openapi-subtype from the AutoRest config file (README)
    // and overriding openapi-type with it.
    let openApiSubType = openApiType;

    // If the tags array is empty run the loop once but with a null tag
    const coalescedTags = tags?.length ? tags : [null];
    for (const tag of coalescedTags) {
      let tagArg = tag ? `--tag=${tag} ` : "";

      let autorestCommand =
        `npm exec --no -- autorest ` +
        `--v3 ` +
        `--spectral ` +
        `--azure-validator ` +
        `--semantic-validator=false ` +
        `--model-validator=false ` +
        `--message-format=json ` +
        `--openapi-type=${openApiType} ` +
        `--openapi-subtype=${openApiSubType} ` +
        `--use=${dependenciesDir} ` +
        `${tagArg} ` +
        `${changedFilePath}`;

      console.log(`::group::Autorest for type: ${openApiType} readme: ${readme} tag: ${tag}`);
      console.log(`\tAutorest command: ${autorestCommand}`);

      const executionResult = await executeCommand(autorestCommand);
      
      console.log(executionResult.stderr + executionResult.stdout);

      const lintDiffResult = {
        autorestCommand,
        rootPath: path,
        readme,
        tag: tag ? tag : "",
        openApiType,
        ...executionResult,
      };
      logAutorestExecutionErrors(lintDiffResult);
      console.log("::endgroup::");

      result.push(lintDiffResult);
      console.log(`\tAutorest result length: ${lintDiffResult.stderr.length + lintDiffResult.stdout.length}\n`);
    }
  }

  return result;
}