Skip to content

Commit af95037

Browse files
committed
ci: set up release script
1 parent 8a7ee6c commit af95037

File tree

5 files changed

+185
-56
lines changed

5 files changed

+185
-56
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"dev": "lerna exec --scope docs -- yarn dev",
1212
"build": "lerna exec --scope docs -- yarn build",
1313
"lint": "eslint --fix packages/**/*.js packages/**/*.vue packages/**/bin/*",
14-
"prepublishOnly": "conventional-changelog -p angular -r 2 -i CHANGELOG.md -s",
15-
"release": "/bin/bash scripts/release.sh",
14+
"release": "yarn --pure-lockfile && node scripts/release.js",
15+
"changelog": "node scripts/genChangelog.js run",
1616
"test": "node scripts/test.js"
1717
},
1818
"repository": {
@@ -47,7 +47,9 @@
4747
"lerna": "^2.11.0",
4848
"lint-staged": "^7.0.4",
4949
"minimist": "^1.2.0",
50-
"yorkie": "^1.0.3"
50+
"yorkie": "^1.0.3",
51+
"inquirer": "^6.2.0",
52+
"@vue/conventional-changelog": "^0.1.1"
5153
},
5254
"engines": {
5355
"node": ">=8"

scripts/genChangelog.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const execa = require('execa')
2+
const cc = require('conventional-changelog')
3+
const config = require('@vue/conventional-changelog')
4+
5+
const gen = module.exports = version => {
6+
const fileStream = require('fs').createWriteStream(`CHANGELOG.md`)
7+
8+
cc({
9+
config,
10+
releaseCount: 0,
11+
pkg: {
12+
transform (pkg) {
13+
pkg.version = `v${version}`
14+
return pkg
15+
}
16+
}
17+
}).pipe(fileStream).on('close', async () => {
18+
delete process.env.PREFIX
19+
await execa('git', ['add', '-A'], { stdio: 'inherit' })
20+
await execa('git', ['commit', '-m', `chore: ${version} changelog`], { stdio: 'inherit' })
21+
})
22+
}
23+
24+
if (process.argv[2] === 'run') {
25+
const version = require('../lerna.json').version
26+
gen(version)
27+
}

scripts/release.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
3+
How to do a release:
4+
5+
1. Make sure you have publish access for all packages:
6+
- You must be in the VuePress team in the npm @vuepress organization
7+
- Make sure you DO NOT have npm per-publish 2-factor / OTP enabled, as it
8+
does not work with Lerna (which we use for batch publishing).
9+
10+
2. Run `yarn release`, follow prompts
11+
12+
3A. If everything works properly, the tag should have been auto-pushed and a
13+
local changelog commit should have been generated. Go to 4.
14+
15+
3B. If the publish fails half-way, things have gotten hairy. Now you need to
16+
go to npm to check which packages have been published and manually publish
17+
the ones that have not been published yet. After all have been published:
18+
19+
3B.1. Push the release git tag to GitHub.
20+
3B.2. Run `yarn changelog` to generate changelog commit.
21+
22+
4. Push the changelog commit to `next` branch.
23+
24+
5. Go to GitHub and verify that the changelog is live.
25+
26+
6. Go to GitHub releases page and publish the release.
27+
28+
*/
29+
30+
process.env.VUE_CLI_RELEASE = true
31+
32+
const execa = require('execa')
33+
const semver = require('semver')
34+
const inquirer = require('inquirer')
35+
36+
const curVersion = require('../lerna.json').version
37+
38+
const release = async () => {
39+
console.log(`Current version: ${curVersion}`)
40+
41+
const bumps = ['patch', 'minor', 'major', 'prerelease', 'premajor']
42+
const versions = {}
43+
bumps.forEach(b => {
44+
versions[b] = semver.inc(curVersion, b)
45+
})
46+
const bumpChoices = bumps.map(b => ({ name: `${b} (${versions[b]})`, value: b }))
47+
48+
const { bump, customVersion } = await inquirer.prompt([
49+
{
50+
name: 'bump',
51+
message: 'Select release type:',
52+
type: 'list',
53+
choices: [
54+
...bumpChoices,
55+
{ name: 'custom', value: 'custom' }
56+
]
57+
},
58+
{
59+
name: 'customVersion',
60+
message: 'Input version:',
61+
type: 'input',
62+
when: answers => answers.bump === 'custom'
63+
}
64+
])
65+
66+
const version = customVersion || versions[bump]
67+
68+
const { yes } = await inquirer.prompt([{
69+
name: 'yes',
70+
message: `Confirm releasing ${version}?`,
71+
type: 'list',
72+
choices: ['N', 'Y']
73+
}])
74+
75+
if (yes === 'N') {
76+
console.log('[release] cancelled.')
77+
return
78+
}
79+
80+
const releaseArguments = [
81+
'publish',
82+
'--repo-version',
83+
version,
84+
'--force-publish',
85+
'*'
86+
]
87+
88+
console.log(`lerna ${releaseArguments.join(' ')}`)
89+
90+
await execa(require.resolve('lerna/bin/lerna'), [
91+
'publish',
92+
'--repo-version',
93+
version,
94+
'--force-publish',
95+
'*'
96+
], { stdio: 'inherit' })
97+
98+
require('./genChangelog')(version)
99+
}
100+
101+
release().catch(err => {
102+
console.error(err)
103+
process.exit(1)
104+
})

scripts/release.sh

Lines changed: 0 additions & 52 deletions
This file was deleted.

yarn.lock

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,14 @@
13051305
source-map "^0.5.6"
13061306
vue-template-es2015-compiler "^1.6.0"
13071307

1308+
"@vue/conventional-changelog@^0.1.1":
1309+
version "0.1.1"
1310+
resolved "https://registry.yarnpkg.com/@vue/conventional-changelog/-/conventional-changelog-0.1.1.tgz#48d2227ca65c354cba4be60754ea531afd0c3718"
1311+
dependencies:
1312+
compare-func "^1.3.2"
1313+
execa "^0.10.0"
1314+
q "^1.5.1"
1315+
13081316
"@vue/test-utils@^1.0.0-beta.16":
13091317
version "1.0.0-beta.21"
13101318
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.0.0-beta.21.tgz#fe1ee11ce16072da7ef29420df4aa5c11f4560ff"
@@ -2397,6 +2405,10 @@ chardet@^0.4.0:
23972405
version "0.4.2"
23982406
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
23992407

2408+
chardet@^0.7.0:
2409+
version "0.7.0"
2410+
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
2411+
24002412
chokidar@^2.0.2, chokidar@^2.0.3:
24012413
version "2.0.4"
24022414
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.0.4.tgz#356ff4e2b0e8e43e322d18a372460bbcf3accd26"
@@ -2645,7 +2657,7 @@ commondir@^1.0.1:
26452657
version "1.0.1"
26462658
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
26472659

2648-
compare-func@^1.3.1:
2660+
compare-func@^1.3.1, compare-func@^1.3.2:
26492661
version "1.3.2"
26502662
resolved "https://registry.yarnpkg.com/compare-func/-/compare-func-1.3.2.tgz#99dd0ba457e1f9bc722b12c08ec33eeab31fa648"
26512663
dependencies:
@@ -3872,6 +3884,14 @@ external-editor@^2.0.4:
38723884
iconv-lite "^0.4.17"
38733885
tmp "^0.0.33"
38743886

3887+
external-editor@^3.0.0:
3888+
version "3.0.3"
3889+
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.0.3.tgz#5866db29a97826dbe4bf3afd24070ead9ea43a27"
3890+
dependencies:
3891+
chardet "^0.7.0"
3892+
iconv-lite "^0.4.24"
3893+
tmp "^0.0.33"
3894+
38753895
extglob@^0.3.1:
38763896
version "0.3.2"
38773897
resolved "https://registry.yarnpkg.com/extglob/-/extglob-0.3.2.tgz#2e18ff3d2f49ab2765cec9023f011daa8d8349a1"
@@ -4574,6 +4594,12 @@ iconv-lite@^0.4.17, iconv-lite@^0.4.4:
45744594
dependencies:
45754595
safer-buffer ">= 2.1.2 < 3"
45764596

4597+
iconv-lite@^0.4.24:
4598+
version "0.4.24"
4599+
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
4600+
dependencies:
4601+
safer-buffer ">= 2.1.2 < 3"
4602+
45774603
icss-replace-symbols@^1.1.0:
45784604
version "1.1.0"
45794605
resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.1.0.tgz#06ea6f83679a7749e386cfe1fe812ae5db223ded"
@@ -4693,6 +4719,24 @@ inquirer@^3.0.6, inquirer@^3.2.2:
46934719
strip-ansi "^4.0.0"
46944720
through "^2.3.6"
46954721

4722+
inquirer@^6.2.0:
4723+
version "6.2.0"
4724+
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.2.0.tgz#51adcd776f661369dc1e894859c2560a224abdd8"
4725+
dependencies:
4726+
ansi-escapes "^3.0.0"
4727+
chalk "^2.0.0"
4728+
cli-cursor "^2.1.0"
4729+
cli-width "^2.0.0"
4730+
external-editor "^3.0.0"
4731+
figures "^2.0.0"
4732+
lodash "^4.17.10"
4733+
mute-stream "0.0.7"
4734+
run-async "^2.2.0"
4735+
rxjs "^6.1.0"
4736+
string-width "^2.1.0"
4737+
strip-ansi "^4.0.0"
4738+
through "^2.3.6"
4739+
46964740
invariant@^2.2.0, invariant@^2.2.2, invariant@^2.2.4:
46974741
version "2.2.4"
46984742
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
@@ -6110,6 +6154,10 @@ [email protected]:
61106154
version "0.3.0"
61116155
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
61126156

6157+
medium-zoom@^0.4.0:
6158+
version "0.4.0"
6159+
resolved "http://registry.npmjs.org/medium-zoom/-/medium-zoom-0.4.0.tgz#8e13c9b754903c0c903220611af0d3cd373a4222"
6160+
61136161
mem@^1.1.0:
61146162
version "1.1.0"
61156163
resolved "https://registry.yarnpkg.com/mem/-/mem-1.1.0.tgz#5edd52b485ca1d900fe64895505399a0dfa45f76"

0 commit comments

Comments
 (0)