@kitman-sh/software-engineering 0.14.8 → 0.15.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 +118 -0
- package/agents/releaser.md +3 -3
- package/dist/bundle.js +12562 -5360
- package/dist/declarations.json +139340 -4561
- package/kitman.config.ts +163 -2
- package/package.json +4 -3
- package/src/agents.ts +10 -0
- package/src/approved.ts +219 -0
- package/src/backport-schemas.ts +46 -0
- package/src/backport.ts +110 -0
- package/src/build-schemas.ts +135 -0
- package/src/build.ts +202 -739
- package/src/change-request-body.ts +22 -3
- package/src/delivery.ts +26 -6
- package/src/deploy.ts +661 -0
- package/src/errand.ts +124 -76
- package/src/file-tasks.ts +17 -10
- package/src/firewatch.ts +191 -82
- package/src/hillclimb.ts +563 -273
- package/src/hindsight.ts +154 -100
- package/src/implemented.ts +143 -0
- package/src/index.ts +511 -12
- package/src/land-epic.ts +30 -19
- package/src/land.ts +293 -0
- package/src/landed.ts +30 -0
- package/src/opened.ts +79 -0
- package/src/plan-review.ts +7 -8
- package/src/plan.ts +717 -432
- package/src/project-update.ts +50 -11
- package/src/rallied.ts +535 -0
- package/src/release-set.ts +370 -0
- package/src/release.ts +1402 -573
- package/src/reproduced.ts +82 -0
- package/src/research.ts +53 -37
- package/src/revert.ts +331 -0
- package/src/review.ts +466 -250
- package/src/shepherd-output.ts +81 -35
- package/src/shepherd.ts +2109 -1304
- package/src/standing.ts +165 -0
- package/src/suggested-check.ts +8 -0
- package/src/sweep.ts +432 -253
- package/src/tidy.ts +239 -156
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ask,
|
|
3
|
+
call,
|
|
4
|
+
type CalledLoop,
|
|
5
|
+
type ChildFailed,
|
|
6
|
+
defineLoop,
|
|
7
|
+
ReleaseScope,
|
|
8
|
+
step,
|
|
9
|
+
type StepFailed
|
|
10
|
+
} from '@kitman-sh/sdk/loop'
|
|
11
|
+
import * as Effect from 'effect/Effect'
|
|
12
|
+
import * as Schema from 'effect/Schema'
|
|
13
|
+
import releaseLoop, { ReleaseDraft } from './release'
|
|
14
|
+
|
|
15
|
+
/** One repository a closed Milestone or Project ships, as `release.due` names it for the set. */
|
|
16
|
+
export const SetRepository = Schema.Struct({
|
|
17
|
+
repoBindingId: Schema.String,
|
|
18
|
+
repository: Schema.optionalKey(Schema.String).annotate({
|
|
19
|
+
description: "The repository's name, such as acme/app, which `order` can name it by."
|
|
20
|
+
}),
|
|
21
|
+
releaseScope: Schema.optionalKey(ReleaseScope),
|
|
22
|
+
closesProject: Schema.optionalKey(Schema.Boolean),
|
|
23
|
+
reopened: Schema.optionalKey(Schema.Boolean),
|
|
24
|
+
branch: Schema.optionalKey(Schema.String).annotate({ description: 'The branch to gate and tag there.' })
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export type SetRepository = typeof SetRepository.Type
|
|
28
|
+
|
|
29
|
+
/** Why the set cannot be released: a repository listed twice. */
|
|
30
|
+
const setProblem = (input: { readonly repositories: readonly SetRepository[] }) => {
|
|
31
|
+
const ids = input.repositories.map(repository => repository.repoBindingId)
|
|
32
|
+
|
|
33
|
+
return new Set(ids).size === ids.length || 'each repository is listed once'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const ReleaseSetInput = Schema.Struct({
|
|
37
|
+
repositories: Schema.Array(SetRepository).check(Schema.isMinLength(1)).annotate({
|
|
38
|
+
description: 'The repositories to release together, each once; Kitman names them when release.due starts the Run.'
|
|
39
|
+
}),
|
|
40
|
+
order: Schema.optional(Schema.Array(Schema.String)).annotate({
|
|
41
|
+
description:
|
|
42
|
+
'The order repositories are tagged and deployed in, by repoBindingId or name; those it leaves out follow in the order given, and a name of no listed repository is skipped, so a Project-wide order fits a set that shipped in only some of them.'
|
|
43
|
+
}),
|
|
44
|
+
together: Schema.optional(Schema.Boolean).annotate({
|
|
45
|
+
description:
|
|
46
|
+
"Set as a Project's Input Default: Kitman then records one release.due for all its repositories, which starts this Loop, in place of one each, which starts Release."
|
|
47
|
+
}),
|
|
48
|
+
releaseScope: Schema.optional(ReleaseScope).annotate({
|
|
49
|
+
description: 'The Milestone or Project whose completion started this release, and every Task it ships.'
|
|
50
|
+
})
|
|
51
|
+
}).check(Schema.makeFilter(setProblem))
|
|
52
|
+
|
|
53
|
+
type Input = typeof ReleaseSetInput.Type
|
|
54
|
+
|
|
55
|
+
/** How each repository's Release ended, or that it was not started. */
|
|
56
|
+
const RepositoryResult = Schema.Struct({
|
|
57
|
+
repoBindingId: Schema.String,
|
|
58
|
+
repository: Schema.optionalKey(Schema.String),
|
|
59
|
+
status: Schema.String.annotate({
|
|
60
|
+
description: "Its Release's status, failed when its Release failed, or not_started."
|
|
61
|
+
}),
|
|
62
|
+
reason: Schema.String,
|
|
63
|
+
tag: Schema.optionalKey(Schema.String),
|
|
64
|
+
tagged: Schema.Union([Schema.Boolean, Schema.Literal('unknown')]).annotate({
|
|
65
|
+
description: 'unknown when its Release failed, which may have been after it tagged.'
|
|
66
|
+
}),
|
|
67
|
+
deployed: Schema.Boolean
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
type RepositoryResult = typeof RepositoryResult.Type
|
|
71
|
+
|
|
72
|
+
export const ReleaseSetOutput = Schema.Struct({
|
|
73
|
+
status: Schema.Literals([
|
|
74
|
+
/** Every repository tagged and released. */
|
|
75
|
+
'released',
|
|
76
|
+
/** A repository's gate failed: nothing was tagged anywhere. */
|
|
77
|
+
'gate_failed',
|
|
78
|
+
/** A repository's Release cut no version or ended before its notes: nothing was tagged anywhere. */
|
|
79
|
+
'not_drafted',
|
|
80
|
+
'rejected',
|
|
81
|
+
/** The first repository's Release ended without tagging: nothing was tagged anywhere. */
|
|
82
|
+
'not_released',
|
|
83
|
+
/** Some repositories tagged and others did not, a deploy failed after tagging, or a Release failed that may have tagged; none was undone. */
|
|
84
|
+
'partly_released'
|
|
85
|
+
]).annotate({ description: 'released, gate_failed, not_drafted, rejected, not_released or partly_released.' }),
|
|
86
|
+
reason: Schema.String.annotate({
|
|
87
|
+
description: 'Which repositories tagged and deployed and which did not, or why none did.'
|
|
88
|
+
}),
|
|
89
|
+
repositories: Schema.Array(RepositoryResult).annotate({
|
|
90
|
+
description: 'Each repository in the order it was tagged and deployed: whether it tagged, and whether it deployed.'
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
type Output = typeof ReleaseSetOutput.Type
|
|
95
|
+
|
|
96
|
+
/** Release's Output, as this Loop reads it. */
|
|
97
|
+
const ReleaseEnd = Schema.Struct({
|
|
98
|
+
status: Schema.String,
|
|
99
|
+
reason: Schema.String,
|
|
100
|
+
tag: Schema.optionalKey(Schema.String),
|
|
101
|
+
drafted: Schema.optionalKey(ReleaseDraft)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
type ReleaseEnd = typeof ReleaseEnd.Type
|
|
105
|
+
|
|
106
|
+
/** A Release Child Run that failed, rather than ending with a status, as this Loop records it. */
|
|
107
|
+
const failedStatus = 'failed'
|
|
108
|
+
|
|
109
|
+
/** A Release that failed outright: the set records it, and what it may have tagged, rather than failing with it. */
|
|
110
|
+
const failedRelease = (failure: ChildFailed | StepFailed) =>
|
|
111
|
+
Effect.succeed<ReleaseEnd>({ status: failedStatus, reason: failure.reason })
|
|
112
|
+
|
|
113
|
+
/** A Release's ends that left a tag published. */
|
|
114
|
+
const taggedStatuses = new Set([
|
|
115
|
+
'deployed',
|
|
116
|
+
'published',
|
|
117
|
+
'rolled_back',
|
|
118
|
+
'deploy_failed',
|
|
119
|
+
'rollback_failed',
|
|
120
|
+
'timed_out',
|
|
121
|
+
'not_deployed'
|
|
122
|
+
])
|
|
123
|
+
|
|
124
|
+
const releasedStatuses = new Set(['deployed', 'published'])
|
|
125
|
+
|
|
126
|
+
const nameOf = (repository: SetRepository) => repository.repository ?? repository.repoBindingId
|
|
127
|
+
|
|
128
|
+
/** The repositories in the order `order` names them, the rest after in the order given. */
|
|
129
|
+
export const ordered = (repositories: readonly SetRepository[], order: readonly string[] = []) => {
|
|
130
|
+
const rank = (repository: SetRepository) => {
|
|
131
|
+
const at = order.findIndex(name => name === repository.repoBindingId || name === repository.repository)
|
|
132
|
+
|
|
133
|
+
return at === -1 ? order.length : at
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return repositories
|
|
137
|
+
.map((repository, index) => ({ repository, index }))
|
|
138
|
+
.toSorted((left, right) => rank(left.repository) - rank(right.repository) || left.index - right.index)
|
|
139
|
+
.map(({ repository }) => repository)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const releaseInput = (repository: SetRepository) => ({
|
|
143
|
+
repoBindingId: repository.repoBindingId,
|
|
144
|
+
...(repository.releaseScope === undefined ? undefined : { releaseScope: repository.releaseScope }),
|
|
145
|
+
...(repository.closesProject === undefined ? undefined : { closesProject: repository.closesProject }),
|
|
146
|
+
...(repository.reopened === undefined ? undefined : { reopened: repository.reopened }),
|
|
147
|
+
...(repository.branch === undefined ? undefined : { branch: repository.branch })
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const ended = (release: {
|
|
151
|
+
readonly status: string
|
|
152
|
+
readonly reason: string
|
|
153
|
+
readonly tag?: string | undefined
|
|
154
|
+
readonly drafted?: ReleaseDraft | undefined
|
|
155
|
+
}): ReleaseEnd => ({
|
|
156
|
+
status: release.status,
|
|
157
|
+
reason: release.reason,
|
|
158
|
+
...(release.tag === undefined ? undefined : { tag: release.tag }),
|
|
159
|
+
...(release.drafted === undefined ? undefined : { drafted: release.drafted })
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
/** Gates, cuts and drafts one repository's release with Release as a Child Run, tagging nothing. */
|
|
163
|
+
export const setDrafted = step('setDrafted', {
|
|
164
|
+
payload: { repository: SetRepository },
|
|
165
|
+
success: ReleaseEnd,
|
|
166
|
+
key: ({ repository }) => repository.repoBindingId,
|
|
167
|
+
run: ({ repository }) =>
|
|
168
|
+
call('release', releaseLoop, { ...releaseInput(repository), stopAfter: 'notes' }).pipe(
|
|
169
|
+
Effect.map(ended),
|
|
170
|
+
Effect.catchTags({ ChildFailed: failedRelease, StepFailed: failedRelease })
|
|
171
|
+
)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
/** Goes on from `approve` in one repository's Release, with the notes this Run approved. */
|
|
175
|
+
export const setReleased = step('setReleased', {
|
|
176
|
+
payload: { repository: SetRepository, draft: ReleaseDraft },
|
|
177
|
+
success: ReleaseEnd,
|
|
178
|
+
key: ({ repository }) => repository.repoBindingId,
|
|
179
|
+
run: ({ repository, draft }) =>
|
|
180
|
+
call('release', releaseLoop, { ...releaseInput(repository), drafted: draft, approvedByCaller: true }).pipe(
|
|
181
|
+
Effect.map(ended),
|
|
182
|
+
Effect.catchTags({ ChildFailed: failedRelease, StepFailed: failedRelease })
|
|
183
|
+
)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const approval = ['Approve', 'Reject'] as const
|
|
187
|
+
|
|
188
|
+
/** The one Question for the whole set, with every repository's notes; a full-auto Team answers Approve. */
|
|
189
|
+
export const setApproved = step('setApproved', {
|
|
190
|
+
payload: {
|
|
191
|
+
drafts: Schema.Array(
|
|
192
|
+
Schema.Struct({
|
|
193
|
+
name: Schema.String,
|
|
194
|
+
tag: Schema.String,
|
|
195
|
+
lands: Schema.optional(Schema.String),
|
|
196
|
+
notes: Schema.String
|
|
197
|
+
})
|
|
198
|
+
)
|
|
199
|
+
},
|
|
200
|
+
success: Schema.Literals(approval),
|
|
201
|
+
run: ({ drafts }) =>
|
|
202
|
+
ask('ask', {
|
|
203
|
+
prompt: [
|
|
204
|
+
`Release these ${drafts.length} repositories together, tagging and deploying them in this order? Every gate passed.`,
|
|
205
|
+
...drafts.map(
|
|
206
|
+
(draft, index) =>
|
|
207
|
+
`## ${index + 1}. ${draft.name}: ${draft.tag}${draft.lands === undefined ? '' : ` (lands ${draft.lands} first)`}\n\n${draft.notes}`
|
|
208
|
+
)
|
|
209
|
+
].join('\n\n'),
|
|
210
|
+
options: [
|
|
211
|
+
{ value: 'Approve', description: 'Tags and deploys each repository in turn.' },
|
|
212
|
+
{ value: 'Reject', description: 'Releases none of them.' }
|
|
213
|
+
] satisfies { readonly value: (typeof approval)[number]; readonly description: string }[],
|
|
214
|
+
recommended: 'Approve',
|
|
215
|
+
recommendationReason: "Every repository's checks pass.",
|
|
216
|
+
default: null,
|
|
217
|
+
// A full-auto Team has handed releasing a proved change to Kitman.
|
|
218
|
+
auto: 'Approve'
|
|
219
|
+
}).pipe(Effect.map(answer => (answer === 'Approve' ? 'Approve' : 'Reject')))
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
const resultOf = (repository: SetRepository, release: ReleaseEnd): RepositoryResult => ({
|
|
223
|
+
repoBindingId: repository.repoBindingId,
|
|
224
|
+
...(repository.repository === undefined ? undefined : { repository: repository.repository }),
|
|
225
|
+
status: release.status,
|
|
226
|
+
reason: release.reason,
|
|
227
|
+
...(release.tag === undefined ? undefined : { tag: release.tag }),
|
|
228
|
+
tagged: release.status === failedStatus ? 'unknown' : taggedStatuses.has(release.status),
|
|
229
|
+
deployed: release.status === 'deployed'
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
const untagged = (repository: SetRepository, status: string, reason: string): RepositoryResult => ({
|
|
233
|
+
repoBindingId: repository.repoBindingId,
|
|
234
|
+
...(repository.repository === undefined ? undefined : { repository: repository.repository }),
|
|
235
|
+
status,
|
|
236
|
+
reason,
|
|
237
|
+
tagged: false,
|
|
238
|
+
deployed: false
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const listed = (results: readonly RepositoryResult[], keep: (result: RepositoryResult) => boolean) =>
|
|
242
|
+
results.flatMap(result =>
|
|
243
|
+
keep(result)
|
|
244
|
+
? [`${result.repository ?? result.repoBindingId}${result.tag === undefined ? '' : ` ${result.tag}`}`]
|
|
245
|
+
: []
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
/** What tagged and deployed, and what did not, in a line. */
|
|
249
|
+
const settledWords = (results: readonly RepositoryResult[]) => {
|
|
250
|
+
const deployed = listed(results, result => result.deployed)
|
|
251
|
+
const taggedOnly = listed(results, result => result.tagged === true && !result.deployed)
|
|
252
|
+
const mayHaveTagged = listed(results, result => result.tagged === 'unknown')
|
|
253
|
+
const notTagged = listed(results, result => result.tagged === false)
|
|
254
|
+
|
|
255
|
+
return [
|
|
256
|
+
...(deployed.length === 0 ? [] : [`tagged and deployed: ${deployed.join(', ')}`]),
|
|
257
|
+
...(taggedOnly.length === 0 ? [] : [`tagged, not deployed: ${taggedOnly.join(', ')}`]),
|
|
258
|
+
...(mayHaveTagged.length === 0 ? [] : [`Release failed, may have tagged: ${mayHaveTagged.join(', ')}`]),
|
|
259
|
+
...(notTagged.length === 0 ? [] : [`not tagged: ${notTagged.join(', ')}`])
|
|
260
|
+
].join('; ')
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Releases a closed Milestone's or Project's repositories together: each one's Release gates, cuts and drafts its notes
|
|
265
|
+
* side by side, tagging nothing; one Question asks with every repository's notes; and only when every gate passed and
|
|
266
|
+
* it is approved does each Release go on to tag and deploy, one at a time in `order`. Tags across repositories are
|
|
267
|
+
* never atomic: a failure after the first tag undoes nothing, and the Output says which repositories tagged and deployed.
|
|
268
|
+
*/
|
|
269
|
+
const releaseSet = defineLoop({
|
|
270
|
+
id: 'release-set',
|
|
271
|
+
version: '1.0.0',
|
|
272
|
+
title: 'Release set',
|
|
273
|
+
description: "Releases a Milestone's or Project's repositories together, tagging none until every gate passes.",
|
|
274
|
+
input: ReleaseSetInput,
|
|
275
|
+
output: ReleaseSetOutput,
|
|
276
|
+
agents: {},
|
|
277
|
+
checkout: 'none',
|
|
278
|
+
// Kitman records one release.due for all of a Project's repositories when its Input Default sets `together`.
|
|
279
|
+
when: [
|
|
280
|
+
{
|
|
281
|
+
event: 'release.due',
|
|
282
|
+
filter: { releaseSet: true },
|
|
283
|
+
input: { repositories: 'repositories', releaseScope: 'releaseScope' }
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
capabilities: ['ask', 'call'],
|
|
287
|
+
calls: (): readonly CalledLoop[] => [releaseLoop],
|
|
288
|
+
run: (input: Input) =>
|
|
289
|
+
Effect.gen(function* () {
|
|
290
|
+
const repositories = ordered(input.repositories, input.order)
|
|
291
|
+
|
|
292
|
+
const drafts = yield* Effect.forEach(
|
|
293
|
+
repositories,
|
|
294
|
+
repository => Effect.map(setDrafted({ repository }), (release: ReleaseEnd) => ({ repository, release })),
|
|
295
|
+
{ concurrency: 'unbounded' }
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
const stopped = drafts.filter(({ release }) => release.status !== 'drafted' || release.drafted === undefined)
|
|
299
|
+
|
|
300
|
+
if (stopped.length > 0) {
|
|
301
|
+
const results = drafts.map(({ repository, release }) =>
|
|
302
|
+
release.status === 'drafted'
|
|
303
|
+
? untagged(repository, 'not_started', 'Drafted; not tagged, as another repository stopped')
|
|
304
|
+
: untagged(repository, release.status, release.reason)
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
const why = stopped.map(
|
|
308
|
+
({ repository, release }) => `${nameOf(repository)} ended ${release.status}: ${release.reason}`
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
return {
|
|
312
|
+
status: stopped.some(({ release }) => release.status === 'gate_failed') ? 'gate_failed' : 'not_drafted',
|
|
313
|
+
reason: `Nothing was tagged in any repository: ${why.join('; ')}`,
|
|
314
|
+
repositories: results
|
|
315
|
+
} satisfies Output
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const ready = drafts.flatMap(({ repository, release }) =>
|
|
319
|
+
release.drafted === undefined ? [] : [{ repository, draft: release.drafted }]
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
const answer = yield* setApproved({
|
|
323
|
+
drafts: ready.map(({ repository, draft }) => ({
|
|
324
|
+
name: nameOf(repository),
|
|
325
|
+
tag: draft.tag,
|
|
326
|
+
...(draft.lands === undefined ? undefined : { lands: `${draft.lands.source} into ${draft.lands.target}` }),
|
|
327
|
+
notes: draft.notes
|
|
328
|
+
}))
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
if (answer === 'Reject')
|
|
332
|
+
return {
|
|
333
|
+
status: 'rejected',
|
|
334
|
+
reason: 'The release was rejected: nothing was tagged in any repository',
|
|
335
|
+
repositories: ready.map(({ repository }) => untagged(repository, 'rejected', 'Rejected with the set'))
|
|
336
|
+
} satisfies Output
|
|
337
|
+
|
|
338
|
+
const results: RepositoryResult[] = []
|
|
339
|
+
|
|
340
|
+
for (const { repository, draft } of ready) {
|
|
341
|
+
const stoppedAt = results.find(result => !releasedStatuses.has(result.status))
|
|
342
|
+
|
|
343
|
+
if (stoppedAt !== undefined) {
|
|
344
|
+
results.push(
|
|
345
|
+
untagged(
|
|
346
|
+
repository,
|
|
347
|
+
'not_started',
|
|
348
|
+
`Not started, as ${stoppedAt.repository ?? stoppedAt.repoBindingId} before it ended ${stoppedAt.status}`
|
|
349
|
+
)
|
|
350
|
+
)
|
|
351
|
+
continue
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const second: ReleaseEnd = yield* setReleased({ repository, draft })
|
|
355
|
+
|
|
356
|
+
results.push(resultOf(repository, second))
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const allReleased = results.every(result => releasedStatuses.has(result.status))
|
|
360
|
+
const anyTagged = results.some(result => result.tagged !== false)
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
status: allReleased ? 'released' : anyTagged ? 'partly_released' : 'not_released',
|
|
364
|
+
reason: settledWords(results),
|
|
365
|
+
repositories: results
|
|
366
|
+
} satisfies Output
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
export default releaseSet
|