Skip to content

Commit

Permalink
Added support for a --no-git-tag CLI flag that can be used with `ch…
Browse files Browse the repository at this point in the history
…angeset publish` (#701)
  • Loading branch information
Andarist committed Dec 16, 2021
1 parent 4272cb0 commit b9b6453
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-wolves-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": minor
---

Added support for a `--no-git-tag` CLI flag that can be used with `changeset publish` to skip creating git tags for published packages. This is mostly useful when publishing snapshot releases.
27 changes: 15 additions & 12 deletions packages/cli/src/commands/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function showNonLatestTagWarning(tag?: string, preState?: PreState) {

export default async function run(
cwd: string,
{ otp, tag }: { otp?: string; tag?: string },
{ otp, tag, gitTag = true }: { otp?: string; tag?: string; gitTag?: boolean },
config: Config
) {
const releaseTag = tag && tag.length > 0 ? tag : undefined;
Expand Down Expand Up @@ -72,20 +72,23 @@ export default async function run(
if (successful.length > 0) {
success("packages published successfully:");
logReleases(successful);
// We create the tags after the push above so that we know that HEAD wont change and that pushing
// wont suffer from a race condition if another merge happens in the mean time (pushing tags wont
// fail if we are behind the base branch).
log(`Creating git tag${successful.length > 1 ? "s" : ""}...`);
if (tool !== "root") {
for (const pkg of successful) {
const tag = `${pkg.name}@${pkg.newVersion}`;

if (gitTag) {
// We create the tags after the push above so that we know that HEAD wont change and that pushing
// wont suffer from a race condition if another merge happens in the mean time (pushing tags wont
// fail if we are behind the base branch).
log(`Creating git tag${successful.length > 1 ? "s" : ""}...`);
if (tool !== "root") {
for (const pkg of successful) {
const tag = `${pkg.name}@${pkg.newVersion}`;
log("New tag: ", tag);
await git.tag(tag, cwd);
}
} else {
const tag = `v${successful[0].newVersion}`;
log("New tag: ", tag);
await git.tag(tag, cwd);
}
} else {
const tag = `v${successful[0].newVersion}`;
log("New tag: ", tag);
await git.tag(tag, cwd);
}
}

Expand Down
15 changes: 11 additions & 4 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { run } from "./run";
const { input, flags } = meow(
`
Usage
$ changesets [command]
$ changeset [command]
Commands
init
add [--empty] [--open]
version [--ignore]
publish [--otp=code]
status [--since <branch>] [--verbose] [--output=JSON_FILE.json]
version [--ignore] [--snapshot <?name>]
publish [--tag <name>] [--otp <code>] [--no-git-tag]
status [--since <branch>] [--verbose] [--output JSON_FILE.json]
pre <enter|exit> <tag>
tag
`,
Expand Down Expand Up @@ -48,7 +48,14 @@ const { input, flags } = meow(
},
open: {
type: "boolean"
},
gitTag: {
type: "boolean",
default: true
}
// mixed type like this is not supported by `meow`
// if it gets passed explicitly then it's still available on the flags with an inferred type though
// snapshot: { type: "boolean" | "string" },
}
}
);
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export async function run(
ignore,
snapshot,
tag,
open
open,
gitTag
}: CliOptions = flags;
const deadFlags = ["updateChangelog", "isPublic", "skipCI", "commit"];

Expand All @@ -104,7 +105,6 @@ export async function run(

switch (input[0]) {
case "add": {
// @ts-ignore if this is undefined, we have already exited
await add(cwd, { empty, open }, config);
return;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ export async function run(
return;
}
case "publish": {
await publish(cwd, { otp, tag }, config);
await publish(cwd, { otp, tag, gitTag }, config);
return;
}
case "status": {
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { AccessType } from "@changesets/types";

export type CliOptions = {
commit?: boolean;
changelog?: string;
access?: AccessType;
sinceMaster?: boolean;
verbose?: boolean;
output?: string;
Expand All @@ -13,6 +8,7 @@ export type CliOptions = {
ignore?: string | string[];
snapshot?: string | boolean;
tag?: string;
gitTag?: boolean;
open?: boolean;
};

Expand Down

0 comments on commit b9b6453

Please sign in to comment.