Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Policy Check into Bump Version Tool #5552

Merged
merged 11 commits into from
Mar 24, 2021
8 changes: 7 additions & 1 deletion tools/build-tools/src/bumpVersion/createBranch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Context, VersionBumpType } from "./context";
import { getReleasedPrereleaseDependencies } from "./bumpDependencies";
import { bumpRepo } from "./bumpVersion";
import { ReferenceVersionBag, getRepoStateChange } from "./versionBag";
import { fatal } from "./utils";
import { fatal, runPolicyCheckWithFix, } from "./utils";
import { MonoRepoKind } from "../common/monoRepo";
import { Package } from "../common/npmPackage";
import * as semver from "semver";
Expand All @@ -17,6 +17,12 @@ import * as semver from "semver";
* and push it to `main` and the new release branch to remote
*/
export async function createReleaseBranch(context: Context) {

// run policy check before creating release branch.
// right now this only does assert short codes
// but could also apply other fixups in the future
await runPolicyCheckWithFix(context.gitRepo);

const remote = await context.gitRepo.getRemote(context.originRemotePartialUrl);
if (!remote) {
fatal(`Unable to find remote for '${context.originRemotePartialUrl}'`)
Expand Down
8 changes: 7 additions & 1 deletion tools/build-tools/src/bumpVersion/releaseVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Context, VersionBumpType } from "./context";
import { bumpDependencies } from "./bumpDependencies";
import { bumpVersion } from "./bumpVersion";
import { fatal } from "./utils";
import { fatal, runPolicyCheckWithFix } from "./utils";
import { MonoRepo, MonoRepoKind } from "../common/monoRepo";
import { Package } from "../common/npmPackage";

Expand All @@ -25,6 +25,12 @@ export function getPackageShortName(pkgName: string) {
* If --commit or --release is specified, the bumpped version changes will be committed and a release branch will be created
*/
export async function releaseVersion(context: Context, releaseName: string, updateLock: boolean, releaseVersion?: VersionBumpType) {

// run policy check before releasing a version.
// right now this only does assert short codes
// but could also apply other fixups in the future
await runPolicyCheckWithFix(context.gitRepo);

if (releaseVersion === undefined) {
if (!context.originalBranchName.startsWith("release/")) {
fatal(`Patch release should only be done on 'release/*' branches, but current branch is '${context.originalBranchName}'`);
Expand Down
21 changes: 21 additions & 0 deletions tools/build-tools/src/bumpVersion/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,24 @@ export class GitRepo {
return execNoError(`git ${command}`, this.resolvedRoot, pipeStdIn);
}
}

/**
* Runs policy check in fix/resolution mode the apply any an necessary changes
* Currently this should only apply assert short codes, but could apply
* additional policies in the future
* @param gitRepo - the git repo context to run policy check on
*/
export async function runPolicyCheckWithFix(gitRepo: GitRepo){
console.log("Running Policy Check with Resolution(fix)");
await exec(
`node ${__dirname}\\..\\repoPolicyCheck\\repoPolicyCheck.js -r -q`,
gitRepo.resolvedRoot,
"policy-check:fix failed");

// check for policy check violation
const afterPolicyCheckStatus = await gitRepo.getStatus();
if (afterPolicyCheckStatus !== "") {
console.log("======================================================================================================");
fatal(`Policy check needed to make modifications. Please create PR for the changes and merge before retrying.\n${afterPolicyCheckStatus}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getAssertMessageParams(sourceFile: SourceFile): (StringLiteral | Numeri

export const handler: Handler = {
name: "assert-short-codes",
match: /^(packages)\/.*\/tsconfig\.json/i,
match: /^(packages|(common\/lib\/common-utils)|(server\/routerlicious\/packages\/protocol-base)).*\/tsconfig\.json/i,
handler: (tsconfigPath) => {
if(tsconfigPath.includes("test")){
return;
Expand Down