Skip to content

Commit 6015bd7

Browse files
committed
fix(release): stop tag-health unpublishing releases; release notes from changelog files
Push-triggered publishes created the vX.Y.Z tag lightweight and unsigned (use_gpg is only true on manual dispatch), so the standalone tag-health run on release:published "fixed" it by deleting the remote tag and pushing a signed one. Deleting the tag behind a published release turns the release back into a draft; when the re-push was rejected (ref-lock race, or the App workflow-permission push check for a tag off the branch tip) the tag stayed gone, the release stayed a draft, and the step still logged "Fixed 0" and exited 0. CLDMV/configs v1.2.0 and v1.2.2 ended up like that. - reusable-publishing: sign release tags whenever the GPG key secret is mapped, not only when use_gpg is passed. - fix-unsigned-tags: replace a tag with an atomic force-update, never a delete; a rejected push leaves the original tag in place. End-state check re-publishes a release the update turned into a draft, and fails the job when a release is left a draft or a tag is missing. - create-release: final gate that fails unless the release is published and its tag exists. - create-release: use docs/changelog[s]/v<major>/v<version>.md at the release commit as the release body when present, keeping the coverage and Contributors blocks. - release/create: drop the duplicated "release: vX.Y.Z - ..." subject line and squash trailers; wrap accidental @word / @org/team mentions outside code in code spans, keeping the Contributors handles live (replaces the zero-width-space JSDoc-tag list). - fix-orphaned-releases: page through all releases, not the first 30. - New workflow-sync-release-notes.yml + sync-release-notes action + consumer template: re-sync release bodies from changelog files and report (on opt-in, repair) drafts, missing tags, missing releases and duplicates. Fixes #362
1 parent bb8e5cb commit 6015bd7

17 files changed

Lines changed: 1161 additions & 143 deletions

File tree

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

Lines changed: 112 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* Fixes all unsigned and lightweight tags by recreating them as signed annotated tags
66
*/
77

