From 2331e578f7b29ba14c6128e360b69cf6b8050af5 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 27 Apr 2023 00:42:52 +0000 Subject: [PATCH] improve release script safety --- scripts/release.js | 24 ++++++++++++++++++++++-- scripts/utils/bumpVersion.js | 6 +++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/scripts/release.js b/scripts/release.js index d3f05260..8e2e9a83 100755 --- a/scripts/release.js +++ b/scripts/release.js @@ -126,6 +126,22 @@ async function uploadAssets({ release, bundlePath }) { } async function main() { + // check if no GITHUB_TOKEN env + if (!process.env.GITHUB_TOKEN) { + console.error("🆘 Missing GITHUB_TOKEN env") + return false + } + + // check if is any changes pending to commit + const gitStatus = child_process.execSync("git status --porcelain", { + cwd: process.cwd() + }).toString().trim() + + if (gitStatus.length > 0) { + console.error("🆘 There are pending changes to commit, please commit first.") + return false + } + let currentVersion = packagejson.version // check if currentVersion match with current latest release on github @@ -141,8 +157,12 @@ async function main() { if (process.argv.includes("--bump")) { const bumpType = process.argv[process.argv.indexOf("--bump") + 1] - const newVersion = await bumpVersion(bumpType, 1).catch((err) => { - console.error(`🆘 Failed to bump version: ${err}`) + const newVersion = await bumpVersion({ + root: process.cwd(), + type: bumpType, + count: 1 + }).catch((error) => { + console.error(`🆘 Failed to bump version >`, error) return false }) diff --git a/scripts/utils/bumpVersion.js b/scripts/utils/bumpVersion.js index f0dc4ea3..374e2ea8 100644 --- a/scripts/utils/bumpVersion.js +++ b/scripts/utils/bumpVersion.js @@ -23,7 +23,7 @@ async function bumpVersion({ let newVersion = rootPkgjson.version - newVersion = rootPkgjson.version.split(".") + newVersion = newVersion.split(".") switch (type) { case "patch": @@ -39,7 +39,7 @@ async function bumpVersion({ newVersion[2] = 0 break default: - console.error("Invalid version type") + console.error("Cannot bump version, invalid type") return false } @@ -101,7 +101,7 @@ async function bumpVersion({ continue } - return await fs.writeFileSync(path.resolve(packagesPath, package, "package.json"), JSON.stringify(pkgjson, null, 4)) + await fs.writeFileSync(path.resolve(packagesPath, package, "package.json"), JSON.stringify(pkgjson, null, 4)) } // write root package.json