From 6ca6717965d2e2100fd53703c380717fdf909439 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Thu, 12 Jan 2023 17:15:11 +0100 Subject: [PATCH] [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. --- tools/release.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/release.js b/tools/release.js index 02d41a2e..164a0dfd 100644 --- a/tools/release.js +++ b/tools/release.js @@ -47,6 +47,18 @@ async function startRelease() { let file = await ask(`Release notes (${REL_NOTES_FILE}): `); file = file || REL_NOTES_FILE; 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 { content = await readFile("./" + file); } catch (e) { @@ -104,7 +116,7 @@ async function startRelease() { // --------------------------------------------------------------------------- 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) { logError("github release failed. Aborting."); 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); + } + }); + }); +}