From 88338839e35c3e0fa61f3c9c3f27e7572cd5f2cf Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Mon, 7 Sep 2026 11:45:47 +0000 Subject: [PATCH] Handle error when pushing git tags with the git CLI (#735) * Handle error when pushing git tags with the git CLI * Update message --- .changeset/cool-rules-shine.md | 5 +++++ src/github.ts | 30 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 .changeset/cool-rules-shine.md diff --git a/.changeset/cool-rules-shine.md b/.changeset/cool-rules-shine.md new file mode 100644 index 0000000..9267c5c --- /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 edf7b74..48886a8 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) {