Skip to content

Commit

Permalink
fix: skip existing git tags for private pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
gakonst committed Apr 14, 2021
1 parent cc409aa commit 2147633
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/cli/src/commands/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ export default async function run(
if (tool !== "root") {
for (const pkg of successful) {
const tag = `${pkg.name}@${pkg.newVersion}`;
log("New tag: ", tag);
await git.tag(tag, cwd);
const isMissingTag = !(await git.tagExists(tag));
if (isMissingTag) {
log("New tag: ", tag);
await git.tag(tag, cwd);
} else {
log("Skipping existing tag: ", tag);
}
}
} else {
const tag = `v${successful[0].newVersion}`;
Expand Down
8 changes: 8 additions & 0 deletions packages/git/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ async function tag(tagStr: string, cwd: string) {
return gitCmd.code === 0;
}

async function tagExists(tagStr: string) {
const gitCmd = await spawn("git", ["tag", "-l", tagStr]);
const output = gitCmd.stdout.toString().trim();
const tagExists = !!output;
return tagExists;
}

// Find the commit where we diverged from `ref` at using `git merge-base`
export async function getDivergedCommit(cwd: string, ref: string) {
const cmd = await spawn("git", ["merge-base", ref, "HEAD"], { cwd });
Expand Down Expand Up @@ -259,6 +266,7 @@ export {
add,
commit,
tag,
tagExists,
getChangedPackagesSinceRef,
getChangedChangesetFilesSinceRef
};

0 comments on commit 2147633

Please sign in to comment.