From 575c2b0098f0ca3b0061f39a7b82e5c10c36d0ba Mon Sep 17 00:00:00 2001 From: mortalYoung Date: Fri, 15 Jul 2022 17:52:24 +0800 Subject: [PATCH] ci: update release --- scripts/release.mjs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/release.mjs b/scripts/release.mjs index 064077988..5a4872706 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -1,6 +1,6 @@ import fs from 'fs'; import path from 'path'; -import { chalk, $, question } from 'zx'; +import { chalk, $, question, echo } from 'zx'; const errorLog = (str) => console.log(chalk.redBright(str)); const infoLog = (str) => console.log(chalk.whiteBright(str)); @@ -27,59 +27,63 @@ const pkg = require(pkgPath); ); succeeDoneLog(); - infoLog('1. Check the staged.'); + infoLog('2. Check the staged.'); const isGitClean = (await $`git status --porcelain`).stdout.trim().length; assert(!isGitClean, 'You should empty the staged before release.'); succeeDoneLog(); - infoLog('2. Check the branch.'); + infoLog('3. Check the branch.'); const currentBranch = ( await $`git rev-parse --abbrev-ref HEAD` ).stdout.trim(); assert(currentBranch === 'main', `can't release on ${currentBranch}`); succeeDoneLog(); - infoLog('3. Check the remote up to date.'); + infoLog('4. Check the remote up to date.'); const gitStatus = (await $`git status --short --branch`).stdout.trim(); assert(!gitStatus.includes('behind'), `git status is behind remote`); succeeDoneLog(); // check npm registry - infoLog('4. Check the npm registry.'); + infoLog('5. Check the npm registry.'); const isNPMRegistry = pkg.publishConfig.registry === 'https://registry.npmjs.org/'; assert(isNPMRegistry, 'npm registry is not https://registry.npmjs.org/'); succeeDoneLog(); - infoLog('5. Bump version.'); + infoLog('6. Bump version.'); const lastVersion = require('../package.json').version; const nextVersion = await question( `Input the next version(current version is ${lastVersion}): ` ); - infoLog(`6. Generate Changelog`); + infoLog(`7. Generate Changelog`); $.verbose = true; await $`npx standard-version --release-as ${nextVersion}`; $.verbose = false; succeeDoneLog(); - infoLog('7. Execute build...'); + infoLog('8. Execute build...'); await $`npm run build`; succeeDoneLog(); - infoLog(`8. Publish`); - await $`npm pack --dry-run`; + infoLog(`9. Publish`); + echo(await $`npm pack --dry-run`); const publishCheck = await question( 'Are these files you want to publish? (Y/n)' ); if (publishCheck.toLocaleLowerCase() === 'n') { + await $`git tag -d v${nextVersion}`; + await $`git reset`; + await $`git reset HEAD^`; + await $`git checkout -- .`; process.exit(1); } // use npm pack --dry-run to check publish pack await $`npm publish`; succeeDoneLog(); - infoLog(`9. git push`); + infoLog(`10. git push`); $.verbose = true; await $`git push --follow-tags origin main`; $.verbose = false;