bulk-release 2.10.0 → 2.11.1

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 CHANGED
@@ -1,3 +1,13 @@
1
+ ## [2.11.1](https://github.com/semrel-extra/zx-bulk-release/compare/v2.11.0...v2.11.1) (2023-06-27)
2
+
3
+ ### Fixes & improvements
4
+ * fix: pass pkg root to `ghAssets` resolver ([b0ba371](https://github.com/semrel-extra/zx-bulk-release/commit/b0ba371263544b7b4081481024fc94413c1a0409))
5
+
6
+ ## [2.11.0](https://github.com/semrel-extra/zx-bulk-release/compare/v2.10.0...v2.11.0) (2023-06-27)
7
+
8
+ ### Features
9
+ * feat: introduce gh assets uploader ([4967fd9](https://github.com/semrel-extra/zx-bulk-release/commit/4967fd9895db684c6832c6055a716c7c7eb1a313))
10
+
1
11
  ## [2.10.0](https://github.com/semrel-extra/zx-bulk-release/compare/v2.9.3...v2.10.0) (2023-06-27)
2
12
 
3
13
  ### Features
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bulk-release",
3
3
  "alias": "bulk-release",
4
- "version": "2.10.0",
4
+ "version": "2.11.1",
5
5
  "description": "zx-based alternative for multi-semantic-release",
6
6
  "type": "module",
7
7
  "exports": {
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
- log({pkg})('create gh release')
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, cwd})
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, _cwd) => {
64
+ const temp = tempy.temporaryDirectory()
65
+
66
+ await Promise.all(assets.map(async ({name, source = 'target/**/*', zip, cwd = _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, cwd}) => {
86
+ const temp = await ghPrepareAssets(ghAssets, cwd)
87
+
88
+ return Promise.all(ghAssets.map(async ({name}) => {
89
+ const url = `${uploadUrl}?name=${name}`
90
+ return $.o({cwd: temp})`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
+
@@ -44,3 +44,5 @@ export const memoizeBy = (fn, getKey = v => v, memo = new Map()) => async (...ar
44
44
  }
45
45
 
46
46
  export const camelize = s => s.replace(/-./g, x => x[1].toUpperCase())
47
+
48
+ export const asArray = v => Array.isArray(v) ? v : [v]