zx-bulk-release 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/main/js/build.js +4 -4
- package/src/main/js/index.js +3 -1
- package/src/main/js/publish.js +46 -25
- package/src/test/js/integration.test.js +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [1.13.0](https://github.com/semrel-extra/zx-bulk-release/compare/v1.12.0...v1.13.0) (2022-06-27)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
* feat: add log labels ([a0e80b6](https://github.com/semrel-extra/zx-bulk-release/commit/a0e80b64215c3f69206713cd6073c0240b0930c9))
|
|
5
|
+
* feat: add changelog generator ([4c0914f](https://github.com/semrel-extra/zx-bulk-release/commit/4c0914f24a91e2297f8c6ff8410949c2a0220fb5))
|
|
6
|
+
|
|
1
7
|
## [1.12.0](https://github.com/semrel-extra/zx-bulk-release/compare/v1.11.2...v1.12.0) (2022-06-26)
|
|
2
8
|
|
|
3
9
|
### Features
|
package/package.json
CHANGED
package/src/main/js/build.js
CHANGED
|
@@ -16,11 +16,11 @@ export const build = (pkg, packages) => ctx(async ($) => {
|
|
|
16
16
|
|
|
17
17
|
if (!pkg.fetched) {
|
|
18
18
|
$.cwd = pkg.absPath
|
|
19
|
-
console.log(`
|
|
19
|
+
console.log(`[${pkg.name}] build`)
|
|
20
20
|
await $.raw`${config.buildCmd}`
|
|
21
21
|
|
|
22
22
|
if (config.testCmd) {
|
|
23
|
-
console.log(`
|
|
23
|
+
console.log(`[${pkg.name}] test`)
|
|
24
24
|
await $.raw`${config.testCmd}`
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -45,9 +45,9 @@ const fetchPkg = (pkg) => ctx(async ($) => {
|
|
|
45
45
|
await copy({from: ['**/*', '!package.json'], to: cwd, cwd: `${temp}/package`})
|
|
46
46
|
|
|
47
47
|
pkg.fetched = true
|
|
48
|
-
console.log(`fetched '${pkg.name}@${pkg.version}'`)
|
|
48
|
+
console.log(`[${pkg.name}] fetched '${pkg.name}@${pkg.version}'`)
|
|
49
49
|
} catch (e) {
|
|
50
|
-
console.log(`fetching '${pkg.name}@${pkg.version}' failed`, e)
|
|
50
|
+
console.log(`[${pkg.name}] fetching '${pkg.name}@${pkg.version}' failed`, e)
|
|
51
51
|
}
|
|
52
52
|
})
|
|
53
53
|
|
package/src/main/js/index.js
CHANGED
|
@@ -7,6 +7,8 @@ import {build} from './build.js'
|
|
|
7
7
|
import {getConfig} from './config.js'
|
|
8
8
|
|
|
9
9
|
export const run = async ({cwd = process.cwd(), env = process.env, flags = {}} = {}) => {
|
|
10
|
+
console.log('zx-bulk-release')
|
|
11
|
+
|
|
10
12
|
try {
|
|
11
13
|
const {packages, queue, root} = await topo({cwd})
|
|
12
14
|
const dryRun = flags['dry-run'] || flags.dryRun
|
|
@@ -25,7 +27,7 @@ export const run = async ({cwd = process.cwd(), env = process.env, flags = {}} =
|
|
|
25
27
|
pkg.manifest.version = pkg.version
|
|
26
28
|
|
|
27
29
|
if (changes.length === 0) continue
|
|
28
|
-
console.log(`
|
|
30
|
+
console.log(`[${name}] semantic changes`, changes)
|
|
29
31
|
|
|
30
32
|
await build(pkg, packages, cwd)
|
|
31
33
|
|
package/src/main/js/publish.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {formatTag, getLatestTag} from './tag.js'
|
|
2
|
-
import {tempy, ctx, fs, path} from 'zx-extra'
|
|
2
|
+
import {tempy, ctx, fs, path, $} from 'zx-extra'
|
|
3
3
|
import {copydir} from 'git-glob-cp'
|
|
4
4
|
|
|
5
5
|
export const publish = async (pkg) => {
|
|
6
6
|
await pushTag(pkg)
|
|
7
7
|
await pushMeta(pkg)
|
|
8
|
+
await pushChangelog(pkg)
|
|
8
9
|
await npmPublish(pkg)
|
|
9
|
-
await
|
|
10
|
+
await ghRelease(pkg)
|
|
10
11
|
await ghPages(pkg)
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -16,7 +17,7 @@ export const pushTag = (pkg) => ctx(async ($) => {
|
|
|
16
17
|
const {gitCommitterEmail, gitCommitterName} = parseEnv($.env)
|
|
17
18
|
$.cwd = cwd
|
|
18
19
|
|
|
19
|
-
console.log(`push release tag ${tag}`)
|
|
20
|
+
console.log(`[${name}] push release tag ${tag}`)
|
|
20
21
|
|
|
21
22
|
await $`git config user.name ${gitCommitterName}`
|
|
22
23
|
await $`git config user.email ${gitCommitterEmail}`
|
|
@@ -25,14 +26,14 @@ export const pushTag = (pkg) => ctx(async ($) => {
|
|
|
25
26
|
})
|
|
26
27
|
|
|
27
28
|
export const pushMeta = (pkg) => ctx(async ($) => {
|
|
28
|
-
console.log(
|
|
29
|
+
console.log(`[${pkg.name}] push artifact to branch 'meta'`)
|
|
29
30
|
|
|
30
31
|
const cwd = pkg.absPath
|
|
31
32
|
const {name, version} = pkg
|
|
32
33
|
const tag = formatTag({name, version})
|
|
33
34
|
const to = '.'
|
|
34
|
-
const branch =
|
|
35
|
-
const msg =
|
|
35
|
+
const branch = 'meta'
|
|
36
|
+
const msg = `chore: release meta ${name} ${version}`
|
|
36
37
|
|
|
37
38
|
$.cwd = cwd
|
|
38
39
|
const hash = (await $`git rev-parse HEAD`).toString().trim()
|
|
@@ -51,11 +52,12 @@ export const pushMeta = (pkg) => ctx(async ($) => {
|
|
|
51
52
|
await push({cwd, to, branch, msg, files})
|
|
52
53
|
})
|
|
53
54
|
|
|
54
|
-
export const npmPublish = (
|
|
55
|
+
export const npmPublish = (pkg) => ctx(async ($) => {
|
|
56
|
+
const {absPath: cwd, name, version} = pkg
|
|
55
57
|
const {npmRegistry, npmToken, npmConfig} = parseEnv($.env)
|
|
56
58
|
const npmrc = npmConfig ? npmConfig : path.resolve(cwd, '.npmrc')
|
|
57
59
|
|
|
58
|
-
console.log(`publish npm package to ${npmRegistry}`)
|
|
60
|
+
console.log(`[${name}] publish npm package ${name} ${version} to ${npmRegistry}`)
|
|
59
61
|
$.cwd = cwd
|
|
60
62
|
if (!npmConfig) {
|
|
61
63
|
await $.raw`echo ${npmRegistry.replace(/https?:/, '')}/:_authToken=${npmToken} >> ${npmrc}`
|
|
@@ -63,16 +65,43 @@ export const npmPublish = ({absPath: cwd}) => ctx(async ($) => {
|
|
|
63
65
|
await $`npm publish --no-git-tag-version --registry=${npmRegistry} --userconfig ${npmrc} --no-workspaces`
|
|
64
66
|
})
|
|
65
67
|
|
|
66
|
-
export const
|
|
67
|
-
console.log(
|
|
68
|
+
export const ghRelease = async (pkg) => {
|
|
69
|
+
console.log(`[${pkg.name}] create gh release`)
|
|
68
70
|
|
|
69
|
-
const cwd = pkg.absPath
|
|
70
|
-
const {name, version} = pkg
|
|
71
71
|
const {ghUser, ghToken} = parseEnv($.env)
|
|
72
|
-
const {repoName, repoPublicUrl} = await parseRepo(cwd)
|
|
73
|
-
|
|
74
72
|
if (!ghToken || !ghUser) return null
|
|
75
73
|
|
|
74
|
+
const {name, version, absPath: cwd} = pkg
|
|
75
|
+
const {repoName} = await parseRepo(cwd)
|
|
76
|
+
const tag = formatTag({name, version})
|
|
77
|
+
const releaseNotes = await formatReleaseNotes(pkg)
|
|
78
|
+
const releaseData = JSON.stringify({
|
|
79
|
+
name: tag,
|
|
80
|
+
tag_name: tag,
|
|
81
|
+
body: releaseNotes
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
await $.o({cwd})`curl -u ${ghUser}:${ghToken} -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${repoName}/releases -d ${releaseData}`
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const pushChangelog = async (pkg) => {
|
|
88
|
+
const {config: {changelog: opts}} = pkg
|
|
89
|
+
if (!opts) return
|
|
90
|
+
|
|
91
|
+
console.log(`[${pkg.name}] push changelog`)
|
|
92
|
+
const [branch = 'changelog', file = `${pkg.name.replace(/[^a-z0-9-]/ig, '')}-changelog.md`, msg = `chore: update changelog ${pkg.name}`] = typeof opts === 'string'
|
|
93
|
+
? opts.split(' ')
|
|
94
|
+
: [opts.branch, opts.file, opts.msg]
|
|
95
|
+
const _cwd = await fetch({cwd: pkg.absPath, branch})
|
|
96
|
+
const releaseNotes = await formatReleaseNotes(pkg)
|
|
97
|
+
|
|
98
|
+
await $.o({cwd: _cwd})`echo ${releaseNotes}"\n$(cat ./${file})" > ./${file}`
|
|
99
|
+
await push({cwd: _cwd, branch, msg})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const formatReleaseNotes = async (pkg) => {
|
|
103
|
+
const {name, version, absPath: cwd} = pkg
|
|
104
|
+
const {repoPublicUrl} = await parseRepo(cwd)
|
|
76
105
|
const tag = formatTag({name, version})
|
|
77
106
|
const releaseDiffRef = `## [${name}@${version}](${repoPublicUrl}/compare/${pkg.latest.tag?.ref}...${tag}) (${new Date().toISOString().slice(0, 10)})`
|
|
78
107
|
const releaseDetails = Object.values(pkg.changes
|
|
@@ -88,22 +117,14 @@ export const createGhRelease = (pkg) => ctx(async ($) => {
|
|
|
88
117
|
### ${group}
|
|
89
118
|
${commits.join('\n')}`).join('\n')
|
|
90
119
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
name: tag,
|
|
94
|
-
tag_name: tag,
|
|
95
|
-
body: releaseNotes
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
$.cwd = cwd
|
|
99
|
-
await $`curl -u ${ghUser}:${ghToken} -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${repoName}/releases -d ${releaseData}`
|
|
100
|
-
})
|
|
120
|
+
return releaseDiffRef + '\n' + releaseDetails + '\n'
|
|
121
|
+
}
|
|
101
122
|
|
|
102
123
|
const ghPages = async (pkg) => {
|
|
103
124
|
const {config: {ghPages: opts}} = pkg
|
|
104
125
|
if (!opts) return
|
|
105
126
|
|
|
106
|
-
console.log(
|
|
127
|
+
console.log(`[${pkg.name}] publish to gh-pages`)
|
|
107
128
|
const [from, branch = 'gh-pages', to = '.', msg = `docs: update docs ${pkg.name} ${pkg.version}`] = typeof opts === 'string'
|
|
108
129
|
? opts.split(' ')
|
|
109
130
|
: [opts.from, opts.branch, opts.to, opts.msg]
|
|
@@ -51,7 +51,8 @@ const cwd = await createFakeRepo({
|
|
|
51
51
|
release: {
|
|
52
52
|
buildCmd: 'yarn && yarn build',
|
|
53
53
|
testCmd: 'yarn test',
|
|
54
|
-
fetch: true
|
|
54
|
+
fetch: true,
|
|
55
|
+
changelog: {}
|
|
55
56
|
},
|
|
56
57
|
exports: {
|
|
57
58
|
'.': {
|
|
@@ -174,9 +175,13 @@ test('run()', async () => {
|
|
|
174
175
|
|
|
175
176
|
const origin = (await $`git remote get-url origin`).toString().trim()
|
|
176
177
|
const meta = tempy.temporaryDirectory()
|
|
178
|
+
const chlog = tempy.temporaryDirectory()
|
|
177
179
|
|
|
178
180
|
await $`git clone --single-branch --branch meta --depth 1 ${origin} ${meta}`
|
|
179
181
|
assert.is((await fs.readJson(`${meta}/${tag.toLowerCase().replace(/[^a-z0-9-]/g, '-')}.json`)).version, '1.0.1')
|
|
182
|
+
|
|
183
|
+
await $`git clone --single-branch --branch changelog --depth 1 ${origin} ${chlog}`
|
|
184
|
+
assert.ok((await fs.readFile(`${chlog}/a-changelog.md`, 'utf-8')).includes('### Fixes & improvements'))
|
|
180
185
|
})
|
|
181
186
|
|
|
182
187
|
await addCommits({cwd, commits: [
|