[IMP] tools: release scripts creates a template for release notes

This template contains the release version as a markdown title followed
by a markdown list with all the commit titles since the previous
release.
This commit is contained in:
Samuel Degueldre
2023-01-12 17:15:11 +01:00
committed by Géry Debongnie
parent ad4adb930e
commit 6ca6717965
+29 -1
View File
@@ -47,6 +47,18 @@ async function startRelease() {
let file = await ask(`Release notes (${REL_NOTES_FILE}): `); let file = await ask(`Release notes (${REL_NOTES_FILE}): `);
file = file || REL_NOTES_FILE; file = file || REL_NOTES_FILE;
let content; let content;
if (!fs.existsSync(`./${file}`)) {
let lastRelease = await getOutput("git log --grep='\\[REL\\]' -n 1 --pretty=%H");
const commitsSinceLastRelease = await getOutput(`git log ${lastRelease.trim()}..HEAD --pretty=%s`);
const commitsAsMdList = commitsSinceLastRelease.trim().split("\n").map(l => " - " + l).join("\n");
log(`${file} did not exist, created a template containing all commits since last release.`)
fs.writeFileSync(file, `# v${next}\n\n${commitsAsMdList}`);
const shouldContinue = await ask(`Check that the contents of ${file} is correct, then press y to continue: `);
if (shouldContinue.toLowerCase() !== "y") {
log("aborted");
return;
}
}
try { try {
content = await readFile("./" + file); content = await readFile("./" + file);
} catch (e) { } catch (e) {
@@ -104,7 +116,7 @@ async function startRelease() {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
log(`Step 7/${STEPS}: Creating the release...`); log(`Step 7/${STEPS}: Creating the release...`);
const relaseResult = await execCommand(`gh release create v${next} dist/*.js ${draft} -F ${REL_NOTES_FILE}`); const relaseResult = await execCommand(`gh release create v${next} dist/*.js ${draft} -F ${file}`);
if (relaseResult !== 0) { if (relaseResult !== 0) {
logError("github release failed. Aborting."); logError("github release failed. Aborting.");
return; return;
@@ -231,3 +243,19 @@ async function replaceInFile(file, from, to) {
}); });
}); });
} }
async function getOutput(command) {
return new Promise((resolve, reject) => {
const childProcess = exec(command, (err, stdout, stderr) => {
if (err) {
reject(err);
}
resolve(stdout);
});
childProcess.on("exit", code => {
if (code !== 0) {
reject(code);
}
});
});
}