Skip to content

Commit 97d28e9

Browse files
committed
Handle error when pushing git tags with the git CLI
1 parent 371fd77 commit 97d28e9

2 files changed

Lines changed: 20 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: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,25 +213,26 @@ 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 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+
// Assuming tag was manually pushed in custom publish script
234+
core.warning(`Failed to create tag ${tag}: ${(err as Error).message}`);
227235
}
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-
});
235236
}
236237

237238
async prepareBranch(branch: string) {

0 commit comments

Comments
 (0)