Add check everything to packages

This commit is contained in:
Dan Schulte 2019-01-02 14:06:13 -08:00
Родитель 1224cf666b
Коммит abdfdceffd
3 изменённых файлов: 93 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,84 @@
import { checkEverything, contains, fileExistsSync, getChildFolderPaths, getDefaultLogger, getName, gitDiff, GitDiffResult, gitStatus, GitStatusResult, joinPath, Logger, normalize, resolvePath } from "@ts-common/azure-js-dev-tools";
import * as path from "path";
import * as yargs from "yargs";
const logger: Logger = getDefaultLogger({ logVerbose: true });
function getArgument(argumentName: string, environmentVariableName?: string, defaultValue?: string): string | undefined {
let rawArgument: string | string[] | undefined = yargs.argv[argumentName] || process.env[environmentVariableName || argumentName] || defaultValue;
if (Array.isArray(rawArgument)) {
rawArgument = rawArgument[rawArgument.length - 1];
}
return rawArgument;
}
const headReference: string | undefined = getArgument("head-reference", "headReference");
const baseReference: string | undefined = getArgument("base-reference", "baseReference");
const changedFiles: string[] = [];
let packBaseReference: string | undefined = baseReference;
if (!packBaseReference) {
packBaseReference = "master";
logger.logInfo(`No base-reference argument specified on command line or in environment variables. Defaulting to "${packBaseReference}".`);
}
let packHeadReference: string | undefined = headReference;
if (!packHeadReference) {
const statusResult: GitStatusResult = gitStatus();
packHeadReference = statusResult.localBranch!;
logger.logInfo(`No head-reference argument specified on command line or in environment variables. Defaulting to "${packHeadReference}".`);
const modifiedFiles: string[] | undefined = statusResult.modifiedFiles;
if (modifiedFiles) {
changedFiles.push(...modifiedFiles);
}
}
if (packBaseReference !== packHeadReference) {
const diffResult: GitDiffResult = gitDiff(packBaseReference, packHeadReference);
changedFiles.push(...diffResult.filesChanged);
if (!changedFiles || changedFiles.length === 0) {
logger.logInfo(`Found no changes between "${packBaseReference}" and "${packHeadReference}".`);
} else {
logger.logVerbose(`Found the following changed files`)
for (const changedFilePath of changedFiles) {
logger.logVerbose(changedFilePath);
}
}
}
const folderNamesToIgnore: string[] = ["node_modules"];
const repositoryFolderPath: string = resolvePath(__dirname, "..");
const packagesFolderPath: string = joinPath(repositoryFolderPath, "packages");
const packageFolderPaths: string[] | undefined = getChildFolderPaths(packagesFolderPath, {
recursive: true,
condition: (folderPath: string) => fileExistsSync(joinPath(folderPath, "package.json")),
folderCondition: (folderPath: string) => !contains(folderNamesToIgnore, getName(folderPath))
});
let exitCode: number = 0;
if (!packageFolderPaths) {
logger.logError(`The packages folder (${packagesFolderPath}) doesn't exist.`);
} else {
logger.logVerbose(`Found ${packageFolderPaths.length} package folders.`);
for (const packageFolderPath of packageFolderPaths) {
const packageFolderPathWithSep: string = normalize(packageFolderPath + path.posix.sep);
const shouldCheck = !!changedFiles && contains(changedFiles, (changedFilePath: string) => normalize(changedFilePath).startsWith(packageFolderPathWithSep));
if (shouldCheck) {
exitCode += checkEverything({
logger,
checkPackageJsonVersionOptions: {
startPath: packageFolderPath
},
checkForOnlyCallsOptions: {
startPaths: packageFolderPath
},
checkForSkipCallsOptions: {
startPaths: packageFolderPath
}
});
}
}
}
process.exitCode = exitCode;

Просмотреть файл

@ -20,6 +20,13 @@ steps:
inputs:
verbose: false
- task: Npm@1
displayName: 'npm run check:everything'
inputs:
command: custom
verbose: false
customCommand: 'run check:everything -- --head-reference=origin/$(System.PullRequest.SourceBranch) --base-reference=origin/$(System.PullRequest.TargetBranch) --azure-devops'
- task: Npm@1
displayName: 'npm run build'
inputs:

Просмотреть файл

@ -29,6 +29,7 @@
},
"scripts": {
"build": "gulp pack --logging-level=info",
"check:everything": "ts-node ./.scripts/checkEverything.ts",
"install-client-keyvault": "cd packages/@azure/keyvault && npm install",
"install-client-template": "cd packages/@azure/template && npm install",
"install-client": "npm-run-all -p -l install-client-*",
@ -46,7 +47,7 @@
},
"devDependencies": {
"@octokit/rest": "15.17.0",
"@ts-common/azure-js-dev-tools": "^0.6.0",
"@ts-common/azure-js-dev-tools": "^0.6.8",
"@types/glob": "^7.1.1",
"@types/gulp": "^4.0.5",
"@types/js-yaml": "^3.11.2",