Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import chalk from "picocolors";
import { findPackageOrReleaseGroup, packageOrReleaseGroupArg } from "../../args.js";
import { BaseCommand } from "../../library/index.js";
import {
CheckCompatLayerGeneration,
CheckDependenciesInstalled,
type CheckFunction,
CheckHasNoPrereleaseDependencies,
Expand All @@ -32,6 +33,7 @@ const allChecks: ReadonlyMap<string, CheckFunction> = new Map([
["Has no pre-release Fluid dependencies", CheckHasNoPrereleaseDependencies],
["No repo policy violations", CheckNoPolicyViolations],
["No untagged asserts", CheckNoUntaggedAsserts],
["Compatibility layer generation is up to date", CheckCompatLayerGeneration],
]);

/**
Expand Down
16 changes: 4 additions & 12 deletions build-tools/packages/build-cli/src/handlers/checkFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getPreReleaseDependencies,
getReleaseSourceForReleaseGroup,
isReleased,
runCompatLayerGenerationCheck,
} from "../library/index.js";
import type { CommandLogger } from "../logging.js";
import type { MachineState } from "../machines/index.js";
Expand Down Expand Up @@ -931,21 +932,12 @@ export const checkCompatLayerGeneration: StateHandlerFunction = async (
return true;
}

// layerGeneration:gen should be run from the root. It will only update packages that have the layerGeneration:gen
// script defined in their package.json.
const result = await execa.command(`pnpm run -r layerGeneration:gen`, {
cwd: context.root,
});
log.verbose(result.stdout);
const isUpToDate = await runCompatLayerGenerationCheck(context);

// check for policy check violation
const gitRepo = await context.getGitRepository();
const afterPolicyCheckStatus = await gitRepo.gitClient.status();
const isClean = afterPolicyCheckStatus.isClean();
if (!isClean) {
if (!isUpToDate) {
log.logHr();
log.errorLog(
`Layer generation needs to be updated. Please create a PR for the changes and merge before retrying.\n${afterPolicyCheckStatus.files.map((fileStatus) => `${fileStatus.index} ${fileStatus.path}`).join("\n")}`,
`Layer generation needs to be updated. Please create a PR for the changes and merge before retrying.`,
);
BaseStateHandler.signalFailure(machine, state);
return false;
Expand Down
1 change: 1 addition & 0 deletions build-tools/packages/build-cli/src/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ export {
} from "./release.js";
export { LayerGraph } from "./layerGraph.js";
export { type Handler, policyHandlers } from "./repoPolicyCheck/index.js";
export { runCompatLayerGenerationCheck } from "./releasePrepChecks.js";
46 changes: 46 additions & 0 deletions build-tools/packages/build-cli/src/library/releasePrepChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,49 @@ export const CheckNoUntaggedAsserts: CheckFunction = async (
};
}
};

/**
* Runs the compatibility layer generation command and checks if it made any changes to the repository.
* This is a shared helper function used by both the prepare command checks and the state machine checks.
*
* @param context - The repository context.
* @returns `true` if no changes were made (i.e., layer generation is up to date), `false` otherwise.
*/
export async function runCompatLayerGenerationCheck(context: Context): Promise<boolean> {
// layerGeneration:gen should be run from the root. It will only update packages that have the layerGeneration:gen
// script defined in their package.json.
await execa("pnpm", ["run", "-r", "layerGeneration:gen"], {
cwd: context.root,
});

// check if the command made any changes
const gitRepo = await context.getGitRepository();
const afterGenStatus = await gitRepo.gitClient.status();
const isClean = afterGenStatus.isClean();

// Reset any changes that were made
if (!isClean) {
await gitRepo.gitClient.reset(ResetMode.HARD);
}

return isClean;
}

/**
* Checks that the compatibility layer generation is up to date. Any necessary changes will return a failure result.
*/
export const CheckCompatLayerGeneration: CheckFunction = async (
context: Context,
_releaseGroupOrPackage: MonoRepo | Package,
): Promise<CheckResult> => {
const isUpToDate = await runCompatLayerGenerationCheck(context);

if (!isUpToDate) {
return {
message: "Layer generation needs to be updated.",
fixCommand: "pnpm run -r layerGeneration:gen",
};
}

return;
};