Skip to content

Commit 95dd420

Browse files
committed
fix(tag-health): re-sign and re-point tags in place instead of delete + recreate
fix-non-bot-tags and fix-orphaned-tags had the same delete-then-push pattern as fix-unsigned-tags: deleting the tag behind a published release unpublishes it, and a rejected re-push leaves the tag gone. Replace with a local tag -f plus a force-updating push, which is atomic on the remote, and pass tag messages through a file instead of the shell command line. Refs #362
1 parent 6015bd7 commit 95dd420

2 files changed

Lines changed: 41 additions & 26 deletions

File tree

‎.github/actions/git/steps/fix-non-bot-tags/action.mjs‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Analyzes detailed tags list, fixes tags not created by bot, returns updated list
66
*/
77

8-
import { writeFileSync } from "fs";
8+
import { writeFileSync, unlinkSync } from "fs";
99
import { gitCommand, getTagInfo } from "../../utilities/git-utils.mjs";
1010
import { debugLog } from "../../../common/common/core.mjs";
1111
import { importGpgIfNeeded, configureGitIdentity } from "../../../github/api/_api/gpg.mjs";
@@ -80,21 +80,26 @@ function fixNonBotTag(tagObj) {
8080
// Use original message or tag name as fallback
8181
const tagMessage = tagObj.message || tagObj.name;
8282

83-
// Delete the existing tag
84-
gitCommand(`git tag -d ${tagObj.name}`, true);
85-
gitCommand(`git push origin :refs/tags/${tagObj.name}`, true);
86-
87-
// Create new annotated tag with bot signature
88-
let tagCommand = `git tag -a ${tagObj.name} ${tagObj.commitSha} -m "${tagMessage}"`;
89-
90-
if (willSign) {
91-
tagCommand = `git tag -a -s ${tagObj.name} ${tagObj.commitSha} -m "${tagMessage}"`;
83+
// Replace the tag in place — never delete it first. Deleting the tag
84+
// behind a published release turns the release back into a draft, and a
85+
// rejected re-push then leaves the tag gone (CLDMV/.github#362). A local
86+
// `tag -f` plus a force-updating push is atomic on the remote: on failure
87+
// the original tag is untouched. The message goes through a file so free
88+
// text never reaches a shell command line.
89+
const msgFile = `${process.env.RUNNER_TEMP || "/tmp"}/tag-msg-${Date.now()}.txt`;
90+
writeFileSync(msgFile, tagMessage, "utf8");
91+
try {
92+
gitCommand(`git tag -f -a ${willSign ? "-s " : ""}-F "${msgFile}" ${tagObj.name} ${tagObj.commitSha}`);
93+
} finally {
94+
try {
95+
unlinkSync(msgFile);
96+
} catch {
97+
// best-effort temp cleanup
98+
}
9299
}
93100

94-
gitCommand(tagCommand);
95-
96-
// Push the new tag
97-
gitCommand(`git push origin ${tagObj.name}`);
101+
// Force-update the remote ref to the new tag object.
102+
gitCommand(`git push origin +refs/tags/${tagObj.name}:refs/tags/${tagObj.name}`);
98103

99104
console.log(`✅ Successfully recreated tag ${tagObj.name} with bot signature`);
100105

‎.github/actions/git/steps/fix-orphaned-tags/action.mjs‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Fixes tags pointing to orphaned commits by re-pointing to equivalent commits
66
*/
77

8-
import { writeFileSync } from "fs";
8+
import { writeFileSync, unlinkSync } from "fs";
99
import { gitCommand } from "../../utilities/git-utils.mjs";
1010
import { importGpgIfNeeded, configureGitIdentity } from "../../../github/api/_api/gpg.mjs";
1111

@@ -197,25 +197,35 @@ function fixOrphanedTag(tagObj) {
197197
enableSign: GPG_ENABLED && GPG_PRIVATE_KEY
198198
});
199199

200-
// Delete the existing tag locally and remotely
201-
gitCommand(`git tag -d ${tagName}`, true);
202-
gitCommand(`git push origin :refs/tags/${tagName}`, true);
203-
204-
// Create new tag pointing to equivalent commit
200+
// Re-point the tag in place — never delete it first. Deleting the tag
201+
// behind a published release turns the release back into a draft, and a
202+
// rejected re-push then leaves the tag gone (CLDMV/.github#362). A local
203+
// `tag -f` plus a force-updating push is atomic on the remote: on failure
204+
// the original tag is untouched.
205+
const msgFile = `${process.env.RUNNER_TEMP || "/tmp"}/tag-msg-${Date.now()}.txt`;
206+
writeFileSync(msgFile, tagMessage, "utf8");
205207
let tagCommand;
206208
if (GPG_ENABLED && GPG_PRIVATE_KEY) {
207209
// Always create signed annotated tags when GPG is enabled
208-
tagCommand = `git tag -s -a ${tagName} ${equivalentCommit} -m "${tagMessage}"`;
210+
tagCommand = `git tag -f -s -a -F "${msgFile}" ${tagName} ${equivalentCommit}`;
209211
} else if (tagObj.isAnnotated) {
210-
tagCommand = `git tag -a ${tagName} ${equivalentCommit} -m "${tagMessage}"`;
212+
tagCommand = `git tag -f -a -F "${msgFile}" ${tagName} ${equivalentCommit}`;
211213
} else {
212-
tagCommand = `git tag ${tagName} ${equivalentCommit}`;
214+
tagCommand = `git tag -f ${tagName} ${equivalentCommit}`;
213215
}
214216

215-
gitCommand(tagCommand);
217+
try {
218+
gitCommand(tagCommand);
219+
} finally {
220+
try {
221+
unlinkSync(msgFile);
222+
} catch {
223+
// best-effort temp cleanup
224+
}
225+
}
216226

217-
// Push the new tag
218-
gitCommand(`git push origin ${tagName}`);
227+
// Force-update the remote ref to the re-pointed tag.
228+
gitCommand(`git push origin +refs/tags/${tagName}:refs/tags/${tagName}`);
219229

220230
console.log(`✅ Successfully re-pointed tag ${tagName} to ${equivalentCommit}`);
221231

0 commit comments

Comments
 (0)