zx-bulk-release 2.2.7 → 2.2.8

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,8 @@
1
+ ## [2.2.8](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.7...v2.2.8) (2023-03-24)
2
+
3
+ ### Fixes & improvements
4
+ * fix: fix git-push-rebase-retry hook ([30df2f1](https://github.com/semrel-extra/zx-bulk-release/commit/30df2f1d25d43145343e47f2f96d4a00955d6b76))
5
+
1
6
  ## [2.2.7](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.6...v2.2.7) (2023-03-24)
2
7
 
3
8
  ### 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.8",
4
4
  "description": "zx-based alternative for multi-semantic-release",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,7 @@
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
+ import {queuefy} from 'queuefy'
4
5
 
5
6
  export const fetchRepo = memoizeBy(async ({cwd: _cwd, branch, origin: _origin, basicAuth}) => ctx(async ($) => {
6
7
  const origin = _origin || (await getRepo(_cwd, {basicAuth})).repoAuthedUrl
@@ -17,32 +18,30 @@ export const fetchRepo = memoizeBy(async ({cwd: _cwd, branch, origin: _origin, b
17
18
  return cwd
18
19
  }), async ({cwd, branch}) => `${await getRoot(cwd)}:${branch}`)
19
20
 
20
- export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFiles, files = [], basicAuth, gitCommitterEmail, gitCommitterName}) => ctx(async ($) => {
21
+ export const pushCommit = queuefy(async ({cwd, from, to, branch, origin, msg, ignoreFiles, files = [], basicAuth, gitCommitterEmail, gitCommitterName}) => ctx(async ($) => {
21
22
  let retries = 3
22
- let _cwd
23
23
 
24
- while (retries > 0) {
25
- try {
26
- _cwd = await fetchRepo({cwd, branch, origin, basicAuth})
24
+ const _cwd = await fetchRepo({cwd, branch, origin, basicAuth})
25
+ $.cwd = _cwd
27
26
 
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
- }
27
+ for (let {relpath, contents} of files) {
28
+ const _contents = typeof contents === 'string' ? contents : JSON.stringify(contents, null, 2)
29
+ await fs.outputFile(path.resolve(_cwd, to, relpath), _contents)
30
+ }
31
+ if (from) await copy({baseFrom: cwd, from, baseTo: _cwd, to, ignoreFiles, cwd})
32
+
33
+ try {
34
+ await $`git config user.name ${gitCommitterName} &&
35
+ git config user.email ${gitCommitterEmail} &&
36
+ git add . &&
37
+ git commit -m ${msg}`
38
+ } catch {
39
+ log({level: 'warn'})(`no changes to commit to ${branch}`)
40
+ return
41
+ }
45
42
 
43
+ while (retries > 0) {
44
+ try {
46
45
  return await $.raw`git push origin HEAD:refs/heads/${branch}`
47
46
  } catch (e) {
48
47
  retries -= 1
@@ -51,9 +50,11 @@ export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFile
51
50
  if (retries === 0) {
52
51
  throw e
53
52
  }
53
+
54
+ await $`git pull --rebase origin ${branch}`
54
55
  }
55
56
  }
56
- })
57
+ }))
57
58
 
58
59
  export const getRoot = async (cwd) => (await $.o({cwd})`git rev-parse --show-toplevel`).toString().trim()
59
60
 
@@ -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
+ }))