From 0586125ecb8c040bd9761ea373cbe3b1546d6610 Mon Sep 17 00:00:00 2001 From: Michael Overmeyer Date: Mon, 25 Oct 2021 20:17:20 -0400 Subject: [PATCH] Delete the existing tag if `input_move_existing_tag` is set --- src/github.ts | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/github.ts b/src/github.ts index 4435876..72e513d 100644 --- a/src/github.ts +++ b/src/github.ts @@ -233,9 +233,34 @@ export const release = async ( config.input_target_commitish && config.input_target_commitish !== existingRelease.data.target_commitish ) { - console.log( - `Updating commit from "${existingRelease.data.target_commitish}" to "${config.input_target_commitish}"` - ); + + if (config.input_move_existing_tag) { + console.log( + `Deleting and recreating tag "${tag}". Moving it from "${existingRelease.data.target_commitish}" to "${config.input_target_commitish}"` + ); + try { + await releaser.deleteTag({ + owner, + repo, + ref: tag, + }); + } catch (error) { + console.log( + `⚠️ Failed to delete tag "${tag}" with status: ${ + error.status + }\n${JSON.stringify( + error.response.data.errors + )}\nretrying... (${maxRetries - 1} retries remaining)` + ); + return release(config, releaser, maxRetries - 1); + } + } else if (existingRelease.data.target_commitish != undefined) { + console.log( + `⚠️ Release tag "${tag}" already points at "${existingRelease.data.target_commitish}"; will not update the tag to point at target_commitish "${config.input_target_commitish}". \ + Set move_existing_tag to true if you want to delete and recreate the "${tag}" existing tag at the new target_commitish.` + ); + } + target_commitish = config.input_target_commitish; } else { target_commitish = existingRelease.data.target_commitish;