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

add --force flag/config option to "next" command #1776

Merged
merged 1 commit into from Feb 4, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions packages/cli/src/parse-args.ts
Expand Up @@ -216,6 +216,13 @@ const noChangelog: AutoOption = {
config: true,
};

const force: AutoOption = {
name: "force",
type: Boolean,
group: "main",
config: true,
};

interface AutoCommand extends Command {
/** Options for the command */
options?: AutoOption[];
Expand Down Expand Up @@ -566,12 +573,9 @@ export const commands: AutoCommand[] = [
config: true,
},
{
name: "force",
type: Boolean,
group: "main",
...force,
description:
"Force a canary release, even if the PR is marked to skip the release",
config: true,
"Force a next release, even if the last commit is marked to skip the release",
},
quiet,
],
Expand All @@ -596,6 +600,11 @@ export const commands: AutoCommand[] = [
"The message used when attaching the prerelease version to a PR",
config: true,
},
{
...force,
description:
"Force a canary release, even if the PR is marked to skip the release",
},
quiet,
],
},
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/__tests__/auto.test.ts
Expand Up @@ -1382,6 +1382,33 @@ describe("Auto", () => {
await auto.next({});
expect(next).not.toHaveBeenCalled();
});

test("can --force release", async () => {
const auto = new Auto({ ...defaults, plugins: [] });

// @ts-ignore
auto.checkClean = () => Promise.resolve(true);
auto.logger = dummyLog();
await auto.loadConfig();
auto.remote = "origin";
auto.git!.publish = () => Promise.resolve({ data: {} } as any);
auto.git!.getLastTagNotInBaseBranch = () =>
Promise.reject(new Error("Test"));
auto.git!.getLatestTagInBranch = () => Promise.reject(new Error("Test"));
auto.git!.getLatestRelease = () => Promise.resolve("abcd");
auto.release!.generateReleaseNotes = () => Promise.resolve("notes");
auto.release!.getCommitsInRelease = () =>
Promise.resolve([
makeCommitFromMsg("Test Commit", { labels: ["skip-release"] }),
]);

const next = jest.fn();
auto.hooks.next.tap("test", next);
jest.spyOn(auto.release!, "getCommits").mockImplementation();

await auto.next({ force: true });
expect(next).toHaveBeenCalled();
});
});

describe("shipit", () => {
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/auto-args.ts
Expand Up @@ -154,7 +154,12 @@ export type IShipItOptions = ILatestOptions & {
onlyGraduateWithReleaseLabel?: boolean;
};

export type ICanaryOptions = QuietOption & {
interface ForceOption {
/** Always deploy even if marked as skip release */
force?: boolean;
}

export type ICanaryOptions = QuietOption & ForceOption & {
/** Do not actually do anything */
dryRun?: boolean;
/** THe PR to attach the canary to */
Expand All @@ -163,11 +168,9 @@ export type ICanaryOptions = QuietOption & {
build?: number;
/** The message used when attaching the canary version to a PR */
message?: string | "false";
/** Always deploy a canary, even if the PR is marked as skip release */
force?: boolean;
};

export type INextOptions = QuietOption & {
export type INextOptions = QuietOption & ForceOption & {
/** Do not actually do anything */
dryRun?: boolean;
/** The message used when attaching the prerelease version to a PR */
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/auto.ts
Expand Up @@ -1390,11 +1390,15 @@ export default class Auto {
const commits = await this.release.getCommitsInRelease(lastTag);
const releaseNotes = await this.release.generateReleaseNotes(lastTag);
const labels = commits.map((commit) => commit.labels);
const bump = calculateSemVerBump(labels, this.semVerLabels!, this.config);
let bump = calculateSemVerBump(labels, this.semVerLabels!, this.config);

if (bump === "") {
this.logger.log.info("No version published.");
return;
if (bump === SEMVER.noVersion) {
if (options.force) {
bump = SEMVER.patch;
} else {;
this.logger.log.info("No version published.");
return;
}
}

if (!args.quiet) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Expand Up @@ -102,6 +102,7 @@ export const globalOptions = t.partial({
}),
/** Options to pass to "auto next" */
next: t.partial({
force: t.boolean,
message: t.string,
}),
});
Expand Down