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

fix(build-cli): Consistent commit messages for dep bumps #12357

Merged
merged 3 commits into from
Oct 11, 2022
Merged
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
14 changes: 11 additions & 3 deletions build-tools/packages/build-cli/src/commands/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
import { packageOrReleaseGroupArg } from "../args";
import { BaseCommand } from "../base";
import { bumpTypeFlag, checkFlags, skipCheckFlag, versionSchemeFlag } from "../flags";
import { bumpReleaseGroup, generateBumpVersionBranchName } from "../lib";
import {
bumpReleaseGroup,
generateBumpVersionBranchName,
generateBumpVersionCommitMessage,
} from "../lib";
import { isReleaseGroup } from "../releaseGroups";

export default class BumpCommand extends BaseCommand<typeof BumpCommand.flags> {
Expand Down Expand Up @@ -158,14 +162,18 @@ export default class BumpCommand extends BaseCommand<typeof BumpCommand.flags> {
}

if (shouldCommit) {
const commitMessage = stripAnsi(
`Bump ${packageOrReleaseGroup} to ${newVersion} (${bumpType} bump)`,
const commitMessage = generateBumpVersionCommitMessage(
args.package_or_release_group,
bumpType,
repoVersion,
scheme,
);

const bumpBranch = generateBumpVersionBranchName(
args.package_or_release_group,
bumpType,
repoVersion,
scheme,
);
this.log(`Creating branch ${bumpBranch}`);
await context.createBranch(bumpBranch);
Expand Down
9 changes: 8 additions & 1 deletion build-tools/packages/build-cli/src/commands/bump/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { BaseCommand } from "../../base";
import { checkFlags, dependencyUpdateTypeFlag, releaseGroupFlag, skipCheckFlag } from "../../flags";
import {
generateBumpDepsBranchName,
generateBumpDepsCommitMessage,
indentString,
isDependencyUpdateType,
npmCheckUpdates,
Expand Down Expand Up @@ -199,7 +200,13 @@ export default class DepsCommand extends BaseCommand<typeof DepsCommand.flags> {

const changedVersionMessage = changedVersionsString.join("\n");
if (shouldCommit) {
const commitMessage = stripAnsi(`Bump dependencies\n\n${changedVersionMessage}`);
const commitMessage = stripAnsi(
`${generateBumpDepsCommitMessage(
args.package_or_release_group,
flags.updateType,
flags.releaseGroup,
)}\n\n${changedVersionMessage}`,
);

const bumpBranch = generateBumpDepsBranchName(
args.package_or_release_group,
Expand Down
7 changes: 4 additions & 3 deletions build-tools/packages/build-cli/src/handlers/checkFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { bumpVersionScheme } from "@fluid-tools/version-tools";

import {
generateBumpDepsBranchName,
generateBumpDepsCommitMessage,
generateBumpVersionBranchName,
generateCommitMessage,
generateBumpVersionCommitMessage,
generateReleaseBranchName,
getPreReleaseDependencies,
getReleaseSourceForReleaseGroup,
Expand Down Expand Up @@ -591,7 +592,7 @@ export const checkShouldCommit: StateHandlerFunction = async (
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const branchName = generateBumpVersionBranchName(releaseGroup!, bumpType!, releaseVersion!);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const commitMsg = generateCommitMessage(releaseGroup!, bumpType!, releaseVersion!);
const commitMsg = generateBumpVersionCommitMessage(releaseGroup!, bumpType!, releaseVersion!);

await context.createBranch(branchName);
log.verbose(`Created bump branch: ${branchName}`);
Expand Down Expand Up @@ -634,7 +635,7 @@ export const checkShouldCommitReleasedDepsBump: StateHandlerFunction = async (
log.verbose(`Created bump branch: ${branchName}`);
log.info(`${releaseGroup}: Bumped prerelease dependencies to release versions.`);

const commitMsg = `[dependencies] ${releaseGroup}: update prerelease dependencies to release versions`;
const commitMsg = generateBumpDepsCommitMessage("prerelease", "latest", releaseGroup);
await context.gitRepo.commit(commitMsg, `Error committing to ${branchName}`);
BaseStateHandler.signalSuccess(machine, state);
return true;
Expand Down
42 changes: 34 additions & 8 deletions build-tools/packages/build-cli/src/lib/branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function generateBumpVersionBranchName(
* @internal
*/
export function generateBumpDepsBranchName(
bumpedDep: ReleaseGroup,
bumpedDep: ReleaseGroup | ReleasePackage,
bumpType: DependencyUpdateType | VersionBumpType,
releaseGroup?: ReleaseGroup,
): string {
Expand Down Expand Up @@ -153,19 +153,15 @@ export function generateReleaseBranchName(releaseGroup: ReleaseGroup, version: s
/**
* Generates an appropriate commit message when bumping a release group or package.
*
* @param releaseGroupOrPackage - The release group or independent package to generate a branch name for.
* @param releaseGroupOrPackage - The release group or independent package to generate a commit message for.
* @param bumpType - The bump type.
* @param version - The current version of the release group or package.
* @param scheme - The version scheme to use. If this is omitted the scheme will be detected using detectVersionScheme.
* @returns The generated branch name.
*
* @remarks
*
* Generated branch names are of the form `bump_deps_<RELEASEGROUP>_<BUMPTYPE>`.
* @returns The generated commit message.
*
* @internal
*/
export function generateCommitMessage(
export function generateBumpVersionCommitMessage(
releaseGroupOrPackage: ReleaseGroup | ReleasePackage,
bumpType: VersionBumpTypeExtended,
version: ReleaseVersion,
Expand All @@ -179,6 +175,36 @@ export function generateCommitMessage(
return message;
}

/**
* Generates an appropriate commit message when bumping the dependencies of release group or package.
*
* @param bumpedDep - The release group on which dependencies were bumped.
* @param bumpType - The bump type.
* @param releaseGroup - If set, changes were made to only this release group.
* @returns The generated commit message.
*
* @internal
*/
export function generateBumpDepsCommitMessage(
bumpedDep: ReleaseGroup | ReleasePackage | "prerelease",
bumpType: DependencyUpdateType | VersionBumpType,
releaseGroup?: ReleaseGroup,
): string {
const name =
bumpedDep === "prerelease"
? "released prerelease packages"
: isReleaseGroup(bumpedDep)
? `${bumpedDep} release group`
: PackageName.getUnscopedName(bumpedDep);

const releaseGroupSegment = isReleaseGroup(releaseGroup)
? ` in the ${releaseGroup} release group`
: " in all packages and release groups";

const message = `Update deps (${bumpType}) on ${name}${releaseGroupSegment}`;
return message;
}

/**
* Returns the default bump type for a branch.
*
Expand Down
3 changes: 2 additions & 1 deletion build-tools/packages/build-cli/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

export {
generateBumpVersionBranchName,
generateBumpVersionCommitMessage,
generateBumpDepsBranchName,
generateCommitMessage,
generateBumpDepsCommitMessage,
createBumpBranch,
getDefaultBumpTypeForBranch,
getReleaseSourceForReleaseGroup,
Expand Down