feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)

This commit is contained in:
Yun Chan 2026-10-31 02:54:54 +09:00
parent f49acf0105
commit 10af20a0ad
157 changed files with 29455 additions and 913 deletions

View file

@ -21,6 +21,7 @@
// 선택: FORGEJO_RELEASE_TAG (기본: CI_COMMIT_TAG/GITHUB_REF_NAME/FORGEJO_REF_NAME)
// 선택: FORGEJO_PUBLISH_DRY_RUN=1 (업로드 없이 사전점검)
import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { createReadStream, readFileSync } from "node:fs";
import { readFile, readdir, stat, writeFile } from "node:fs/promises";
@ -423,14 +424,48 @@ function extractChangelogSection(changelog, targetVersion) {
return lines.slice(start, end).join("\n").trim();
}
function resolveTargetCommitish(releaseTag) {
const fromEnv =
process.env.FORGEJO_TARGET_COMMITISH?.trim() ||
process.env.CI_COMMIT_SHA?.trim() ||
process.env.GITHUB_SHA?.trim();
if (fromEnv && /^[0-9a-f]{40}$/i.test(fromEnv)) return fromEnv;
const repoRoot = fileURLToPath(new URL("../..", import.meta.url));
const resolved = spawnSync("git", ["rev-parse", `${releaseTag}^{commit}`], {
cwd: repoRoot,
encoding: "utf8",
});
const sha = (resolved.stdout ?? "").trim();
if (resolved.status === 0 && /^[0-9a-f]{40}$/i.test(sha)) return sha;
const head = spawnSync("git", ["rev-parse", "HEAD"], {
cwd: repoRoot,
encoding: "utf8",
});
const headSha = (head.stdout ?? "").trim();
if (head.status === 0 && /^[0-9a-f]{40}$/i.test(headSha)) return headSha;
throw new Error(
`Cannot resolve commit SHA for ${releaseTag}; push the annotated tag first or set FORGEJO_TARGET_COMMITISH.`,
);
}
async function upsertRelease(description) {
const targetCommitish = resolveTargetCommitish(tag);
const byTag = await forgejoFetch(`${releasesApiUrl}/tags/${encodeURIComponent(tag)}`);
if (byTag.ok) {
const existing = await byTag.json();
const update = await forgejoFetch(`${releasesApiUrl}/${existing.id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: `D3RO Voice ${tag}`, body: description, prerelease: false, draft: false }),
body: JSON.stringify({
target_commitish: targetCommitish,
name: `D3RO Voice ${tag}`,
body: description,
prerelease: false,
draft: false,
}),
});
if (!update.ok) throw new Error(`release update failed: HTTP ${update.status} ${await update.text()}`);
return existing.id;
@ -439,12 +474,22 @@ async function upsertRelease(description) {
throw new Error(`release lookup failed: HTTP ${byTag.status} ${await byTag.text()}`);
}
// Forgejo POST /releases 는 원격에 태그가 아직 없으면 target_commitish 에 lightweight 태그를 새로 만든다.
// 로컬 annotated 태그 푸시가 나중에 'already exists' 로 거절되지 않도록 원격 태그 존재를 먼저 확인한다(GAP-REL-14).
const tagRefUrl = `${origin}/api/v1/repos/${owner}/${repo}/git/refs/tags/${encodeURIComponent(tag)}`;
const tagRefRes = await forgejoFetch(tagRefUrl);
if (tagRefRes.status === 404) {
throw new Error(
`Remote tag ${tag} does not exist on Forgejo yet. Push main and ${tag} before creating the Forgejo release.`,
);
}
const create = await forgejoFetch(releasesApiUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tag_name: tag,
target_commitish: "main",
target_commitish: targetCommitish,
name: `D3RO Voice ${tag}`,
body: description,
draft: false,