diff --git a/.changeset/cool-rules-shine.md b/.changeset/cool-rules-shine.md new file mode 100644 index 00000000..9267c5cf --- /dev/null +++ b/.changeset/cool-rules-shine.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": patch +--- + +Handle error when pushing git tags with the git CLI diff --git a/src/github.ts b/src/github.ts index edf7b74b..48886a8d 100644 --- a/src/github.ts +++ b/src/github.ts @@ -213,25 +213,27 @@ export class GitHub { } async pushTag(tag: string) { - if (!this.pushWithGitCli) { - return this.octokit.rest.git - .createRef({ + try { + if (!this.pushWithGitCli) { + await this.octokit.rest.git.createRef({ ...context.repo, ref: `refs/tags/${tag}`, sha: context.sha, - }) - .catch((err) => { - // Assuming tag was manually pushed in custom publish script - core.warning(`Failed to create git tag "${tag}": ${err.message}`); }); + } else { + await exec("git", ["push", "origin", tag], { + cwd: this.cwd, + env: { + ...process.env, + ...(await this.#getCliAuthEnv()), + } as Record, + }); + } + } catch (err) { + core.warning( + `Failed to create git tag "${tag}". Assuming it was manually pushed by the publish script: ${(err as Error).message}`, + ); } - await exec("git", ["push", "origin", tag], { - cwd: this.cwd, - env: { - ...process.env, - ...(await this.#getCliAuthEnv()), - } as Record, - }); } async prepareBranch(branch: string) {