bulk-release 3.2.0 → 3.3.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 +16 -0
- package/README.md +58 -22
- package/package.json +7 -6
- package/src/main/js/cli.js +3 -3
- package/src/main/js/config.js +2 -1
- package/src/main/js/post/api/git.js +96 -47
- package/src/main/js/post/api/npm.js +24 -15
- package/src/main/js/post/courier/channels/changelog.js +5 -10
- package/src/main/js/post/courier/channels/cmd.js +5 -1
- package/src/main/js/post/courier/channels/gh-pages.js +4 -4
- package/src/main/js/post/courier/channels/gh-release.js +3 -3
- package/src/main/js/post/courier/channels/git-tag.js +6 -26
- package/src/main/js/post/courier/channels/index.js +19 -0
- package/src/main/js/post/courier/channels/meta.js +4 -4
- package/src/main/js/post/courier/channels/npm.js +20 -17
- package/src/main/js/post/courier/execute.js +88 -0
- package/src/main/js/post/courier/index.js +115 -228
- package/src/main/js/post/courier/plan.js +149 -0
- package/src/main/js/post/courier/semaphore.js +14 -24
- package/src/main/js/post/courier/seniority.js +7 -17
- package/src/main/js/post/depot/context.js +14 -1
- package/src/main/js/post/depot/deps.js +13 -1
- package/src/main/js/post/depot/exec.js +2 -2
- package/src/main/js/post/depot/reconcile.js +15 -23
- package/src/main/js/post/depot/steps/clean.js +1 -2
- package/src/main/js/post/depot/steps/contextify.js +9 -0
- package/src/main/js/post/depot/steps/pack.js +6 -4
- package/src/main/js/post/depot/steps/publish.js +2 -1
- package/src/main/js/post/log.js +10 -1
- package/src/main/js/post/modes/deliver.js +14 -30
- package/src/main/js/post/modes/pack.js +8 -16
- package/src/main/js/post/modes/receive.js +10 -14
- package/src/main/js/post/modes/verify.js +18 -2
- package/src/main/js/post/parcel/build.js +24 -3
- package/src/main/js/post/parcel/directive.js +10 -24
- package/src/main/js/post/parcel/index.js +7 -1
- package/src/main/js/post/parcel/populate.js +136 -0
- package/src/main/js/post/parcel/verify-directive.js +81 -0
- package/src/main/js/post/parcel/verify.js +93 -36
- package/src/main/js/post/release.js +5 -4
- package/src/main/js/post/tar.js +83 -20
- package/src/main/js/util.js +32 -5
- package/src/test/js/utils/mock.js +0 -3
- package/src/test/js/utils/repo.js +10 -4
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// What the courier is about to deliver: parcels read for this env and arranged into packages.
|
|
2
|
+
// Nothing here touches a remote; the plan is all a dry run does.
|
|
3
|
+
|
|
4
|
+
import {path, semver} from 'zx-extra'
|
|
5
|
+
import {topoOrder} from '../../util.js'
|
|
6
|
+
import {readManifest, readMarker} from '../tar.js'
|
|
7
|
+
import {log} from '../log.js'
|
|
8
|
+
import {parcelChannel} from '../parcel/directive.js'
|
|
9
|
+
import {PLACEHOLDER, mergePopulate, assertPopulate, checkManifest} from '../parcel/populate.js'
|
|
10
|
+
import {channels, stageOf} from './channels/index.js'
|
|
11
|
+
|
|
12
|
+
const own = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)
|
|
13
|
+
|
|
14
|
+
export const ghAuth = (env) => {
|
|
15
|
+
const token = env.GH_TOKEN || env.GITHUB_TOKEN
|
|
16
|
+
const user = ['GH_USER', 'GH_USERNAME', 'GITHUB_USER', 'GITHUB_USERNAME'].map(k => env[k]).find(Boolean) || 'x-access-token'
|
|
17
|
+
return token ? `${user}:${token}` : ''
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const resolveManifest = (manifest, env = process.env) => {
|
|
21
|
+
// Credentials-bearing fields are derived below, never taken from the parcel.
|
|
22
|
+
const {repoAuthedUrl, ghBasicAuth, ...fields} = manifest
|
|
23
|
+
// fromEntries defines own properties: a `__proto__` key stays a plain field and can't swap the prototype
|
|
24
|
+
const resolved = Object.fromEntries(Object.entries(fields).map(([k, v]) =>
|
|
25
|
+
[k, typeof v === 'string' ? v.replace(PLACEHOLDER, (_, n) => env[n] || '') : v]))
|
|
26
|
+
|
|
27
|
+
const {repoHost, repoName, originUrl} = resolved
|
|
28
|
+
const auth = ghAuth(env)
|
|
29
|
+
|
|
30
|
+
if (repoHost && repoName && auth) {
|
|
31
|
+
resolved.repoAuthedUrl = `https://${auth}@${repoHost}/${repoName}.git`
|
|
32
|
+
resolved.ghBasicAuth = auth
|
|
33
|
+
} else if (originUrl) {
|
|
34
|
+
resolved.repoAuthedUrl = originUrl
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return resolved
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Manifest fields the channel needs to run, but that are empty after resolution.
|
|
41
|
+
export const missingRequires = (ch, resolved) =>
|
|
42
|
+
(typeof ch.requires === 'function' ? ch.requires(resolved) : (ch.requires || [])).filter(f => !resolved[f])
|
|
43
|
+
|
|
44
|
+
const populateErrors = (manifest, resolved) => {
|
|
45
|
+
if (own(manifest, '__proto__')) return ['__proto__: is not allowed']
|
|
46
|
+
try {
|
|
47
|
+
const populate = manifest.populate ? assertPopulate(manifest.populate) : mergePopulate()
|
|
48
|
+
return checkManifest({values: resolved, channel: resolved.channel, populate})
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return [e.message]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Parcel: {file, tarPath, state, stage, ch, resolved, reason}
|
|
55
|
+
// state: ready | released | conflict (markers) | held (not deliverable by this env) | invalid (breaks its rules)
|
|
56
|
+
// | dropped (3.x skip and orphan markers: nothing is left to deliver)
|
|
57
|
+
// Every parcel has a stage, so no parcel, however broken, slips past the claim of its package.
|
|
58
|
+
const MARKER_STATES = {released: 'released', conflict: 'conflict', skip: 'dropped', orphan: 'dropped'}
|
|
59
|
+
|
|
60
|
+
export const openParcel = async (tarPath, env) => {
|
|
61
|
+
const file = path.basename(tarPath)
|
|
62
|
+
const stage = stageOf(parcelChannel(file))
|
|
63
|
+
const marker = await readMarker(tarPath)
|
|
64
|
+
if (marker) return {file, tarPath, stage, state: MARKER_STATES[marker]}
|
|
65
|
+
|
|
66
|
+
const manifest = await readManifest(tarPath).catch(() => null)
|
|
67
|
+
if (!manifest || typeof manifest !== 'object') return {file, tarPath, stage, state: 'invalid', reason: 'unreadable manifest'}
|
|
68
|
+
|
|
69
|
+
const resolved = resolveManifest(manifest, env)
|
|
70
|
+
const ch = own(channels, resolved.channel) ? channels[resolved.channel] : undefined
|
|
71
|
+
return {file, tarPath, resolved, ch, stage: ch ? stageOf(resolved.channel) : stage, ...checkParcel(ch, manifest, resolved)}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Whether this env can deliver the parcel, and whether the parcel keeps its own rules.
|
|
75
|
+
const checkParcel = (ch, manifest, resolved) => {
|
|
76
|
+
if (!ch) return {state: 'held', reason: `unknown channel ${JSON.stringify(resolved.channel ?? null)}`}
|
|
77
|
+
|
|
78
|
+
const missing = missingRequires(ch, resolved)
|
|
79
|
+
if (missing.length) return {state: 'held', reason: `missing credentials — ${missing.join(', ')}`}
|
|
80
|
+
|
|
81
|
+
const errors = populateErrors(manifest, resolved)
|
|
82
|
+
return errors.length ? {state: 'invalid', reason: `populate rules — ${errors.join('; ')}`, errors} : {state: 'ready'}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const openAll = async (tars, env) =>
|
|
86
|
+
new Map((await Promise.all(tars.map(t => openParcel(t, env)))).map(p => [p.file, p]))
|
|
87
|
+
|
|
88
|
+
// A listed parcel must be there and belong to its package, so no parcel rides on another package's claim.
|
|
89
|
+
// A foreign parcel is reported, never marked: it is not this package's to mark.
|
|
90
|
+
const parcelOf = (file, name, version, opened) => {
|
|
91
|
+
const p = opened.get(file)
|
|
92
|
+
if (!p) return {file, state: 'held', reason: 'missing', stage: stageOf(parcelChannel(file))}
|
|
93
|
+
if (p.resolved && (p.resolved.name !== name || p.resolved.version !== version))
|
|
94
|
+
return {file, stage: p.stage, state: 'invalid', reason: `belongs to ${JSON.stringify(`${p.resolved.name}@${p.resolved.version}`)}, not ${name}@${version}`}
|
|
95
|
+
return p
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Plan: {queue, prev, deps: Map<key, key[]>, packages: {[key]: Parcel[]}}
|
|
99
|
+
// prev orders the queue, deps are what a package waits on: in a directive they are the same.
|
|
100
|
+
// The queue follows prev wherever a package stands in it: the order is the graph's, not the list's.
|
|
101
|
+
export const planOf = ({queue, prev = {}, packages}, opened) => {
|
|
102
|
+
const deps = new Map(Object.entries(prev))
|
|
103
|
+
return {
|
|
104
|
+
queue: topoOrder(queue, deps),
|
|
105
|
+
prev: deps,
|
|
106
|
+
deps,
|
|
107
|
+
packages: Object.fromEntries(queue.map(key => {
|
|
108
|
+
const {version, parcels = []} = packages[key] || {}
|
|
109
|
+
return [key, parcels.map(file => parcelOf(file, key, version, opened))]
|
|
110
|
+
})),
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
// Without a directive a parcel belongs to the name@version its manifest names, and that package's claim gates it.
|
|
116
|
+
// Versions of a name go in ascending order, one at a time, yet none waits on another's outcome: they are
|
|
117
|
+
// releases of their own, as in 3.x. A parcel that names no package can't be gated at all: it is `unowned`.
|
|
118
|
+
// Markers carry no manifest and nothing to deliver.
|
|
119
|
+
export const looseOf = (opened) => {
|
|
120
|
+
const packages = {}
|
|
121
|
+
const ids = {}
|
|
122
|
+
const unowned = []
|
|
123
|
+
for (const p of opened.values()) {
|
|
124
|
+
if (!p.resolved && p.state !== 'invalid') continue
|
|
125
|
+
const {name, version} = p.resolved || {}
|
|
126
|
+
if (!name || !version) {
|
|
127
|
+
unowned.push(p.file)
|
|
128
|
+
continue
|
|
129
|
+
}
|
|
130
|
+
const key = `${name}@${version}`
|
|
131
|
+
ids[key] = {name, version}
|
|
132
|
+
const parcels = packages[key] ??= []
|
|
133
|
+
parcels.push(p)
|
|
134
|
+
}
|
|
135
|
+
const queue = Object.keys(packages).sort((a, b) => byVersion(ids[a], ids[b]))
|
|
136
|
+
const prev = new Map()
|
|
137
|
+
queue.forEach((key, i) => { if (i && ids[queue[i - 1]].name === ids[key].name) prev.set(key, [queue[i - 1]]) })
|
|
138
|
+
return {queue, prev, deps: new Map(), packages, unowned}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const byVersion = (a, b) =>
|
|
142
|
+
a.name.localeCompare(b.name) || semver.compare(semver.valid(a.version) || '0.0.0', semver.valid(b.version) || '0.0.0')
|
|
143
|
+
|
|
144
|
+
// Held and invalid parcels are named before anything runs: a failing channel must not hide them.
|
|
145
|
+
export const warnSkipped = (plan) => {
|
|
146
|
+
const parcels = Object.values(plan.packages).flat()
|
|
147
|
+
for (const p of parcels) if (p.state === 'held' || p.state === 'invalid') log.warn(`skipping ${p.file}: ${p.reason}`)
|
|
148
|
+
return plan
|
|
149
|
+
}
|
|
@@ -1,41 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {randomUUID} from 'node:crypto'
|
|
2
2
|
import {api} from '../api/index.js'
|
|
3
|
-
import {
|
|
3
|
+
import {log} from '../log.js'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const ensureHead = async (cwd) => {
|
|
9
|
-
try { await $({cwd, quiet: true})`git rev-parse HEAD` } catch {
|
|
10
|
-
await api.git.setUserConfig(cwd, DEFAULT_GIT_COMMITTER_NAME, DEFAULT_GIT_COMMITTER_EMAIL)
|
|
11
|
-
await $({cwd, quiet: true})`git commit --allow-empty -m init`
|
|
12
|
-
}
|
|
13
|
-
}
|
|
5
|
+
// Lock and rebuild tags point at the release commit, the one the directive delivers.
|
|
6
|
+
const lockTag = (sha) => `zbr-deliver.${sha.slice(0, 7)}`
|
|
7
|
+
const rebuildTag = (sha) => `zbr-rebuild.${sha.slice(0, 7)}`
|
|
14
8
|
|
|
9
|
+
// The holder makes each lock tag unique: identical tag objects from two runners would both push fine.
|
|
15
10
|
export const tryLock = async (cwd, directive) => {
|
|
16
|
-
const
|
|
17
|
-
const body = JSON.stringify({
|
|
11
|
+
const message = JSON.stringify({
|
|
18
12
|
ts: directive.timestamp,
|
|
19
13
|
sha: directive.sha,
|
|
20
14
|
packages: directive.queue,
|
|
15
|
+
holder: randomUUID(),
|
|
21
16
|
})
|
|
22
|
-
|
|
23
|
-
await ensureHead(cwd)
|
|
24
|
-
await api.git.pushAnnotatedTag(cwd, tag, body)
|
|
25
|
-
return true
|
|
26
|
-
} catch {
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
17
|
+
return (await api.git.pushTag({cwd, tag: lockTag(directive.sha), sha: directive.sha, message})).pushed
|
|
29
18
|
}
|
|
30
19
|
|
|
31
20
|
export const unlock = async (cwd, directive) => {
|
|
32
|
-
await api.git.deleteRemoteTag(cwd,
|
|
21
|
+
const res = await api.git.deleteRemoteTag(cwd, lockTag(directive.sha))
|
|
22
|
+
if (res.exitCode !== 0) log.warn(`failed to remove ${lockTag(directive.sha)}, delete it by hand`, res)
|
|
33
23
|
}
|
|
34
24
|
|
|
25
|
+
// An existing tag means the rebuild is already signalled.
|
|
35
26
|
export const signalRebuild = async (cwd, sha) => {
|
|
36
|
-
|
|
37
|
-
try { await api.git.pushAnnotatedTag(cwd, tag, 'rebuild') } catch { /* already signaled */ }
|
|
27
|
+
await api.git.pushTag({cwd, tag: rebuildTag(sha), sha, message: 'rebuild'})
|
|
38
28
|
}
|
|
39
29
|
|
|
40
30
|
export const consumeRebuildSignal = async (cwd, sha) =>
|
|
41
|
-
api.git.deleteRemoteTag(cwd,
|
|
31
|
+
api.git.deleteRemoteTag(cwd, rebuildTag(sha))
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {semver} from 'zx-extra'
|
|
2
|
+
import {api} from '../api/index.js'
|
|
2
3
|
import {parseTag} from '../depot/generators/tag.js'
|
|
3
4
|
|
|
4
|
-
export const hasHigherVersion = async (cwd, name, version) =>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const ref = line.split('\t')[1]?.replace('refs/tags/', '')
|
|
10
|
-
if (!ref) continue
|
|
11
|
-
const parsed = parseTag(ref)
|
|
12
|
-
if (!parsed || parsed.name !== name) continue
|
|
13
|
-
try {
|
|
14
|
-
if (semver.gt(parsed.version, version)) return true
|
|
15
|
-
} catch { /* unparseable version, skip */ }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
5
|
+
export const hasHigherVersion = async (cwd, name, version) =>
|
|
6
|
+
(await api.git.listRemoteTags(cwd)).some(ref => {
|
|
7
|
+
const tag = parseTag(ref)
|
|
8
|
+
return tag?.name === name && !!semver.valid(tag.version) && semver.gt(tag.version, version)
|
|
9
|
+
})
|
|
@@ -25,7 +25,8 @@ export const readContext = async (filePath) => {
|
|
|
25
25
|
return data
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// prev: what each package waits on, as in the directive; snapshot: whether npm publishes under the snapshot tag.
|
|
29
|
+
export const buildContext = (packages, queue, sha, {getChannels, getPopulate, timestamp, prev, snapshot} = {}) => {
|
|
29
30
|
const pkgs = {}
|
|
30
31
|
for (const name of queue) {
|
|
31
32
|
const pkg = packages[name]
|
|
@@ -34,6 +35,7 @@ export const buildContext = (packages, queue, sha, {getChannels} = {}) => {
|
|
|
34
35
|
version: pkg.version,
|
|
35
36
|
tag: pkg.tag,
|
|
36
37
|
channels: getChannels ? getChannels(pkg) : [],
|
|
38
|
+
populate: getPopulate ? getPopulate(pkg) : undefined,
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -41,6 +43,17 @@ export const buildContext = (packages, queue, sha, {getChannels} = {}) => {
|
|
|
41
43
|
status: 'proceed',
|
|
42
44
|
sha,
|
|
43
45
|
sha7: sha.slice(0, 7),
|
|
46
|
+
timestamp, // commit time: directives are delivered oldest first
|
|
47
|
+
snapshot,
|
|
48
|
+
prev: prev && prevOf(prev, Object.keys(pkgs)),
|
|
44
49
|
packages: pkgs,
|
|
45
50
|
}
|
|
46
51
|
}
|
|
52
|
+
|
|
53
|
+
// The dependencies among the given packages only, the way the directive keeps them.
|
|
54
|
+
export const prevOf = (prev, names) => {
|
|
55
|
+
const listed = new Set(names)
|
|
56
|
+
return Object.fromEntries(names
|
|
57
|
+
.map(name => [name, (prev.get(name) || []).filter(d => listed.has(d))])
|
|
58
|
+
.filter(([, deps]) => deps.length))
|
|
59
|
+
}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import {semver} from 'zx-extra'
|
|
2
|
-
import {topo as _topo, traverseDeps} from '@semrel-extra/topo'
|
|
2
|
+
import {topo as _topo, traverseDeps, traverseQueue} from '@semrel-extra/topo'
|
|
3
|
+
import {throwAll} from '../../util.js'
|
|
3
4
|
|
|
4
5
|
export {traverseQueue, traverseDeps} from '@semrel-extra/topo'
|
|
5
6
|
|
|
7
|
+
// traverseQueue that settles: after the first error no package starts, the running ones finish,
|
|
8
|
+
// and the errors come out together — nothing is cut halfway by the exit that follows.
|
|
9
|
+
export const settleQueue = async ({queue, prev, cb}) => {
|
|
10
|
+
const errors = []
|
|
11
|
+
await traverseQueue({queue, prev, cb: async (name) => {
|
|
12
|
+
if (errors.length) return
|
|
13
|
+
try { await cb(name) } catch (e) { errors.push(e) }
|
|
14
|
+
}})
|
|
15
|
+
throwAll(errors, 'packages')
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
export const updateDeps = async (pkg) => {
|
|
7
19
|
const changes = []
|
|
8
20
|
const {packages} = pkg.ctx
|
|
@@ -2,13 +2,13 @@ import {tpl} from '../../util.js'
|
|
|
2
2
|
import {log} from '../log.js'
|
|
3
3
|
import {$} from 'zx-extra'
|
|
4
4
|
|
|
5
|
-
export const exec = async (pkg, name) => {
|
|
5
|
+
export const exec = async (pkg, name, env = $.env) => {
|
|
6
6
|
const cmd = tpl(pkg.ctx.flags[name] ?? pkg.config[name], {...pkg, ...pkg.ctx})
|
|
7
7
|
const now = Date.now()
|
|
8
8
|
|
|
9
9
|
if (cmd) {
|
|
10
10
|
log.info(`run ${name} '${cmd}'`)
|
|
11
|
-
const result = await $({cwd: pkg.absPath, quote: v => v, preferLocal: true})`${cmd}`
|
|
11
|
+
const result = await $({cwd: pkg.absPath, env, quote: v => v, preferLocal: true})`${cmd}`
|
|
12
12
|
|
|
13
13
|
log.info(`duration ${name}: ${Date.now() - now}`)
|
|
14
14
|
return result
|
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
import {$} from 'zx-extra'
|
|
2
1
|
import {api} from '../api/index.js'
|
|
3
2
|
import {log} from '../log.js'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import {getLatestTag} from './generators/meta.js'
|
|
4
|
+
import {analyze} from './steps/analyze.js'
|
|
6
5
|
|
|
7
6
|
export const preflight = async (pkg, ctx) => {
|
|
8
7
|
if (!pkg.tag) return 'ok'
|
|
9
8
|
|
|
10
9
|
const cwd = ctx.git.root
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
10
|
+
const commit = await api.git.getRemoteTagCommit(cwd, pkg.tag)
|
|
11
|
+
if (!commit) return 'ok'
|
|
13
12
|
|
|
14
13
|
// tag exists on remote
|
|
15
|
-
if (
|
|
14
|
+
if (commit === ctx.git.sha) {
|
|
16
15
|
log.info(`preflight: ${pkg.tag} already exists for our commit, skipping`)
|
|
17
16
|
return 'skip'
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
//
|
|
21
|
-
await
|
|
19
|
+
// bring the tagged commit and enough history for merge-base
|
|
20
|
+
await api.git.fetchTags(cwd)
|
|
21
|
+
await api.git.deepen(cwd, 100)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
if (isOursOlder.exitCode === 0) {
|
|
23
|
+
if (await api.git.isAncestor(cwd, ctx.git.sha, commit)) {
|
|
25
24
|
log.info(`preflight: ${pkg.tag} — we are older, skipping`)
|
|
26
25
|
return 'skip'
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
log.info(`preflight: ${pkg.tag} — we are newer,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const pre = ctx.flags.snapshot ? `-snap.${ctx.git.sha.slice(0, 7)}` : undefined
|
|
36
|
-
// re-resolve: the fetched tags will give us a new latest version
|
|
37
|
-
const latestVersion = pkg.latest.tag?.version || pkg.manifest.version
|
|
38
|
-
pkg.version = resolvePkgVersion(pkg.releaseType, latestVersion, pkg.manifest.version, pre)
|
|
39
|
-
pkg.manifest.version = pkg.version
|
|
40
|
-
pkg.tag = formatTag({name: pkg.name, version: pkg.version, format: pkg.config.tagFormat})
|
|
41
|
-
return 'refetch'
|
|
28
|
+
// The release behind that tag is ours to build on: analyze again from it. No changes since — nothing to release.
|
|
29
|
+
if (await api.git.isAncestor(cwd, commit, ctx.git.sha)) {
|
|
30
|
+
log.info(`preflight: ${pkg.tag} — we are newer, analyzing from the fetched tags`)
|
|
31
|
+
pkg.latest = {...pkg.latest, tag: await getLatestTag(pkg.absPath, pkg.name)}
|
|
32
|
+
await analyze(pkg, ctx)
|
|
33
|
+
return pkg.releaseType ? 'refetch' : 'skip'
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
// diverged — anomaly
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {api} from '../../api/index.js'
|
|
2
2
|
|
|
3
|
-
export const clean = async ({
|
|
4
|
-
await api.git.unsetUserConfig(cwd)
|
|
3
|
+
export const clean = async ({packages}) => {
|
|
5
4
|
await Promise.all(Object.values(packages).filter(p => !p.skipped).map(api.npm.npmRestore))
|
|
6
5
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import {$, within} from 'zx-extra'
|
|
1
2
|
import {getPkgConfig} from '../../../config.js'
|
|
2
3
|
import {api} from '../../api/index.js'
|
|
3
4
|
import {getLatest} from '../generators/meta.js'
|
|
5
|
+
import {settleQueue} from '../deps.js'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Global release context — one per `run()` invocation.
|
|
@@ -48,3 +50,10 @@ export const contextify = async (pkg, ctx) => {
|
|
|
48
50
|
},
|
|
49
51
|
}
|
|
50
52
|
}
|
|
53
|
+
|
|
54
|
+
// Runs cb for each package in dependency order, in the package's own scope and context, and settles.
|
|
55
|
+
export const forEachPkg = (ctx, cb) => settleQueue({queue: ctx.queue, prev: ctx.prev, cb: (name) => within(async () => {
|
|
56
|
+
$.scope = name
|
|
57
|
+
await contextify(ctx.packages[name], ctx)
|
|
58
|
+
return cb(ctx.packages[name])
|
|
59
|
+
})})
|
|
@@ -2,7 +2,7 @@ import {$, tempy, fs, path} from 'zx-extra'
|
|
|
2
2
|
import {memoizeBy, asTuple} from '../../../util.js'
|
|
3
3
|
import {api} from '../../api/index.js'
|
|
4
4
|
import {prepare, getActiveChannels} from '../../courier/index.js'
|
|
5
|
-
import {buildParcels,
|
|
5
|
+
import {buildParcels, parcelsDir} from '../../parcel/index.js'
|
|
6
6
|
import {sanitizePkgName} from '../../parcel/build.js'
|
|
7
7
|
import {formatReleaseNotes} from '../generators/notes.js'
|
|
8
8
|
import {packTar, hashFile} from '../../tar.js'
|
|
@@ -49,20 +49,22 @@ export const pack = memoizeBy(async (pkg, ctx = pkg.ctx) => {
|
|
|
49
49
|
await prepare(active, pkg)
|
|
50
50
|
await api.npm.npmPersist(pkg)
|
|
51
51
|
|
|
52
|
-
const outputDir = flags.pack ?
|
|
52
|
+
const outputDir = flags.pack ? parcelsDir(ctx.git.root, flags) : null
|
|
53
53
|
const stageDir = outputDir || tempy.temporaryDirectory()
|
|
54
54
|
if (outputDir) await fs.ensureDir(outputDir)
|
|
55
55
|
const {repoName, repoHost, originUrl} = await api.git.getRepo(pkg.absPath, {basicAuth: pkg.config.ghBasicAuth})
|
|
56
56
|
const artifacts = {repoName, repoHost, originUrl}
|
|
57
|
+
// Packages are packed in parallel, and packers name tarballs on their own: keep each package's files apart.
|
|
58
|
+
const workDir = tempy.temporaryDirectory()
|
|
57
59
|
|
|
58
60
|
if (active.includes('npm')) {
|
|
59
|
-
artifacts.npmTarball = await packNpmTarball(pkg,
|
|
61
|
+
artifacts.npmTarball = await packNpmTarball(pkg, workDir)
|
|
60
62
|
}
|
|
61
63
|
if (active.includes('gh-release') || active.includes('changelog'))
|
|
62
64
|
artifacts.releaseNotes = await formatReleaseNotes(pkg)
|
|
63
65
|
if (active.includes('gh-pages')) {
|
|
64
66
|
const [, from = 'docs'] = asTuple(pkg.config.ghPages, ['branch', 'from'])
|
|
65
|
-
artifacts.docsDir = path.join(
|
|
67
|
+
artifacts.docsDir = path.join(workDir, 'docs')
|
|
66
68
|
await fs.copy(path.join(pkg.absPath, from), artifacts.docsDir)
|
|
67
69
|
}
|
|
68
70
|
if (active.includes('gh-release') && pkg.config.ghAssets?.length)
|
|
@@ -9,7 +9,8 @@ export const publish = memoizeBy(async (pkg, ctx = pkg.ctx) => {
|
|
|
9
9
|
const {run = exec, channels: channelNames = [], flags} = ctx
|
|
10
10
|
const {tars = []} = pkg
|
|
11
11
|
|
|
12
|
-
await deliver(tars, ctx.env)
|
|
12
|
+
const {invalid} = await deliver(tars, ctx.env, {cwd: ctx.git.root})
|
|
13
|
+
if (invalid.length) throw new Error(`${invalid.length} invalid parcel(s) of ${pkg.name} not delivered, see the warnings above`)
|
|
13
14
|
|
|
14
15
|
const cmd = channels.cmd
|
|
15
16
|
if (channelNames.includes('cmd') && cmd?.when(pkg) && (!flags.snapshot || cmd.snapshot))
|
package/src/main/js/post/log.js
CHANGED
|
@@ -10,8 +10,17 @@ export const redact = (v) => {
|
|
|
10
10
|
return v
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// Errors are logged as redacted stacks (with every inner error of an aggregate) and remembered,
|
|
14
|
+
// so the CLI prints only failures nobody has reported yet.
|
|
15
|
+
const printed = new WeakSet()
|
|
16
|
+
export const wasPrinted = (e) => printed.has(e)
|
|
17
|
+
|
|
18
|
+
const describe = (e) => [e, ...(e instanceof AggregateError ? e.errors : [])]
|
|
19
|
+
.map(err => { if (err instanceof Error) printed.add(err); return redact(String(err?.stack || err)) })
|
|
20
|
+
.join('\n')
|
|
21
|
+
|
|
13
22
|
// Module-level logger. Delegates to $.report when inside a release run, falls back to console.
|
|
14
|
-
const sanitize = (args) => args.map(a => typeof a === 'string' ? redact(a) : a)
|
|
23
|
+
const sanitize = (args) => args.map(a => typeof a === 'string' ? redact(a) : a instanceof Error ? describe(a) : a)
|
|
15
24
|
const r = () => $.report || console
|
|
16
25
|
|
|
17
26
|
export const log = Object.assign(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {$, glob, path
|
|
1
|
+
import {$, glob, path} from 'zx-extra'
|
|
2
2
|
import {createReport, log} from '../log.js'
|
|
3
3
|
import {deliver} from '../courier/index.js'
|
|
4
4
|
import {PARCELS_DIR} from '../parcel/index.js'
|
|
@@ -10,38 +10,22 @@ export const runDeliver = async ({env, flags}) => {
|
|
|
10
10
|
$.memo = new Map()
|
|
11
11
|
$.report = report
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const tars = await glob(path.join(dir, 'parcel.*.tar'))
|
|
16
|
-
if (!tars.length) return report.setStatus('success').log(`no parcels in ${dir}`)
|
|
13
|
+
try {
|
|
14
|
+
report.setStatus('inspecting')
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
const tars = await glob(path.join(dir, 'parcel.*.tar'))
|
|
17
|
+
if (!tars.length) return report.setStatus('success').log(`no parcels in ${dir}`)
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
report.setStatus('delivering').log(`parcels: ${tars.length}`)
|
|
20
|
+
const result = await deliver(tars, env, {dryRun: flags.dryRun})
|
|
21
|
+
report.set('delivery', result)
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const ensureGitRepo = async (env) => {
|
|
28
|
-
try {
|
|
29
|
-
return (await $({quiet: true})`git rev-parse --show-toplevel`).toString().trim()
|
|
30
|
-
} catch {
|
|
31
|
-
// Deliver runs in a clean runner with no checkout — init a temp repo for git push operations.
|
|
32
|
-
const tmp = tempy.temporaryDirectory()
|
|
33
|
-
const repo = env.GITHUB_REPOSITORY || ''
|
|
34
|
-
const token = env.GH_TOKEN || env.GITHUB_TOKEN || ''
|
|
35
|
-
const user = env.GH_USER || env.GH_USERNAME || 'x-access-token'
|
|
36
|
-
const server = env.GITHUB_SERVER_URL || 'https://github.com'
|
|
37
|
-
const host = new URL(server).host
|
|
38
|
-
const origin = token
|
|
39
|
-
? `https://${user}:${token}@${host}/${repo}.git`
|
|
40
|
-
: `${server}/${repo}.git`
|
|
23
|
+
log.info(`done: ${result.delivered} delivered, ${result.skipped} skipped`)
|
|
41
24
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
if (result.invalid.length) throw new Error(`${result.invalid.length} invalid parcel(s) not delivered, see the warnings above`)
|
|
26
|
+
report.setStatus('success')
|
|
27
|
+
} catch (e) {
|
|
28
|
+
report.error(e).setStatus('failure')
|
|
29
|
+
throw e
|
|
46
30
|
}
|
|
47
31
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {path} from 'zx-extra'
|
|
2
2
|
|
|
3
3
|
import {log} from '../log.js'
|
|
4
|
-
import {
|
|
5
|
-
import {contextify} from '../depot/steps/contextify.js'
|
|
4
|
+
import {forEachPkg} from '../depot/steps/contextify.js'
|
|
6
5
|
import {analyze} from '../depot/steps/analyze.js'
|
|
7
6
|
import {build} from '../depot/steps/build.js'
|
|
8
7
|
import {pack} from '../depot/steps/pack.js'
|
|
@@ -11,27 +10,21 @@ import {clean} from '../depot/steps/clean.js'
|
|
|
11
10
|
import {test} from '../depot/steps/test.js'
|
|
12
11
|
import {preflight} from '../depot/reconcile.js'
|
|
13
12
|
import {CONTEXT_FILE, readContext} from '../depot/context.js'
|
|
14
|
-
import {buildDirective,
|
|
13
|
+
import {buildDirective, parcelsDir} from '../parcel/index.js'
|
|
15
14
|
|
|
16
15
|
export const runPack = async ({cwd, env, flags}, ctx) => {
|
|
17
|
-
const {report,
|
|
16
|
+
const {report, queue} = ctx
|
|
18
17
|
|
|
19
18
|
// When running in split pipeline (receive → pack → deliver),
|
|
20
19
|
// the context file is the source of truth for what to release.
|
|
21
20
|
const contextFilter = await loadContextFilter(cwd, flags)
|
|
22
21
|
|
|
23
|
-
const forEachPkg = (cb) => traverseQueue({queue, prev, cb: (name) => within(async () => {
|
|
24
|
-
$.scope = name
|
|
25
|
-
await contextify(packages[name], ctx)
|
|
26
|
-
return cb(packages[name])
|
|
27
|
-
})})
|
|
28
|
-
|
|
29
22
|
report
|
|
30
23
|
.log('queue:', queue)
|
|
31
24
|
.log('graphs', ctx.graphs)
|
|
32
25
|
|
|
33
26
|
try {
|
|
34
|
-
await forEachPkg(async (pkg) => {
|
|
27
|
+
await forEachPkg(ctx, async (pkg) => {
|
|
35
28
|
report.setStatus('analyzing', pkg.name)
|
|
36
29
|
await analyze(pkg)
|
|
37
30
|
report.set({
|
|
@@ -46,7 +39,7 @@ export const runPack = async ({cwd, env, flags}, ctx) => {
|
|
|
46
39
|
report.setStatus('pending')
|
|
47
40
|
|
|
48
41
|
const packed = []
|
|
49
|
-
await forEachPkg(async (pkg) => {
|
|
42
|
+
await forEachPkg(ctx, async (pkg) => {
|
|
50
43
|
if (contextFilter) {
|
|
51
44
|
// Split pipeline: context is the source of truth
|
|
52
45
|
const ctxPkg = contextFilter[pkg.name]
|
|
@@ -74,11 +67,10 @@ export const runPack = async ({cwd, env, flags}, ctx) => {
|
|
|
74
67
|
})
|
|
75
68
|
|
|
76
69
|
if (flags.pack && packed.length) {
|
|
77
|
-
|
|
78
|
-
await buildDirective(ctx, packed, outputDir)
|
|
70
|
+
await buildDirective(ctx, packed, parcelsDir(packed[0].ctx.git.root, flags))
|
|
79
71
|
}
|
|
80
72
|
} catch (e) {
|
|
81
|
-
report.error(e
|
|
73
|
+
report.error(e).set('error', e).setStatus('failure')
|
|
82
74
|
throw e
|
|
83
75
|
} finally {
|
|
84
76
|
await clean(ctx)
|