8-
import { writeFileSync } from "fs";
8+
import { writeFileSync, unlinkSync } from "fs";
9+
import { execFileSync } from "node:child_process";
910
import { gitCommand } from "../../utilities/git-utils.mjs";
1011
import { debugLog } from "../../../common/common/core.mjs";
1112
import { importGpgIfNeeded, configureGitIdentity } from "../../../github/api/_api/gpg.mjs";
@@ -92,6 +93,28 @@ async function reassertPublished(releaseId) {
9293

9394
console.log(`🔍 DEBUG: Processing ${TAGS_DETAILED.length} tags for unsigned analysis`);
9495

96+
// Tags whose signing push was rejected. The remote tag is untouched in that case
97+
// (we never delete it), so these are warnings, not breakage.
98+
const failedTags = [];
99+
// Releases this run touched, so the end-state check can confirm none was left
100+
// as a draft and no tag went missing.
101+
const touched = [];
102+
103+
/**
104+
* Run git with an argument vector (no shell) and capture stdout+stderr, so a
105+
* push rejection carries git's actual reason instead of "Command failed".
106+
* @param {string[]} args - git arguments.
107+
* @returns {{ok: boolean, output: string}} Result.
108+
*/
109+
function git(args) {
110+
try {
111+
const out = execFileSync("git", args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
112+
return { ok: true, output: out.trim() };
113+
} catch (error) {
114+
return { ok: false, output: `${error.stdout || ""}${error.stderr || ""}`.trim() || error.message };
115+
}
116+
}
117+
95118
/**
96119
* Check if a tag needs signing/annotation fixes
97120
* @param {object} tagObj - Tag object from detailed analysis
@@ -130,6 +153,11 @@ async function fixUnsignedTag(tagObj) {
130153

131154
console.log(`🔐 Converting tag ${tagName} to signed/annotated tag...`);
132155

156+
if (!/^[\w.@+\/-]+$/.test(tagName) || tagName.startsWith("-")) {
157+
console.warn(`::warning::Skipping tag with an unexpected name: ${JSON.stringify(tagName)}`);
158+
return null;
159+
}
160+
133161
// Get the commit this tag points to
134162
const commitSha = tagObj.commitSha || gitCommand(`git rev-list -n 1 ${tagName}`, true);
135163
if (!commitSha) {
@@ -150,21 +178,40 @@ async function fixUnsignedTag(tagObj) {
150178
debugLog(`Tag ${tagName} is bound to release ${existingRelease.id} (draft: ${existingRelease.draft})`);
151179
}
152180

153-
// Delete the existing tag locally and remotely
154-
gitCommand(`git tag -d ${tagName}`, true);
155-
gitCommand(`git push origin :refs/tags/${tagName}`, true);
156-
157-
// Create new annotated and potentially signed tag
158-
let tagCommand = `git tag -a ${tagName} ${commitSha} -m "${tagMessage}"`;
181+
touched.push({ tagName, release: existingRelease, wasPublished });
159182

160-
if (GPG_ENABLED && GPG_PRIVATE_KEY) {
161-
tagCommand = `git tag -a -s ${tagName} ${commitSha} -m "${tagMessage}"`;
183+
// Build the replacement tag object locally (replacing only the LOCAL ref).
184+
// The message goes through a file: it is free text and must never be
185+
// spliced into a shell command line.
186+
const msgFile = `${process.env.RUNNER_TEMP || "/tmp"}/tag-msg-${Date.now()}-${Math.random().toString(36).slice(2)}.txt`;
187+
writeFileSync(msgFile, tagMessage, "utf8");
188+
const tagArgs = ["tag", "-f", "-a", ...(GPG_ENABLED && GPG_PRIVATE_KEY ? ["-s"] : []), "-F", msgFile, tagName, commitSha];
189+
const made = git(tagArgs);
190+
try {
191+
unlinkSync(msgFile);
192+
} catch {
193+
// best-effort temp cleanup
194+
}
195+
if (!made.ok) {
196+
console.warn(`::warning::Could not create the signed replacement for ${tagName}: ${made.output}`);
197+
failedTags.push({ tagName, reason: made.output });
198+
return null;
162199
}
163200

164-
gitCommand(tagCommand);
165-
166-
// Push the new tag
167-
gitCommand(`git push origin ${tagName}`);
201+
// Replace the remote ref ATOMICALLY with a force-update. Never delete it
202+
// first: deleting the tag behind a published release makes GitHub turn the
203+
// release back into a draft, and if the follow-up push is then rejected
204+
// (ref-lock race "reference already exists", or GitHub's App push check
205+
// "refusing to allow a GitHub App to create or update workflow … without
206+
// workflows permission" for a tag off the branch tip) the tag stays gone and
207+
// the release stays a draft — CLDMV/.github#362. With a force-update a
208+
// rejection leaves the original tag exactly where it was.
209+
const pushed = git(["push", "origin", `+refs/tags/${tagName}:refs/tags/${tagName}`]);
210+
if (!pushed.ok) {
211+
console.warn(`::warning::Could not replace ${tagName} with a signed tag; the existing tag was left unchanged. git said: ${pushed.output}`);
212+
failedTags.push({ tagName, reason: pushed.output.split("\n").find((l) => /rejected|error|fatal/i.test(l)) || pushed.output });
213+
return null;
214+
}
168215

169216
console.log(`✅ Successfully converted tag ${tagName} to signed/annotated`);
170217

@@ -293,6 +340,41 @@ if (TAGS_DETAILED.length === 0) {
293340
}
294341
}
295342

343+
// End-state check: every tag this run touched must still exist on the remote,
344+
// and every release that was published before must still be published. This is
345+
// the loud failure the old delete-and-recreate path never had — it logged
346+
// "Fixed 0" and exited 0 while leaving a draft release with no tag behind.
347+
const brokenReleases = [];
348+
if (!DRY_RUN && touched.length > 0) {
349+
for (const t of touched) {
350+
const remote = git(["ls-remote", "--tags", "origin", `refs/tags/${t.tagName}`]);
351+
if (!remote.ok || !remote.output) {
352+
brokenReleases.push(`${t.tagName}: tag is missing on the remote`);
353+
continue;
354+
}
355+
if (t.wasPublished && t.release?.id) {
356+
let current = null;
357+
try {
358+
const { owner, repo } = parseRepo(REPOSITORY);
359+
current = await api("GET", `/releases/${t.release.id}`, null, { token: GITHUB_TOKEN, owner, repo });
360+
} catch (error) {
361+
debugLog(`end-state read of release ${t.release.id} failed: ${error.message}`);
362+
}
363+
if (current?.draft === true) {
364+
console.log(`🔁 Release for ${t.tagName} reads draft after the tag update — re-publishing...`);
365+
await reassertPublished(t.release.id);
366+
try {
367+
const { owner, repo } = parseRepo(REPOSITORY);
368+
current = await api("GET", `/releases/${t.release.id}`, null, { token: GITHUB_TOKEN, owner, repo });
369+
} catch {
370+
// fall through with the previous read
371+
}
372+
if (current?.draft === true) brokenReleases.push(`${t.tagName}: release ${t.release.html_url || t.release.id} was published and is now a draft`);
373+
}
374+
}
375+
}
376+
}
377+
296378
// Set outputs
297379
const updatedTagsJson = JSON.stringify(updatedTagsDetailed);
298380
const fixedTagsJson = JSON.stringify(fixedTagsArray);
@@ -324,8 +406,17 @@ for (const tagName of fixedTagsArray) {
324406
}
325407
}
326408

409+
for (const f of failedTags) {
410+
summaryData.lines.push(`- ⚠️ **${f.tagName}** left unchanged (signing push rejected: ${String(f.reason).replace(/[\r\n]+/g, " ").slice(0, 200)})`);
411+
}
412+
for (const b of brokenReleases) {
413+
summaryData.lines.push(`- ❌ **${b}**`);
414+
}
415+
327416
// Add appropriate notes
328-
if (fixedTagsArray.length > 0) {
417+
if (failedTags.length > 0 || brokenReleases.length > 0) {
418+
summaryData.notes.push(`${failedTags.length} tag(s) could not be signed; ${brokenReleases.length} release/tag problem(s) need attention`);
419+
} else if (fixedTagsArray.length > 0) {
329420
summaryData.notes.push(`Successfully fixed ${fixedTagsArray.length} unsigned tag(s)`);
330421
} else {
331422
summaryData.lines.push("- ✅ **No issues found**: All version tags are properly signed");
@@ -358,4 +449,10 @@ if (githubOutput) {
358449
console.log("🔍 DEBUG: No GITHUB_OUTPUT file available");
359450
}
360451

361-
console.log("🔍 DEBUG: Unsigned tags action completed successfully");
452+
if (brokenReleases.length > 0) {
453+
for (const b of brokenReleases) console.error(`::error::${b}`);
454+
console.error("::error::Tag health left a release unpublished or a tag missing — see CLDMV/.github#362 and repair with the sync-release-notes workflow.");
455+
process.exitCode = 1;
456+
} else {
457+
console.log("🔍 DEBUG: Unsigned tags action completed successfully");
458+
}

‎.github/actions/github/api/release/create/_impl.mjs‎

Lines changed: 14 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { debugLog } from "../../../../common/common/core.mjs";
2+
import { stripReleaseSubject, stripCommitTrailers, neutralizeMentions, contributorHandles } from "../../../utilities/release-notes.mjs";
23

34
/**
45
* Normalize arbitrary values to boolean.
@@ -32,128 +33,25 @@ function toBoolean(value, fallback = false) {
3233
}
3334

3435
/**
35-
* Remove duplicated title lines from the beginning of release body.
36-
* This handles cases where the commit message subject is also present
37-
* as the first line of the body.
36+
* Normalize a release body before it is written: drop a leading line that only
37+
* repeats the release title (the release name or the squash subject
38+
* `release: vX.Y.Z - …`), drop the squash trailer tail (`Co-authored-by:` …),
39+
* and neutralize accidental `@word` mentions in prose (wrapped in a code span)
40+
* so GitHub doesn't ping, or add to the release's Contributors avatars, an
41+
* account that only appears in text such as a fix-headers `@Author` tag. The
42+
* handles in the body's own Contributors block stay live mentions.
3843
* @param {string} body - Raw release body markdown.
3944
* @param {string} title - Release title/name.
45+
* @param {string} tagName - Release tag (used to derive the version).
4046
* @returns {string} Normalized release body.
4147
*/
42-
function normalizeReleaseBody(body, title) {
48+
function normalizeReleaseBody(body, title, tagName = "") {
4349
if (!body) {
4450
return "";
4551
}
46-
47-
const normalizedBody = String(body).replace(/\r\n/g, "\n");
48-
const normalizedTitle = (title || "").trim();
49-
50-
if (!normalizedTitle) {
51-
return normalizedBody;
52-
}
53-
54-
const lines = normalizedBody.split("\n");
55-
const firstNonEmptyIndex = lines.findIndex((line) => line.trim().length > 0);
56-
57-
if (firstNonEmptyIndex === -1) {
58-
return normalizedBody;
59-
}
60-
61-
const firstLine = lines[firstNonEmptyIndex].trim();
62-
if (firstLine.toLowerCase() === normalizedTitle.toLowerCase()) {
63-
lines.splice(firstNonEmptyIndex, 1);
64-
while (lines.length > 0 && lines[0].trim() === "") {
65-
lines.shift();
66-
}
67-
}
68-
69-
return lines.join("\n");
70-
}
71-
72-
/**
73-
* Escape JSDoc-style tags in release body so they are not interpreted as GitHub mentions.
74-
* @param {string} content - Release body markdown.
75-
* @returns {string} Sanitized release body.
76-
*/
77-
function neutralizeJsdocTagMentions(content) {
78-
if (!content) {
79-
return "";
80-
}
81-
82-
const jsdocTags = [
83-
"abstract",
84-
"access",
85-
"alias",
86-
"async",
87-
"augments",
88-
"author",
89-
"borrows",
90-
"callback",
91-
"class",
92-
"classdesc",
93-
"constant",
94-
"constructs",
95-
"default",
96-
"deprecated",
97-
"description",
98-
"enum",
99-
"event",
100-
"example",
101-
"exports",
102-
"extends",
103-
"external",
104-
"file",
105-
"fires",
106-
"function",
107-
"generator",
108-
"global",
109-
"hideconstructor",
110-
"ignore",
111-
"implements",
112-
"inheritdoc",
113-
"inner",
114-
"instance",
115-
"interface",
116-
"kind",
117-
"lends",
118-
"license",
119-
"listens",
120-
"member",
121-
"memberof",
122-
"mixes",
123-
"mixin",
124-
"module",
125-
"name",
126-
"namespace",
127-
"override",
128-
"package",
129-
"param",
130-
"private",
131-
"property",
132-
"protected",
133-
"public",
134-
"readonly",
135-
"returns",
136-
"return",
137-
"see",
138-
"since",
139-
"static",
140-
"summary",
141-
"template",
142-
"this",
143-
"throws",
144-
"todo",
145-
"tutorial",
146-
"type",
147-
"typedef",
148-
"variation",
149-
"version",
150-
"yields",
151-
"yield",
152-
"internal"
153-
];
154-
155-
const tagPattern = new RegExp(`@(${jsdocTags.join("|")})(?=$|[\\s.,;:!?()[\\]{}])`, "gi");
156-
return String(content).replace(tagPattern, "@​$1");
52+
const version = String(tagName || title || "").replace(/^.*@(?=\d)/, "");
53+
const cleaned = stripCommitTrailers(stripReleaseSubject(body, { name: title, version }));
54+
return neutralizeMentions(cleaned, contributorHandles(cleaned));
15755
}
15856

15957
/**
@@ -214,7 +112,7 @@ export async function run({ token, repo, tag_name, name, body, is_prerelease, is
214112
)
215113
? String(make_latest).trim().toLowerCase()
216114
: undefined;
217-
const finalBody = neutralizeJsdocTagMentions(normalizeReleaseBody(body, name));
115+
const finalBody = normalizeReleaseBody(body, name, tag_name);
218116
// Satellite tags (@scope/name@version) contain "/" and "@"; encode the tag in
219117
// URL path segments so the lookups below resolve. No-op for core v<version>.
220118
const encTag = encodeURIComponent(tag_name);

‎.github/actions/github/jobs/create-release/action.yml‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ runs:
132132
commits-file: ${{ steps.get-commits.outputs.commits-file }}
133133
use-single-commit-message: "true"
134134

135+
# Release body: the committed per-version changelog file at the release
136+
# commit when there is one (docs/changelog[s]/v<major>/v<version>.md), else
137+
# the commit-derived body. Either way the duplicated "release: vX.Y.Z - …"
138+
# subject line and squash trailers are dropped and the Contributors /
139+
# coverage blocks are kept. An explicit release-notes input wins.
140+
- name: Resolve release notes
141+
if: inputs.release-notes == ''
142+
id: resolve-notes
143+
shell: bash
144+
run: node "${{ github.action_path }}/resolve-notes.mjs"
145+
env:
146+
VERSION: ${{ steps.prepare.outputs.version }}
147+
COMMIT_SHA: ${{ steps.prepare.outputs.commit-sha }}
148+
TAG_NAME: ${{ inputs.tag-name || format('v{0}', steps.prepare.outputs.version) }}
149+
GENERATED_BODY: ${{ steps.release-notes.outputs.changelog-content }}
150+
135151
- name: Calculate artifact and release names
136152
id: names
137153
uses: CLDMV/.github/.github/actions/common/steps/calculate-names@v4
@@ -149,7 +165,7 @@ runs:
149165
with:
150166
tag: ${{ inputs.tag-name || format('v{0}', steps.prepare.outputs.version) }}
151167
sha: ${{ steps.prepare.outputs.commit-sha }}
152-
message: ${{ inputs.release-notes || steps.release-notes.outputs.changelog-content }}
168+
message: ${{ inputs.release-notes || steps.resolve-notes.outputs.body || steps.release-notes.outputs.changelog-content }}
153169
gpg_enabled: ${{ inputs.gpg_enabled }}
154170
tagger_name: ${{ inputs.tagger_name }}
155171
tagger_email: ${{ inputs.tagger_email }}
@@ -201,7 +217,7 @@ runs:
201217
with:
202218
tag_name: ${{ inputs.tag-name || format('v{0}', steps.prepare.outputs.version) }}
203219
name: ${{ steps.names.outputs.release-name }}
204-
body: ${{ inputs.release-notes || steps.release-notes.outputs.changelog-content }}
220+
body: ${{ inputs.release-notes || steps.resolve-notes.outputs.body || steps.release-notes.outputs.changelog-content }}
205221
is_prerelease: ${{ inputs.is-prerelease }}
206222
is_draft: ${{ inputs.is-draft }}
207223
make_latest: ${{ inputs.make-latest }}
@@ -291,6 +307,19 @@ runs:
291307
with:
292308
tag: ${{ inputs.tag-name || format('v{0}', steps.prepare.outputs.version) }}
293309

310+
# Fail loudly when the release did not end up published with its tag in
311+
# place. Before this gate a draft or tagless release still reported success.
312+
- name: Verify release is published and tagged
313+
if: inputs.dry-run != 'true'
314+
shell: bash
315+
run: node "${{ github.action_path }}/verify-published.mjs"
316+
env:
317+
GITHUB_TOKEN: ${{ inputs.github-token }}
318+
REPOSITORY: ${{ github.repository }}
319+
RELEASE_ID: ${{ steps.create-release.outputs.release_id }}
320+
TAG_NAME: ${{ inputs.tag-name || format('v{0}', steps.prepare.outputs.version) }}
321+
WANT_DRAFT: ${{ inputs.is-draft }}
322+
294323
- name: Dry run validation
295324
if: inputs.dry-run == 'true'
296325
id: dry-run

0 commit comments

Comments
 (0)