zx-bulk-release 2.2.7 → 2.2.9

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.2.9](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.8...v2.2.9) (2023-03-24)
2
+
3
+ ### Fixes & improvements
4
+ * refactor: wrap git pushers with queuefy ([2e9355f](https://github.com/semrel-extra/zx-bulk-release/commit/2e9355f69724a8ba097024456cbe5a80f37ea2a7))
5
+
6
+ ## [2.2.8](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.7...v2.2.8) (2023-03-24)
7
+
8
+ ### Fixes & improvements
9
+ * fix: fix git-push-rebase-retry hook ([30df2f1](https://github.com/semrel-extra/zx-bulk-release/commit/30df2f1d25d43145343e47f2f96d4a00955d6b76))
10
+
1
11
  ## [2.2.7](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.6...v2.2.7) (2023-03-24)
2
12
 
3
13
  ### Fixes & improvements
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zx-bulk-release",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "description": "zx-based alternative for multi-semantic-release",
5
5
  "type": "module",
6
6
  "exports": {
package/src/main/js/gh.js CHANGED
@@ -1,8 +1,9 @@
1
+ import {queuefy} from 'queuefy'
2
+ import {$, path} from 'zx-extra'
1
3
  import {log} from './log.js'
2
4
  import {getRepo, pushCommit} from './git.js'
3
5
  import {formatTag} from './meta.js'
4
6
  import {formatReleaseNotes} from './changelog.js'
5
- import {$, path} from 'zx-extra'
6
7
  import {msgJoin} from './util.js'
7
8
 
8
9
  export const ghRelease = async (pkg) => {
@@ -24,7 +25,7 @@ export const ghRelease = async (pkg) => {
24
25
  await $.o({cwd})`curl -H 'Authorization: token ${ghToken}' -H 'Accept: application/vnd.github.v3+json' https://api.github.com/repos/${repoName}/releases -d ${releaseData}`
25
26
  }
26
27
 
27
- export const ghPages = async (pkg) => {
28
+ export const ghPages = queuefy(async (pkg) => {
28
29
  const {config: {ghPages: opts, gitCommitterEmail, gitCommitterName, ghBasicAuth: basicAuth}} = pkg
29
30
  if (!opts) return
30
31
 
@@ -45,4 +46,4 @@ export const ghPages = async (pkg) => {
45
46
  gitCommitterName,
46
47
  basicAuth
47
48
  })
48
- }
49
+ })
@@ -1,6 +1,6 @@
1
1
  import {$, ctx, fs, path, tempy, copy} from 'zx-extra'
2
2
  import {log} from './log.js'
3
- import {keyByValue, memoizeBy} from './util.js'
3
+ import {memoizeBy} from './util.js'
4
4
 
5
5
  export const fetchRepo = memoizeBy(async ({cwd: _cwd, branch, origin: _origin, basicAuth}) => ctx(async ($) => {
6
6
  const origin = _origin || (await getRepo(_cwd, {basicAuth})).repoAuthedUrl
@@ -19,30 +19,28 @@ export const fetchRepo = memoizeBy(async ({cwd: _cwd, branch, origin: _origin, b
19
19
 
20
20
  export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFiles, files = [], basicAuth, gitCommitterEmail, gitCommitterName}) => ctx(async ($) => {
21
21
  let retries = 3
22
- let _cwd
23
22
 
24
- while (retries > 0) {
25
- try {
26
- _cwd = await fetchRepo({cwd, branch, origin, basicAuth})
23
+ const _cwd = await fetchRepo({cwd, branch, origin, basicAuth})
24
+ $.cwd = _cwd
27
25
 
28
- for (let {relpath, contents} of files) {
29
- const _contents = typeof contents === 'string' ? contents : JSON.stringify(contents, null, 2)
30
- await fs.outputFile(path.resolve(_cwd, to, relpath), _contents)
31
- }
32
- if (from) await copy({baseFrom: cwd, from, baseTo: _cwd, to, ignoreFiles, cwd})
33
-
34
- $.cwd = _cwd
35
-
36
- await $`git config user.name ${gitCommitterName}`
37
- await $`git config user.email ${gitCommitterEmail}`
38
- await $`git add .`
39
- try {
40
- await $`git commit -m ${msg}`
41
- } catch {
42
- log({level: 'warn'})(`no changes to commit to ${branch}`)
43
- return
44
- }
26
+ for (let {relpath, contents} of files) {
27
+ const _contents = typeof contents === 'string' ? contents : JSON.stringify(contents, null, 2)
28
+ await fs.outputFile(path.resolve(_cwd, to, relpath), _contents)
29
+ }
30
+ if (from) await copy({baseFrom: cwd, from, baseTo: _cwd, to, ignoreFiles, cwd})
45
31
 
32
+ try {
33
+ await $`git config user.name ${gitCommitterName} &&
34
+ git config user.email ${gitCommitterEmail} &&
35
+ git add . &&
36
+ git commit -m ${msg}`
37
+ } catch {
38
+ log({level: 'warn'})(`no changes to commit to ${branch}`)
39
+ return
40
+ }
41
+
42
+ while (retries > 0) {
43
+ try {
46
44
  return await $.raw`git push origin HEAD:refs/heads/${branch}`
47
45
  } catch (e) {
48
46
  retries -= 1
@@ -51,6 +49,8 @@ export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFile
51
49
  if (retries === 0) {
52
50
  throw e
53
51
  }
52
+
53
+ await $`git pull --rebase origin ${branch}`
54
54
  }
55
55
  }
56
56
  })
@@ -1,7 +1,8 @@
1
1
  // Semantic tags processing
2
2
 
3
+ import {Buffer} from 'node:buffer'
4
+ import {queuefy} from 'queuefy'
3
5
  import {ctx, semver, $, fs, path} from 'zx-extra'
4
- import {Buffer} from 'buffer'
5
6
  import {log} from './log.js'
6
7
  import {fetchRepo, pushCommit, getTags as getGitTags} from './git.js'
7
8
  import {fetchManifest} from './npm.js'
@@ -20,7 +21,7 @@ export const pushTag = (pkg) => ctx(async ($) => {
20
21
  await $`git push origin ${tag}`
21
22
  })
22
23
 
23
- export const pushMeta = async (pkg) => {
24
+ export const pushMeta = queuefy(async (pkg) => {
24
25
  log({pkg})('push artifact to branch \'meta\'')
25
26
 
26
27
  const {name, version, absPath: cwd, config: {gitCommitterEmail, gitCommitterName, ghBasicAuth: basicAuth}} = pkg
@@ -42,7 +43,7 @@ export const pushMeta = async (pkg) => {
42
43
  const files = [{relpath: `${getArtifactPath(tag)}.json`, contents: meta}]
43
44
 
44
45
  await pushCommit({cwd, to, branch, msg, files, gitCommitterEmail, gitCommitterName, basicAuth})
45
- }
46
+ })
46
47
 
47
48
  export const getLatest = async (pkg) => {
48
49
  const {absPath: cwd, name, config: {ghBasicAuth: basicAuth}} = pkg
@@ -14,7 +14,8 @@ import {memoizeBy, tpl} from './util.js'
14
14
 
15
15
  export const run = async ({cwd = process.cwd(), env, flags = {}} = {}) => within(async () => {
16
16
  const context = await createContext({flags, env, cwd})
17
- const {report, build, publish, packages, queue, prev, graphs} = context
17
+ const {report, packages, queue, prev, graphs} = context
18
+ const _runCmd = queuefy(runCmd, flags.concurrency || os.cpus().length)
18
19
 
19
20
  report
20
21
  .log()('zx-bulk-release')
@@ -46,11 +47,11 @@ export const run = async ({cwd = process.cwd(), env, flags = {}} = {}) => within
46
47
  }
47
48
  if (!flags.noBuild) {
48
49
  report.setStatus('building', name)
49
- await build(pkg)
50
+ await build(pkg, _runCmd)
50
51
  }
51
52
  if (!flags.dryRun && !flags.noPublish) {
52
53
  report.setStatus('publishing', name)
53
- await publish(pkg)
54
+ await publish(pkg, _runCmd)
54
55
  }
55
56
 
56
57
  report.setStatus('success', name)
@@ -79,9 +80,6 @@ export const runCmd = async (pkg, name) => {
79
80
  const createContext = async ({flags, env, cwd}) => {
80
81
  const { packages, queue, root, prev, graphs } = await topo({cwd, flags})
81
82
  const report = createReport({packages, queue, flags})
82
- const run = queuefy(runCmd, flags.concurrency || os.cpus().length)
83
- const _build = memoizeBy((pkg) => build(pkg, run, _build, flags))
84
- const _publish = memoizeBy((pkg) => publish(pkg, run))
85
83
 
86
84
  $.report = report
87
85
  $.env = {...process.env, ...env}
@@ -89,13 +87,12 @@ const createContext = async ({flags, env, cwd}) => {
89
87
 
90
88
  return {
91
89
  report,
92
- build: _build,
93
- publish: _publish,
94
90
  packages,
95
91
  root,
96
92
  queue,
97
93
  prev,
98
- graphs
94
+ graphs,
95
+ flags
99
96
  }
100
97
  }
101
98
 
@@ -113,11 +110,11 @@ const contextify = async (pkg, {packages, root}) => {
113
110
  }
114
111
  }
115
112
 
116
- const build = async (pkg, run = runCmd, self = build, flags = {}) => within(async () => {
113
+ const build = memoizeBy(async (pkg, run = runCmd, flags = {}, self = build) => within(async () => {
117
114
  $.scope = pkg.name
118
115
 
119
116
  await Promise.all([
120
- traverseDeps(pkg, pkg.context.packages, async (_, {pkg}) => self(pkg, run, self, flags)),
117
+ traverseDeps(pkg, pkg.context.packages, async (_, {pkg}) => self(pkg, run, flags, self)),
121
118
  pkg.changes.length === 0 && pkg.config.npmFetch && !flags.noNpmFetch
122
119
  ? fetchPkg(pkg)
123
120
  : Promise.resolve()
@@ -129,10 +126,11 @@ const build = async (pkg, run = runCmd, self = build, flags = {}) => within(asyn
129
126
  }
130
127
 
131
128
  pkg.built = true
132
- })
129
+ }))
133
130
 
134
- const publish = async (pkg, run = runCmd) => within(async () => {
131
+ const publish = memoizeBy(async (pkg, run = runCmd) => within(async () => {
135
132
  $.scope = pkg.name
133
+
136
134
  await fs.writeJson(pkg.manifestPath, pkg.manifest, {spaces: 2})
137
135
  await pushTag(pkg)
138
136
 
@@ -146,4 +144,4 @@ const publish = async (pkg, run = runCmd) => within(async () => {
146
144
  ])
147
145
 
148
146
  pkg.published = true
149
- })
147
+ }))