Skip to content

Commit 83ccc11

Browse files
authored
ci: update release (#783)
1 parent 18d2cd4 commit 83ccc11

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

scripts/release.mjs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import { chalk, $, question } from 'zx';
3+
import { chalk, $, question, echo } from 'zx';
44

55
const errorLog = (str) => console.log(chalk.redBright(str));
66
const infoLog = (str) => console.log(chalk.whiteBright(str));
@@ -27,59 +27,63 @@ const pkg = require(pkgPath);
2727
);
2828
succeeDoneLog();
2929

30-
infoLog('1. Check the staged.');
30+
infoLog('2. Check the staged.');
3131
const isGitClean = (await $`git status --porcelain`).stdout.trim().length;
3232
assert(!isGitClean, 'You should empty the staged before release.');
3333
succeeDoneLog();
3434

35-
infoLog('2. Check the branch.');
35+
infoLog('3. Check the branch.');
3636
const currentBranch = (
3737
await $`git rev-parse --abbrev-ref HEAD`
3838
).stdout.trim();
3939
assert(currentBranch === 'main', `can't release on ${currentBranch}`);
4040
succeeDoneLog();
4141

42-
infoLog('3. Check the remote up to date.');
42+
infoLog('4. Check the remote up to date.');
4343
const gitStatus = (await $`git status --short --branch`).stdout.trim();
4444
assert(!gitStatus.includes('behind'), `git status is behind remote`);
4545
succeeDoneLog();
4646

4747
// check npm registry
48-
infoLog('4. Check the npm registry.');
48+
infoLog('5. Check the npm registry.');
4949
const isNPMRegistry =
5050
pkg.publishConfig.registry === 'https://registry.npmjs.org/';
5151
assert(isNPMRegistry, 'npm registry is not https://registry.npmjs.org/');
5252
succeeDoneLog();
5353

54-
infoLog('5. Bump version.');
54+
infoLog('6. Bump version.');
5555
const lastVersion = require('../package.json').version;
5656
const nextVersion = await question(
5757
`Input the next version(current version is ${lastVersion}): `
5858
);
5959

60-
infoLog(`6. Generate Changelog`);
60+
infoLog(`7. Generate Changelog`);
6161
$.verbose = true;
6262
await $`npx standard-version --release-as ${nextVersion}`;
6363
$.verbose = false;
6464
succeeDoneLog();
6565

66-
infoLog('7. Execute build...');
66+
infoLog('8. Execute build...');
6767
await $`npm run build`;
6868
succeeDoneLog();
6969

70-
infoLog(`8. Publish`);
71-
await $`npm pack --dry-run`;
70+
infoLog(`9. Publish`);
71+
echo(await $`npm pack --dry-run`);
7272
const publishCheck = await question(
7373
'Are these files you want to publish? (Y/n)'
7474
);
7575
if (publishCheck.toLocaleLowerCase() === 'n') {
76+
await $`git tag -d v${nextVersion}`;
77+
await $`git reset`;
78+
await $`git reset HEAD^`;
79+
await $`git checkout -- .`;
7680
process.exit(1);
7781
}
7882
// use npm pack --dry-run to check publish pack
7983
await $`npm publish`;
8084
succeeDoneLog();
8185

82-
infoLog(`9. git push`);
86+
infoLog(`10. git push`);
8387
$.verbose = true;
8488
await $`git push --follow-tags origin main`;
8589
$.verbose = false;

0 commit comments

Comments
 (0)