Skip to content

Commit 8833883

Browse files
authored
Handle error when pushing git tags with the git CLI (#735)
* Handle error when pushing git tags with the git CLI * Update message
1 parent e08fde7 commit 8833883

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

.changeset/cool-rules-shine.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/action": patch
3+
---
4+
5+
Handle error when pushing git tags with the git CLI

src/github.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,25 +213,27 @@ export class GitHub {
213213
}
214214

215215
async pushTag(tag: string) {
216-
if (!this.pushWithGitCli) {
217-
return this.octokit.rest.git
218-
.createRef({
216+
try {
217+
if (!this.pushWithGitCli) {
218+
await this.octokit.rest.git.createRef({
219219
...context.repo,
220220
ref: `refs/tags/${tag}`,
221221
sha: context.sha,
222-
})
223-
.catch((err) => {
224-
// Assuming tag was manually pushed in custom publish script
225-
core.warning(`Failed to create git tag "${tag}": ${err.message}`);
226222
});
223+
} else {
224+
await exec("git", ["push", "origin", tag], {
225+
cwd: this.cwd,
226+
env: {
227+
...process.env,
228+
...(await this.#getCliAuthEnv()),
229+
} as Record<string, string>,
230+
});
231+
}
232+
} catch (err) {
233+
core.warning(
234+
`Failed to create git tag "${tag}". Assuming it was manually pushed by the publish script: ${(err as Error).message}`,
235+
);
227236
}
228-
await exec("git", ["push", "origin", tag], {
229-
cwd: this.cwd,
230-
env: {
231-
...process.env,
232-
...(await this.#getCliAuthEnv()),
233-
} as Record<string, string>,
234-
});
235237
}
236238

237239
async prepareBranch(branch: string) {

0 commit comments

Comments
 (0)