From 11a3380d83be8cfd7801aa5a846f39ff7614a798 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Wed, 6 Jul 2022 15:20:52 +0530 Subject: [PATCH] build: automate release step fully (#5414) * build: automate release step fully * exit process when error * Add npm scripts for release and prerelease * update docs with release setps --- package.json | 4 ++- scripts/prerelease.js | 37 +++++++++++++++++++++++ scripts/release.js | 49 +++++++++++++------------------ src/packages/excalidraw/README.md | 20 +++++++++++++ 4 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 scripts/prerelease.js diff --git a/package.json b/package.json index e9aed5025..e622c9386 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,8 @@ "test:typecheck": "tsc", "test:update": "yarn test:app --updateSnapshot --watchAll=false", "test": "yarn test:app", - "autorelease": "node scripts/autorelease.js" + "autorelease": "node scripts/autorelease.js", + "prerelease": "node scripts/prerelease.js", + "release": "node scripts/release.js" } } diff --git a/scripts/prerelease.js b/scripts/prerelease.js new file mode 100644 index 000000000..25e9ddf83 --- /dev/null +++ b/scripts/prerelease.js @@ -0,0 +1,37 @@ +const fs = require("fs"); +const util = require("util"); +const exec = util.promisify(require("child_process").exec); +const updateChangelog = require("./updateChangelog"); + +const excalidrawDir = `${__dirname}/../src/packages/excalidraw`; +const excalidrawPackage = `${excalidrawDir}/package.json`; + +const updatePackageVersion = (nextVersion) => { + const pkg = require(excalidrawPackage); + pkg.version = nextVersion; + const content = `${JSON.stringify(pkg, null, 2)}\n`; + fs.writeFileSync(excalidrawPackage, content, "utf-8"); +}; + +const prerelease = async (nextVersion) => { + try { + await updateChangelog(nextVersion); + updatePackageVersion(nextVersion); + await exec(`git add -u`); + await exec( + `git commit -m "docs: release @excalidraw/excalidraw@${nextVersion} 🎉"`, + ); + + console.info("Done!"); + } catch (error) { + console.error(error); + process.exit(1); + } +}; + +const nextVersion = process.argv.slice(2)[0]; +if (!nextVersion) { + console.error("Pass the next version to release!"); + process.exit(1); +} +prerelease(nextVersion); diff --git a/scripts/release.js b/scripts/release.js index 479593f94..986eadc2a 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -1,10 +1,10 @@ const fs = require("fs"); -const util = require("util"); -const exec = util.promisify(require("child_process").exec); -const updateChangelog = require("./updateChangelog"); +const { execSync } = require("child_process"); const excalidrawDir = `${__dirname}/../src/packages/excalidraw`; const excalidrawPackage = `${excalidrawDir}/package.json`; +const pkg = require(excalidrawPackage); + const originalReadMe = fs.readFileSync(`${excalidrawDir}/README.md`, "utf8"); const updateReadme = () => { @@ -17,35 +17,28 @@ const updateReadme = () => { fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8"); }; -const updatePackageVersion = (nextVersion) => { - const pkg = require(excalidrawPackage); - pkg.version = nextVersion; - const content = `${JSON.stringify(pkg, null, 2)}\n`; - fs.writeFileSync(excalidrawPackage, content, "utf-8"); -}; - -const release = async (nextVersion) => { +const publish = () => { try { - updateReadme(); - await updateChangelog(nextVersion); - updatePackageVersion(nextVersion); - await exec(`git add -u`); - await exec( - `git commit -m "docs: release @excalidraw/excalidraw@${nextVersion} 🎉"`, - ); - // revert readme after release - fs.writeFileSync(`${excalidrawDir}/README.md`, originalReadMe, "utf8"); - - console.info("Done!"); + execSync(`yarn --frozen-lockfile`); + execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir }); + execSync(`yarn run build:umd`, { cwd: excalidrawDir }); + execSync(`yarn --cwd ${excalidrawDir} publish`); } catch (error) { console.error(error); process.exit(1); } }; -const nextVersion = process.argv.slice(2)[0]; -if (!nextVersion) { - console.error("Pass the next version to release!"); - process.exit(1); -} -release(nextVersion); +const release = () => { + updateReadme(); + console.info("Note for stable readme removed"); + + publish(); + console.info(`Published ${pkg.version}!`); + + // revert readme after release + fs.writeFileSync(`${excalidrawDir}/README.md`, originalReadMe, "utf8"); + console.info("Readme reverted"); +}; + +release(); diff --git a/src/packages/excalidraw/README.md b/src/packages/excalidraw/README.md index c11966e8c..6c5f98205 100644 --- a/src/packages/excalidraw/README.md +++ b/src/packages/excalidraw/README.md @@ -1341,3 +1341,23 @@ You can create a test release by posting the below comment in your pull request ``` Once the version is released `@excalibot` will post a comment with the release version. + +#### Creating a production release + +To release the next stable version follow the below steps + +``` +yarn prerelease version +``` + +You need to pass the `version` for which you want to create the release. This will make the changes needed before making the release like updating `package.json`, `changelog` and more. + +The next step is to run the `release` script + +``` +yarn release +``` + +This will publish the package. + +Right now there are two steps to create a production release but once this works fine these scripts will be combined and more automation will be done.