Files
Kaname/scripts/release-notes.mjs
T
Pascal LinxweilerandClaude Opus 5.5 30b01d7bca Add Gitea release pipeline and server compose
- .gitea/workflows/release.yaml: on vX.Y.Z tags run checks, build and push the
  image to the Gitea registry (X.Y.Z, X.Y, latest), create a release from the
  CHANGELOG section
- scripts/release-notes.mjs: extract changelog section, create the release
- deploy/compose.yaml: server setup using the released image
- APP_VERSION build arg, shown in the header

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:12:32 +02:00

59 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
// Release helpers for CI (no dependencies).
//
// node scripts/release-notes.mjs notes <version> print the CHANGELOG section for <version>
// node scripts/release-notes.mjs publish create the Gitea release for $GITHUB_REF_NAME
//
// `publish` uses the Gitea Actions environment: GITHUB_SERVER_URL, GITHUB_REPOSITORY,
// GITHUB_REF_NAME (the tag), IMAGE (registry/owner/name) and TOKEN (API token).
import { readFileSync } from "node:fs";
export function changelogSection(markdown, version) {
const lines = markdown.split(/\r?\n/);
const start = lines.findIndex((l) => l.startsWith(`## [${version}]`));
if (start === -1) return null;
let end = lines.findIndex((l, i) => i > start && l.startsWith("## "));
if (end === -1) end = lines.length;
return lines
.slice(start + 1, end)
.join("\n")
.trim();
}
async function publish() {
const { GITHUB_SERVER_URL: server, GITHUB_REPOSITORY: repo, GITHUB_REF_NAME: tag, IMAGE, TOKEN } = process.env;
if (!server || !repo || !tag || !IMAGE || !TOKEN) throw new Error("missing CI environment variables");
const version = tag.replace(/^v/, "");
const notes = changelogSection(readFileSync("CHANGELOG.md", "utf8"), version);
if (!notes) throw new Error(`CHANGELOG.md has no section for ${version}`);
const body = `${notes}\n\n### Docker image\n\n\`\`\`\n${IMAGE}:${version}\n\`\`\`\n`;
const res = await fetch(`${server}/api/v1/repos/${repo}/releases`, {
method: "POST",
headers: { Authorization: `token ${TOKEN}`, "Content-Type": "application/json" },
body: JSON.stringify({ tag_name: tag, name: tag, body, draft: false, prerelease: false }),
});
if (res.status === 409) {
console.log(`Release ${tag} already exists, leaving it as is.`);
return;
}
if (!res.ok) throw new Error(`Creating release failed: ${res.status} ${await res.text()}`);
console.log(`Created release ${tag}.`);
}
const [cmd, arg] = process.argv.slice(2);
if (cmd === "notes") {
const section = changelogSection(readFileSync("CHANGELOG.md", "utf8"), arg);
if (!section) {
console.error(`No CHANGELOG section for ${arg}`);
process.exit(1);
}
console.log(section);
} else if (cmd === "publish") {
publish().catch((err) => {
console.error(err.message);
process.exit(1);
});
}