Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Refresh existing tag to current commit if unpublished

Richie McIlroy3e2fc1b2a53d
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index a5d626960..838dddb4d 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -54,17 +54,19 @@ jobs:
async function main() {
let tagExisted = true;
+ let tagSha = "";
let releasePublished = false;
let releaseUrl = "";
try {
- await github.rest.git.getRef({
+ const tagRefResponse = await github.rest.git.getRef({
ref: tagRef,
owner: context.repo.owner,
repo: context.repo.repo,
});
tagExisted = true;
+ tagSha = tagRefResponse.data.object.sha;
core.notice(`Tag '${tag}' already exists. Reusing it for this release run.`);
} catch (error) {
if ("status" in error && error.status === 404) tagExisted = false;
@@ -97,6 +99,18 @@ jobs:
core.notice(`Draft release '${tag}' already exists. Continuing build and upload.`);
}
+ if (tagExisted && !releasePublished && tagSha !== context.sha) {
+ await github.rest.git.updateRef({
+ ref: tagRef,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ sha: context.sha,
+ force: true,
+ });
+
+ core.notice(`Updated unpublished tag '${tag}' to ${context.sha}.`);
+ }
+
core.setOutput(TAG_EXISTED, tagExisted);
core.setOutput(RELEASE_PUBLISHED, releasePublished);
core.setOutput(RELEASE_URL, releaseUrl);