Files
3f9daed6a0 ⬆️ Bump simple-git from 3.36.0 to 4.0.1 (#5380)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
Co-authored-by: Halvor Haugan <halvor.haugan@nav.no>
2026-10-12 10:13:58 +02:00

64 lines
1.6 KiB
TypeScript

import { spawnSync } from "node:child_process";
import fs from "node:fs";
import { simpleGit } from "simple-git";
const git = simpleGit();
main();
async function main() {
const changelogFile = fs.readFileSync("../../CHANGELOG.md", "utf-8");
const newestEntry = changelogFile.split("\n## ")[1]; // The first item is the main heading.
const releaseLines = newestEntry.trim().split("\n");
const version = releaseLines[0];
// Remove the version line and the empty line before the actual release notes.
releaseLines.splice(0, 2);
const releaseNotes = releaseLines.join("\n").trim();
console.info(`Creating release for version: ${version}`);
const tagName = `v${version}`;
/* Release will fail if tag is duplicated */
const tagExists = await gitTagExists(tagName);
if (tagExists) {
console.info(`Tag ${tagName} already exists. Skipping release creation.`);
return;
}
try {
const result = spawnSync(
"gh",
[
"release",
"create",
tagName,
"--title",
`v${version}`,
"--notes",
releaseNotes,
],
{ stdio: "inherit" },
);
if (result.error) {
throw result.error;
}
} catch (error) {
console.error("Error creating GitHub release:", error);
}
}
async function gitTagExists(tag: string): Promise<boolean> {
try {
const output = await git.listRemote(["--tags", "origin", tag]);
return output.includes(tag);
} catch (error) {
console.error("Error checking for tag:", error);
return false; // Assume tag doesn't exist on error
}
}