zx-bulk-release 2.9.3 → 2.11.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 +10 -0
- package/package.json +1 -1
- package/src/main/js/gh.js +47 -6
- package/src/main/js/npm.js +3 -1
- package/src/main/js/processor.js +5 -1
- package/src/main/js/util.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [2.11.0](https://github.com/semrel-extra/zx-bulk-release/compare/v2.10.0...v2.11.0) (2023-06-27)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
* feat: introduce gh assets uploader ([4967fd9](https://github.com/semrel-extra/zx-bulk-release/commit/4967fd9895db684c6832c6055a716c7c7eb1a313))
|
|
5
|
+
|
|
6
|
+
## [2.10.0](https://github.com/semrel-extra/zx-bulk-release/compare/v2.9.3...v2.10.0) (2023-06-27)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
* feat: log `fetch`, `build` & `test` steps duration ([b7b3db3](https://github.com/semrel-extra/zx-bulk-release/commit/b7b3db3af378f3153f8ad8fa62eec79852da6c0b))
|
|
10
|
+
|
|
1
11
|
## [2.9.3](https://github.com/semrel-extra/zx-bulk-release/compare/v2.9.2...v2.9.3) (2023-06-27)
|
|
2
12
|
|
|
3
13
|
### Fixes & improvements
|
package/package.json
CHANGED
package/src/main/js/gh.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import {queuefy} from 'queuefy'
|
|
2
|
-
import {$, path} from 'zx-extra'
|
|
2
|
+
import {$, path, tempy, glob, fs} from 'zx-extra'
|
|
3
3
|
import {log} from './log.js'
|
|
4
4
|
import {getRepo, pushCommit} from './git.js'
|
|
5
5
|
import {formatTag} from './meta.js'
|
|
6
6
|
import {formatReleaseNotes} from './changelog.js'
|
|
7
|
-
import {msgJoin} from './util.js'
|
|
7
|
+
import {asArray, msgJoin} from './util.js'
|
|
8
8
|
|
|
9
|
+
// https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release
|
|
9
10
|
export const ghRelease = async (pkg) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const {ghBasicAuth: basicAuth, ghToken} = pkg.config
|
|
11
|
+
const {ghBasicAuth: basicAuth, ghToken, ghAssets} = pkg.config
|
|
13
12
|
if (!ghToken) return null
|
|
14
13
|
|
|
14
|
+
log({pkg})('create gh release')
|
|
15
|
+
|
|
16
|
+
const now = Date.now()
|
|
15
17
|
const {name, version, absPath: cwd} = pkg
|
|
16
18
|
const {repoName} = await getRepo(cwd, {basicAuth})
|
|
17
19
|
const tag = formatTag({name, version})
|
|
@@ -25,7 +27,13 @@ export const ghRelease = async (pkg) => {
|
|
|
25
27
|
const {stdout} = await $.o({cwd})`curl -H 'Authorization: token ${ghToken}' -H 'Accept: application/vnd.github.v3+json' https://api.github.com/repos/${repoName}/releases -d ${releaseData}`
|
|
26
28
|
const res = JSON.parse(stdout.toString().trim())
|
|
27
29
|
|
|
28
|
-
log({pkg})('gh release url:', res.url, res.html_url)
|
|
30
|
+
log({pkg})('gh release url:', res.url, res.html_url, res.upload_url)
|
|
31
|
+
|
|
32
|
+
if (ghAssets) {
|
|
33
|
+
await ghUploadAssets({ghToken, uploadUrl: res.upload_url})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
log({pkg})(`duration gh release: ${Date.now() - now}`)
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
export const ghPages = queuefy(async (pkg) => {
|
|
@@ -50,3 +58,36 @@ export const ghPages = queuefy(async (pkg) => {
|
|
|
50
58
|
basicAuth
|
|
51
59
|
})
|
|
52
60
|
})
|
|
61
|
+
|
|
62
|
+
// https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset8
|
|
63
|
+
export const ghPrepareAssets = async (assets) => {
|
|
64
|
+
const temp = tempy.temporaryDirectory()
|
|
65
|
+
|
|
66
|
+
await Promise.all(assets.map(async ({name, source = 'target/**/*', zip, cwd}) => {
|
|
67
|
+
const patterns = asArray(source)
|
|
68
|
+
const target = path.join(temp, name)
|
|
69
|
+
if (patterns.some(s => s.includes('*'))) {
|
|
70
|
+
zip = true
|
|
71
|
+
}
|
|
72
|
+
const files = await glob(patterns, {cwd, absolute: true, onlyFiles: true})
|
|
73
|
+
|
|
74
|
+
if (!zip && files.length === 1) {
|
|
75
|
+
await fs.copy(files[0], target)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return $.raw`tar -C ${cwd} -cv${zip ? 'z' : ''}f ${target} ${files.join(' ')}`
|
|
80
|
+
}))
|
|
81
|
+
|
|
82
|
+
return temp
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const ghUploadAssets = async ({ghToken, ghAssets, uploadUrl}) => {
|
|
86
|
+
const cwd = await ghPrepareAssets(ghAssets)
|
|
87
|
+
|
|
88
|
+
return Promise.all(ghAssets.map(async ({name}) => {
|
|
89
|
+
const url = `${uploadUrl}?name=${name}`
|
|
90
|
+
return $.o({cwd})`curl -H 'Authorization: token ${ghToken}' -H 'Accept: application/vnd.github.v3+json' -H 'Content-Type: application/octet-stream' ${url} --data-binary '@${name}'`
|
|
91
|
+
}))
|
|
92
|
+
}
|
|
93
|
+
|
package/src/main/js/npm.js
CHANGED
|
@@ -3,6 +3,7 @@ import {$, fs, INI, fetch, tempy} from 'zx-extra'
|
|
|
3
3
|
|
|
4
4
|
export const fetchPkg = async (pkg) => {
|
|
5
5
|
const id = `${pkg.name}@${pkg.version}`
|
|
6
|
+
const now = Date.now()
|
|
6
7
|
|
|
7
8
|
try {
|
|
8
9
|
const cwd = pkg.absPath
|
|
@@ -11,8 +12,9 @@ export const fetchPkg = async (pkg) => {
|
|
|
11
12
|
const bearerToken = getBearerToken(npmRegistry, npmToken, npmConfig)
|
|
12
13
|
const authorization = bearerToken ? `--header='Authorization: ${bearerToken}'` : ''
|
|
13
14
|
log({pkg})(`fetching '${id}' from ${npmRegistry}`)
|
|
14
|
-
await $.raw`wget --timeout=
|
|
15
|
+
await $.raw`wget --timeout=15 --connect-timeout=5 ${authorization} -qO- ${tarballUrl} | tar -xvz --strip-components=1 --exclude='package.json' -C ${cwd}`
|
|
15
16
|
|
|
17
|
+
log({pkg})(`fetch duration '${id}': ${Date.now() - now}`)
|
|
16
18
|
pkg.fetched = true
|
|
17
19
|
} catch (e) {
|
|
18
20
|
log({pkg, level: 'warn'})(`fetching '${id}' failed`, e)
|
package/src/main/js/processor.js
CHANGED
|
@@ -79,10 +79,14 @@ export const run = async ({cwd = process.cwd(), env, flags = {}} = {}) => within
|
|
|
79
79
|
|
|
80
80
|
export const runCmd = async (pkg, name) => {
|
|
81
81
|
const cmd = tpl(pkg.config[name], {...pkg, ...pkg.context})
|
|
82
|
+
const now = Date.now()
|
|
82
83
|
|
|
83
84
|
if (cmd) {
|
|
84
85
|
log({pkg})(`run ${name} '${cmd}'`)
|
|
85
|
-
|
|
86
|
+
const result = await $.o({cwd: pkg.absPath, quote: v => v, preferLocal: true})`${cmd}`
|
|
87
|
+
|
|
88
|
+
log({pkg})(`duration ${name}: ${Date.now() - now}`)
|
|
89
|
+
return result
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
|