Handle error when pushing git tags with the git CLI (#735)

* Handle error when pushing git tags with the git CLI

* Update message
This commit is contained in:
Bjorn Lu
2026-09-07 11:45:47 +00:00
committed by GitHub
parent e08fde7435
commit 88338839e3
2 changed files with 21 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@changesets/action": patch
---
Handle error when pushing git tags with the git CLI
+9 -7
View File
@@ -213,18 +213,14 @@ export class GitHub {
} }
async pushTag(tag: string) { async pushTag(tag: string) {
try {
if (!this.pushWithGitCli) { if (!this.pushWithGitCli) {
return this.octokit.rest.git await this.octokit.rest.git.createRef({
.createRef({
...context.repo, ...context.repo,
ref: `refs/tags/${tag}`, ref: `refs/tags/${tag}`,
sha: context.sha, 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], { await exec("git", ["push", "origin", tag], {
cwd: this.cwd, cwd: this.cwd,
env: { env: {
@@ -233,6 +229,12 @@ export class GitHub {
} as Record<string, string>, } as Record<string, string>,
}); });
} }
} catch (err) {
core.warning(
`Failed to create git tag "${tag}". Assuming it was manually pushed by the publish script: ${(err as Error).message}`,
);
}
}
async prepareBranch(branch: string) { async prepareBranch(branch: string) {
await switchToMaybeExistingBranch(branch, { cwd: this.cwd }); await switchToMaybeExistingBranch(branch, { cwd: this.cwd });