From 7dfa90133207bb7f85c9bbbb7813301e95a61911 Mon Sep 17 00:00:00 2001 From: "Simon Genin (ges)" Date: Mon, 29 Mar 2021 12:09:26 +0200 Subject: [PATCH] [IMP] tooling: improve release script Release script errase dist folder closes #793 Release can only be done on master branch closes #829 Update the playground owl version on release closes #814 Add logError method in release to show messages in red. Check-formatting command added to the release process. --- package.json | 2 ++ tools/release.js | 73 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index d3b1316d..ddcc53ea 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "pretools:watch": "npm run build", "tools:watch": "npm-run-all --parallel tools:serve \"build:* -- --watch\"", "prettier": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md} --write", + "check-formatting": "prettier {src/*.ts,src/**/*.ts,tests/*.ts,tests/**/*.ts,doc/*.md,doc/**/*.md} --check", "publish": "npm run build && npm publish", "release": "node tools/release.js" }, @@ -40,6 +41,7 @@ "@types/node": "^14.11.8", "chalk": "^3.0.0", "cpx": "^1.5.0", + "current-git-branch": "^1.1.0", "git-rev-sync": "^1.12.0", "github-api": "^3.3.0", "jest": "^23.6.0", diff --git a/tools/release.js b/tools/release.js index 7681fd61..ddf685f1 100644 --- a/tools/release.js +++ b/tools/release.js @@ -3,9 +3,11 @@ const readline = require("readline"); const fs = require("fs"); const exec = require("child_process").exec; const chalk = require("chalk"); +const branchName = require('current-git-branch'); const REL_NOTES_FILE = `release-notes.md`; const STEPS = 8; +const branch = "master"; const rl = readline.createInterface({ input: process.stdin, @@ -21,6 +23,19 @@ startRelease().then(() => { // ----------------------------------------------------------------------------- async function startRelease() { + // First check we are on master + if (branchName() !== branch) { + logError(`You shall not pass! You are not on the ${branch} branch!`) + return; + } + + log("Check if code formatting is right...") + const checkFormatting = await execCommand("npm run check-formatting"); + if (checkFormatting !== 0) { + logError("Prettier format validation failed. Aborting."); + return; + } + log(`*** Owl release script ***`); log(`Current Version: ${package.version}`); @@ -36,7 +51,7 @@ async function startRelease() { content = await readFile("./" + file); } catch (e) { logSubContent(e.message); - log("Cannot find release notes... Aborting"); + logError("Cannot find release notes... Aborting"); return; } let shouldBeDraft = await ask(`Should be a draft [y/n] ? (n)`); @@ -45,12 +60,14 @@ async function startRelease() { { draft = "--draft"; } + let shouldUploadPlayground = await ask(`Should this release be uploaded on the playground [y/n] ? (y)`); + shouldUploadPlayground = shouldUploadPlayground.toLowerCase() !== 'n'; // --------------------------------------------------------------------------- log(`Step 2/${STEPS}: running tests...`); const testsResult = await execCommand("npm run test"); if (testsResult !== 0) { - log("Test suite does not pass. Aborting."); + logError("Test suite does not pass. Aborting."); return; } @@ -64,24 +81,24 @@ async function startRelease() { log(`Step 4/${STEPS}: creating git commit...`); const gitResult = await execCommand(`git commit -am "[REL] v${next}\n\n${content}"`); if (gitResult !== 0) { - log("Git commit failed. Aborting."); + logError("Git commit failed. Aborting."); return; } // ---------------------------------------------------------------------------- log(`Step 5/${STEPS}: building owl...`); - await execCommand("npm run prettier"); + await execCommand("rm -rf dist/"); const buildResult = await execCommand("npm run build"); if (buildResult !== 0) { - log("Build failed. Aborting."); + logError("Build failed. Aborting."); return; } // --------------------------------------------------------------------------- log(`Step 6/${STEPS}: pushing on github...`); - const pushResult = await execCommand("git push"); + const pushResult = await execCommand("git push origin " + branch); if (pushResult !== 0) { - log("git push failed. Aborting."); + logError("git push failed. Aborting."); return; } @@ -90,17 +107,51 @@ async function startRelease() { log(`Step 7/${STEPS}: Creating the release...`); const relaseResult = await execCommand(`gh release create v${next} dist/*.js ${draft} -F release-notes.md`); if (relaseResult !== 0) { - log("github release failed. Aborting."); + logError("github release failed. Aborting."); return; } log(`Step 8/${STEPS}: publishing module on npm...`); await execCommand("npm run publish"); - + log("Owl Release process completed! Thank you for your patience"); await execCommand(`gh release view`); await execCommand(`gh release view -w`); + if (shouldUploadPlayground) { + log(`Bonus step: publishing new release on playground...`); + let owl_code = null; + status = 0 + + try { + owl_code = await readFile("dist/owl.iife.js"); + } catch (e) { + logSubContent(e.message); + logError("Cannot read owl.iife.js... Aborting"); + return; + } + + status += await execCommand("git checkout gh-pages"); + + if (status !== 0) { + logError("Couldn't switch to gh-pages branch") + return; + } + + try { + fs.writeFileSync('owl.js', owl_code) + } catch (err) { + logError(err) + return; + } + + status += await execCommand(`git commit -am "[IMP] update owl to v${next}"`); + status += await execCommand(`git push origin gh-pages`); + status += await execCommand("git checkout -"); + if (status !== 0) { + logError("Something went wrong for the playground update.") + } + } } // ----------------------------------------------------------------------------- @@ -111,6 +162,10 @@ function log(text) { console.log(chalk.yellow(formatLog(text))); } +function logError(text) { + console.log(chalk.red(formatLog(text))); +} + function formatLog(text) { return `[REL] ${text}`; }