@kitman-sh/software-engineering 0.11.0-rc.4 → 0.11.0-rc.6
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/dist/bundle.js +102 -67
- package/dist/declarations.json +25 -4
- package/package.json +3 -3
- package/src/release.ts +159 -66
- package/src/shepherd.ts +1 -1
package/dist/bundle.js
CHANGED
|
@@ -21222,7 +21222,9 @@ var Input2 = Struct({
|
|
|
21222
21222
|
repoBindingId: optional2(String5),
|
|
21223
21223
|
releaseTrigger: optional2(ReleaseTrigger),
|
|
21224
21224
|
releaseWhen: optional2(ResolvedReleaseTrigger),
|
|
21225
|
-
releaseScope: optional2(ReleaseScope)
|
|
21225
|
+
releaseScope: optional2(ReleaseScope),
|
|
21226
|
+
version: optional2(String5),
|
|
21227
|
+
candidate: optional2(Boolean3)
|
|
21226
21228
|
});
|
|
21227
21229
|
var Drafted = Struct({
|
|
21228
21230
|
tag: String5,
|
|
@@ -21286,16 +21288,33 @@ var scopePrompt2 = (scope) => scope === undefined ? [] : [
|
|
|
21286
21288
|
scope.tasks.map((task) => `- ${task.key} ${task.title}`).join(`
|
|
21287
21289
|
`)
|
|
21288
21290
|
];
|
|
21289
|
-
var
|
|
21291
|
+
var nextCandidateWords = (version) => `the next release candidate of ${version} after the latest the repository has: one past the highest N of any ${version}-rc.N tag, or ${version}-rc.1 when there is none`;
|
|
21292
|
+
var tagWords = (tag, cut) => {
|
|
21293
|
+
if (cut?.candidate === true)
|
|
21294
|
+
return `The release is a release candidate of ${cut.version}, numbered again once it is tagged. Give as tag ${nextCandidateWords(cut.version)}.`;
|
|
21295
|
+
const given = tag ?? cut?.version;
|
|
21296
|
+
return given === undefined ? "Propose the next version tag, following the scheme earlier tags use. With no earlier tag, propose v0.1.0 and say so in the notes." : `The release is tagged ${given}.`;
|
|
21297
|
+
};
|
|
21298
|
+
var draftPrompt = (tag, cut, changeRequestId, scope) => [
|
|
21299
|
+
"Fetch the base branch and tags first (`git fetch origin --tags`).",
|
|
21290
21300
|
"Draft the release notes for the ChangeRequests merged since the last release tag on the base branch, including those with no linked Task.",
|
|
21291
21301
|
...scopePrompt2(scope),
|
|
21292
21302
|
...changeRequestId === undefined ? [] : [`The release ChangeRequest ${changeRequestId} is part of it.`],
|
|
21293
21303
|
"Group them by what a user of the software notices, and name each ChangeRequest you cover.",
|
|
21294
|
-
tag
|
|
21304
|
+
tagWords(tag, cut),
|
|
21295
21305
|
"Give the latest earlier release tag as previousTag, or leave it out when there is none."
|
|
21296
21306
|
].join(`
|
|
21297
21307
|
|
|
21298
21308
|
`);
|
|
21309
|
+
var regexSpecial = /[.*+?^$()|[\]{}\\]/g;
|
|
21310
|
+
var escaped = (text) => text.replaceAll(regexSpecial, "\\$&");
|
|
21311
|
+
var candidateNumber = (tag, version) => {
|
|
21312
|
+
const [, number] = new RegExp(`^${escaped(version)}-rc\\.(\\d+)$`).exec(tag) ?? [];
|
|
21313
|
+
return number === undefined ? undefined : Number(number);
|
|
21314
|
+
};
|
|
21315
|
+
var renameTag = (text, taken, tag) => text.replaceAll(new RegExp(`${escaped(taken)}(?!\\d)`, "g"), tag);
|
|
21316
|
+
var isTagElsewhere = (failed) => failed.reason.includes("TAG_ELSEWHERE");
|
|
21317
|
+
var isReleasedByOther = (failed) => failed.reason.includes("TAG_RELEASED");
|
|
21299
21318
|
var redraftPrompt = (drafted, edit) => [
|
|
21300
21319
|
"Redraft these release notes as asked, keeping the tag and everything not mentioned.",
|
|
21301
21320
|
`Asked: ${edit}`,
|
|
@@ -21305,19 +21324,26 @@ var redraftPrompt = (drafted, edit) => [
|
|
|
21305
21324
|
].join(`
|
|
21306
21325
|
|
|
21307
21326
|
`);
|
|
21308
|
-
var
|
|
21327
|
+
var pickInstructions = (drafted, revision, givenTag, cut) => {
|
|
21328
|
+
if (cut !== undefined)
|
|
21329
|
+
return [
|
|
21330
|
+
`Fetch the tags (\`git fetch origin --tags\`). ${cut.candidate ? `Give as tag ${nextCandidateWords(cut.version)}, naming it in the title and notes where they name ${drafted.tag}, and` : `The release is tagged ${cut.version}: give the draft unchanged but for`} the latest release tag as previousTag. It is released even when another tag already contains ${revision}: leave releasedIn out.`
|
|
21331
|
+
];
|
|
21309
21332
|
const ownTag = givenTag ?? drafted.tag;
|
|
21310
21333
|
return [
|
|
21311
|
-
"This Release now holds the deploy target, so no other Release tags until it settles. Another Release may have tagged since these notes were drafted: pick their version again.",
|
|
21312
21334
|
`Fetch the tags (\`git fetch origin --tags\`) and list the release tags that contain ${revision} (\`git tag --contains ${revision}\`). ${ownTag} at ${revision} itself, as \`git rev-list -n 1 ${ownTag}\` tells, is this Release tagged on an earlier attempt: ignore it. Any other, ${ownTag} at another commit included, means ${revision} is released already: give that tag as releasedIn and the draft unchanged.`,
|
|
21313
|
-
givenTag === undefined ? `Otherwise, when ${drafted.tag} is still free and the latest release tag is still ${drafted.previousTag ?? "none"}, give the draft unchanged. When not, give the next version tag after the latest release tag, that latest tag as previousTag, and drop from the notes and changeRequests what it already released.` : `Otherwise give the draft unchanged. The release is tagged ${givenTag}
|
|
21314
|
-
|
|
21315
|
-
|
|
21316
|
-
|
|
21317
|
-
|
|
21335
|
+
givenTag === undefined ? `Otherwise, when ${drafted.tag} is still free and the latest release tag is still ${drafted.previousTag ?? "none"}, give the draft unchanged. When not, give the next version tag after the latest release tag, that latest tag as previousTag, and drop from the notes and changeRequests what it already released.` : `Otherwise give the draft unchanged. The release is tagged ${givenTag}.`
|
|
21336
|
+
];
|
|
21337
|
+
};
|
|
21338
|
+
var pickPrompt = (drafted, revision, givenTag, cut) => [
|
|
21339
|
+
"This Release now holds the deploy target, so no other Release tags until it settles. Another Release may have tagged since these notes were drafted: pick their version again.",
|
|
21340
|
+
...pickInstructions(drafted, revision, givenTag, cut),
|
|
21341
|
+
"```json",
|
|
21342
|
+
JSON.stringify(drafted, null, 2),
|
|
21343
|
+
"```"
|
|
21344
|
+
].join(`
|
|
21318
21345
|
|
|
21319
21346
|
`);
|
|
21320
|
-
};
|
|
21321
21347
|
var readyToMerge = (changeRequestId, round = 1) => gen2(function* () {
|
|
21322
21348
|
for (let pass = 1;; pass++) {
|
|
21323
21349
|
const at = (name) => {
|
|
@@ -21377,7 +21403,7 @@ var readyToMerge = (changeRequestId, round = 1) => gen2(function* () {
|
|
|
21377
21403
|
var recovery = (previous) => previous === undefined ? ["Retry the deploy", "Leave it"] : ["Retry the deploy", `Roll back to ${previous}`, "Leave it"];
|
|
21378
21404
|
var release_default = defineLoop({
|
|
21379
21405
|
id: "release",
|
|
21380
|
-
version: "2.
|
|
21406
|
+
version: "2.3.0",
|
|
21381
21407
|
title: "Release",
|
|
21382
21408
|
input: Input2,
|
|
21383
21409
|
output: Output2,
|
|
@@ -21387,7 +21413,8 @@ var release_default = defineLoop({
|
|
|
21387
21413
|
{
|
|
21388
21414
|
event: "release.due",
|
|
21389
21415
|
input: {
|
|
21390
|
-
|
|
21416
|
+
version: "version",
|
|
21417
|
+
candidate: "candidate",
|
|
21391
21418
|
releaseScope: "releaseScope",
|
|
21392
21419
|
releaseWhen: "releaseWhen",
|
|
21393
21420
|
repoBindingId: "repoBindingId"
|
|
@@ -21410,7 +21437,7 @@ var release_default = defineLoop({
|
|
|
21410
21437
|
status: "not_due",
|
|
21411
21438
|
reason: `Release runs when ${triggerWords[when.trigger]}, as ${layerWords[when.layer]} says; this Run did not override that`
|
|
21412
21439
|
};
|
|
21413
|
-
if (input.releaseScope !== undefined && input.tag === undefined)
|
|
21440
|
+
if (input.releaseScope !== undefined && input.tag === undefined && input.version === undefined)
|
|
21414
21441
|
return {
|
|
21415
21442
|
status: "no_version",
|
|
21416
21443
|
reason: "Kitman cut no version for this Milestone or Project: its Project is not named by a full semver version. Release it with a tag.",
|
|
@@ -21462,15 +21489,33 @@ var release_default = defineLoop({
|
|
|
21462
21489
|
return ready;
|
|
21463
21490
|
gated = ready.passed;
|
|
21464
21491
|
}
|
|
21492
|
+
const cut = input.tag === undefined && input.version !== undefined ? { version: input.version, candidate: input.candidate === true } : undefined;
|
|
21493
|
+
const tagOf = (proposed, fallback) => {
|
|
21494
|
+
if (cut === undefined)
|
|
21495
|
+
return input.tag ?? proposed;
|
|
21496
|
+
if (!cut.candidate)
|
|
21497
|
+
return cut.version;
|
|
21498
|
+
return candidateNumber(proposed, cut.version) === undefined ? fallback : proposed;
|
|
21499
|
+
};
|
|
21465
21500
|
let drafted = yield* agentWork("draft-notes", {
|
|
21466
21501
|
agent: "releaser",
|
|
21467
|
-
prompt: draftPrompt(input.tag, changeRequestId, input.releaseScope),
|
|
21502
|
+
prompt: draftPrompt(input.tag, cut, changeRequestId, input.releaseScope),
|
|
21468
21503
|
output: Drafted
|
|
21469
21504
|
});
|
|
21470
|
-
let tag =
|
|
21505
|
+
let tag = tagOf(drafted.tag, cut === undefined ? drafted.tag : `${cut.version}-rc.1`);
|
|
21506
|
+
const recordNotes = (step) => artifact(step, {
|
|
21507
|
+
kind: "release_notes",
|
|
21508
|
+
title: drafted.title,
|
|
21509
|
+
text: drafted.notes,
|
|
21510
|
+
data: {
|
|
21511
|
+
tag,
|
|
21512
|
+
changeRequests: drafted.changeRequests,
|
|
21513
|
+
...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
|
|
21514
|
+
}
|
|
21515
|
+
});
|
|
21471
21516
|
for (let round = 1;; round++) {
|
|
21472
21517
|
const answer = yield* ask(round === 1 ? "approve" : `approve:${round}`, {
|
|
21473
|
-
prompt: `Release ${tag} with these notes?
|
|
21518
|
+
prompt: `Release ${cut?.candidate === true ? `${tag}, or the next release candidate of ${cut.version} still free when it is tagged,` : tag} with these notes?
|
|
21474
21519
|
|
|
21475
21520
|
${drafted.notes}`,
|
|
21476
21521
|
options: [
|
|
@@ -21494,16 +21539,7 @@ ${drafted.notes}`,
|
|
|
21494
21539
|
default: "No reason given",
|
|
21495
21540
|
timeout: "1 day"
|
|
21496
21541
|
});
|
|
21497
|
-
const kept = yield*
|
|
21498
|
-
kind: "release_notes",
|
|
21499
|
-
title: drafted.title,
|
|
21500
|
-
text: drafted.notes,
|
|
21501
|
-
data: {
|
|
21502
|
-
tag,
|
|
21503
|
-
changeRequests: drafted.changeRequests,
|
|
21504
|
-
...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
|
|
21505
|
-
}
|
|
21506
|
-
});
|
|
21542
|
+
const kept = yield* recordNotes("notes");
|
|
21507
21543
|
return { status: "rejected", reason: why, tag, notesArtifactId: kept.artifactId };
|
|
21508
21544
|
}
|
|
21509
21545
|
const edit = yield* ask(`edit:${round}`, {
|
|
@@ -21522,16 +21558,7 @@ ${drafted.notes}`,
|
|
|
21522
21558
|
output: Drafted
|
|
21523
21559
|
});
|
|
21524
21560
|
}
|
|
21525
|
-
let notes = yield*
|
|
21526
|
-
kind: "release_notes",
|
|
21527
|
-
title: drafted.title,
|
|
21528
|
-
text: drafted.notes,
|
|
21529
|
-
data: {
|
|
21530
|
-
tag,
|
|
21531
|
-
changeRequests: drafted.changeRequests,
|
|
21532
|
-
...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
|
|
21533
|
-
}
|
|
21534
|
-
});
|
|
21561
|
+
let notes = yield* recordNotes("notes");
|
|
21535
21562
|
let revision = gated;
|
|
21536
21563
|
if (changeRequestId !== undefined) {
|
|
21537
21564
|
for (let round = 1;; round++) {
|
|
@@ -21567,38 +21594,46 @@ ${drafted.notes}`,
|
|
|
21567
21594
|
yield* claim("deploy-target", { resource: `deploy:${input.deployTarget ?? deployEvent}`, takeOverOwnLoop: true });
|
|
21568
21595
|
const { releasedIn, ...picked } = yield* agentWork("pick-version", {
|
|
21569
21596
|
agent: "releaser",
|
|
21570
|
-
prompt: pickPrompt({ ...drafted, tag }, revision, input.tag),
|
|
21597
|
+
prompt: pickPrompt({ ...drafted, tag }, revision, input.tag, cut),
|
|
21571
21598
|
output: Picked
|
|
21572
21599
|
});
|
|
21573
|
-
|
|
21574
|
-
|
|
21575
|
-
|
|
21576
|
-
|
|
21577
|
-
|
|
21578
|
-
|
|
21579
|
-
|
|
21600
|
+
const alreadyReleased = (released, reason) => ({
|
|
21601
|
+
status: "nothing_to_release",
|
|
21602
|
+
reason,
|
|
21603
|
+
tag: released,
|
|
21604
|
+
notesArtifactId: notes.artifactId,
|
|
21605
|
+
revision
|
|
21606
|
+
});
|
|
21607
|
+
if (cut === undefined && releasedIn !== undefined)
|
|
21608
|
+
return alreadyReleased(releasedIn, `${revision} is already released in ${releasedIn}`);
|
|
21609
|
+
const pickedTag = tagOf(picked.tag, tag);
|
|
21610
|
+
const repicked = cut === undefined ? picked : {
|
|
21611
|
+
...picked,
|
|
21612
|
+
title: renameTag(picked.title, tag, pickedTag),
|
|
21613
|
+
notes: renameTag(picked.notes, tag, pickedTag)
|
|
21614
|
+
};
|
|
21615
|
+
const changed = pickedTag !== tag || repicked.notes !== drafted.notes || repicked.title !== drafted.title;
|
|
21616
|
+
drafted = repicked;
|
|
21617
|
+
tag = pickedTag;
|
|
21618
|
+
if (changed)
|
|
21619
|
+
notes = yield* recordNotes("notes:picked");
|
|
21620
|
+
const publish = (step) => release2(step, { tag, revision, title: drafted.title, notes: drafted.notes }).pipe(catchTag2("StepFailed", (failed) => isTagElsewhere(failed) || isReleasedByOther(failed) ? succeed7(failed) : fail7(failed)));
|
|
21621
|
+
const approved = { tag, title: drafted.title, notes: drafted.notes };
|
|
21622
|
+
let released = yield* publish("tag");
|
|
21623
|
+
if (released instanceof StepFailed && cut === undefined && isReleasedByOther(released))
|
|
21624
|
+
return alreadyReleased(tag, `${tag} is already released at ${revision} by another Run`);
|
|
21625
|
+
for (let round = 2;released instanceof StepFailed; round++) {
|
|
21626
|
+
if (cut?.candidate !== true || round > 20)
|
|
21627
|
+
return yield* released;
|
|
21628
|
+
tag = `${cut.version}-rc.${(candidateNumber(tag, cut.version) ?? 0) + 1}`;
|
|
21629
|
+
drafted = {
|
|
21630
|
+
...drafted,
|
|
21631
|
+
title: renameTag(approved.title, approved.tag, tag),
|
|
21632
|
+
notes: renameTag(approved.notes, approved.tag, tag)
|
|
21580
21633
|
};
|
|
21581
|
-
|
|
21582
|
-
|
|
21583
|
-
notes = yield* artifact("notes:picked", {
|
|
21584
|
-
kind: "release_notes",
|
|
21585
|
-
title: picked.title,
|
|
21586
|
-
text: picked.notes,
|
|
21587
|
-
data: {
|
|
21588
|
-
tag: pickedTag,
|
|
21589
|
-
changeRequests: picked.changeRequests,
|
|
21590
|
-
...input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) }
|
|
21591
|
-
}
|
|
21592
|
-
});
|
|
21634
|
+
notes = yield* recordNotes(`notes:${round}`);
|
|
21635
|
+
released = yield* publish(`tag:${round}`);
|
|
21593
21636
|
}
|
|
21594
|
-
drafted = picked;
|
|
21595
|
-
tag = pickedTag;
|
|
21596
|
-
const released = yield* release2("tag", {
|
|
21597
|
-
tag,
|
|
21598
|
-
revision,
|
|
21599
|
-
title: drafted.title,
|
|
21600
|
-
notes: drafted.notes
|
|
21601
|
-
});
|
|
21602
21637
|
const deployed = (step, deployTag) => waitFor(step, {
|
|
21603
21638
|
event: deployEvent,
|
|
21604
21639
|
filter: { tag: deployTag },
|
|
@@ -21774,7 +21809,7 @@ var repliesPrompt = (threads) => [
|
|
|
21774
21809
|
var threadKey = (thread) => `${thread.id}:${thread.comments.length}`;
|
|
21775
21810
|
var shepherd_default = defineLoop({
|
|
21776
21811
|
id: "shepherd",
|
|
21777
|
-
version: "1.6.
|
|
21812
|
+
version: "1.6.1",
|
|
21778
21813
|
title: "Shepherd",
|
|
21779
21814
|
input: Input3,
|
|
21780
21815
|
output: Output3,
|
|
@@ -30605,4 +30640,4 @@ var runKit = (config, identity, packages) => {
|
|
|
30605
30640
|
runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
|
|
30606
30641
|
};
|
|
30607
30642
|
// .kitman-build-entry.ts
|
|
30608
|
-
runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.11.0-rc.
|
|
30643
|
+
runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.11.0-rc.6" }, []);
|
package/dist/declarations.json
CHANGED
|
@@ -1629,7 +1629,7 @@
|
|
|
1629
1629
|
{
|
|
1630
1630
|
"id": "release",
|
|
1631
1631
|
"title": "Release",
|
|
1632
|
-
"version": "2.
|
|
1632
|
+
"version": "2.3.0",
|
|
1633
1633
|
"input": {
|
|
1634
1634
|
"type": "object",
|
|
1635
1635
|
"properties": {
|
|
@@ -1813,6 +1813,26 @@
|
|
|
1813
1813
|
"type": "null"
|
|
1814
1814
|
}
|
|
1815
1815
|
]
|
|
1816
|
+
},
|
|
1817
|
+
"version": {
|
|
1818
|
+
"anyOf": [
|
|
1819
|
+
{
|
|
1820
|
+
"type": "string"
|
|
1821
|
+
},
|
|
1822
|
+
{
|
|
1823
|
+
"type": "null"
|
|
1824
|
+
}
|
|
1825
|
+
]
|
|
1826
|
+
},
|
|
1827
|
+
"candidate": {
|
|
1828
|
+
"anyOf": [
|
|
1829
|
+
{
|
|
1830
|
+
"type": "boolean"
|
|
1831
|
+
},
|
|
1832
|
+
{
|
|
1833
|
+
"type": "null"
|
|
1834
|
+
}
|
|
1835
|
+
]
|
|
1816
1836
|
}
|
|
1817
1837
|
},
|
|
1818
1838
|
"additionalProperties": true,
|
|
@@ -1968,7 +1988,8 @@
|
|
|
1968
1988
|
{
|
|
1969
1989
|
"event": "release.due",
|
|
1970
1990
|
"input": {
|
|
1971
|
-
"
|
|
1991
|
+
"version": "version",
|
|
1992
|
+
"candidate": "candidate",
|
|
1972
1993
|
"releaseScope": "releaseScope",
|
|
1973
1994
|
"releaseWhen": "releaseWhen",
|
|
1974
1995
|
"repoBindingId": "repoBindingId"
|
|
@@ -2942,7 +2963,7 @@
|
|
|
2942
2963
|
{
|
|
2943
2964
|
"id": "shepherd",
|
|
2944
2965
|
"title": "Shepherd",
|
|
2945
|
-
"version": "1.6.
|
|
2966
|
+
"version": "1.6.1",
|
|
2946
2967
|
"input": {
|
|
2947
2968
|
"type": "object",
|
|
2948
2969
|
"properties": {
|
|
@@ -3848,7 +3869,7 @@
|
|
|
3848
3869
|
"carried": [
|
|
3849
3870
|
{
|
|
3850
3871
|
"name": "@kitman-sh/software-engineering",
|
|
3851
|
-
"version": "0.11.0-rc.
|
|
3872
|
+
"version": "0.11.0-rc.6",
|
|
3852
3873
|
"setup": "2a237548a69b0cd53ec3be7f687cfa8c2128335b3a655d34e185f2abce6a3c37",
|
|
3853
3874
|
"loops": [
|
|
3854
3875
|
"build",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitman-sh/software-engineering",
|
|
3
|
-
"version": "0.11.0-rc.
|
|
3
|
+
"version": "0.11.0-rc.6",
|
|
4
4
|
"description": "Everything for building software: Loops, their Agents, the skills they use and the Ponytail plugin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"tsconfig.json"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@kitman-sh/sdk": "0.11.0-rc.
|
|
20
|
+
"@kitman-sh/sdk": "0.11.0-rc.6",
|
|
21
21
|
"effect": "^4.1.2"
|
|
22
22
|
},
|
|
23
23
|
"kitman": {
|
|
24
24
|
"bundle": "dist/bundle.js",
|
|
25
|
-
"digest": "
|
|
25
|
+
"digest": "83ce0a27e6119d8a59eb395c03738a860696e54e0105486592aa6b7abb57de86",
|
|
26
26
|
"protocolVersion": 5,
|
|
27
27
|
"declarations": "dist/declarations.json",
|
|
28
28
|
"setup": {
|
package/src/release.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
rerunPipeline,
|
|
15
15
|
ShippedScope,
|
|
16
16
|
shippedScope,
|
|
17
|
+
StepFailed,
|
|
17
18
|
verify,
|
|
18
19
|
waitFor
|
|
19
20
|
} from '@kitman-sh/sdk/loop'
|
|
@@ -41,7 +42,11 @@ const Input = Schema.Struct({
|
|
|
41
42
|
/** The release trigger the Run uses and the layer it came from; Kitman sets it when the Run starts. */
|
|
42
43
|
releaseWhen: Schema.optional(ResolvedReleaseTrigger),
|
|
43
44
|
/** The Milestone or Project whose completion started this Release, and the Tasks it ships. */
|
|
44
|
-
releaseScope: Schema.optional(ReleaseScope)
|
|
45
|
+
releaseScope: Schema.optional(ReleaseScope),
|
|
46
|
+
/** The Project's version its Milestone or Project releases; Kitman sets it when release.due starts the Run. */
|
|
47
|
+
version: Schema.optional(Schema.String),
|
|
48
|
+
/** Whether it releases the next release candidate of `version`, numbered once it holds the deploy target, or `version`. */
|
|
49
|
+
candidate: Schema.optional(Schema.Boolean)
|
|
45
50
|
})
|
|
46
51
|
|
|
47
52
|
const Drafted = Schema.Struct({
|
|
@@ -95,7 +100,7 @@ const Output = Schema.Struct({
|
|
|
95
100
|
'not_due',
|
|
96
101
|
/** A Milestone or Project started it without the version to cut, which a Release never picks for itself. */
|
|
97
102
|
'no_version',
|
|
98
|
-
/** An existing tag already contains the revision, as when another Release tagged it first. */
|
|
103
|
+
/** An existing tag already contains the revision, as when another Release tagged it first; never for a Milestone or Project. */
|
|
99
104
|
'nothing_to_release'
|
|
100
105
|
]),
|
|
101
106
|
/** Why it stopped, or what happened, in a line. */
|
|
@@ -139,18 +144,59 @@ const scopePrompt = (scope: ReleaseScope | undefined) =>
|
|
|
139
144
|
scope.tasks.map(task => `- ${task.key} ${task.title}`).join('\n')
|
|
140
145
|
]
|
|
141
146
|
|
|
142
|
-
|
|
147
|
+
/** What a Milestone or Project releases of its Project's version: its next release candidate, or the version itself. */
|
|
148
|
+
type Cut = { readonly version: string; readonly candidate: boolean }
|
|
149
|
+
|
|
150
|
+
const nextCandidateWords = (version: string) =>
|
|
151
|
+
`the next release candidate of ${version} after the latest the repository has: one past the highest N of any ${version}-rc.N tag, or ${version}-rc.1 when there is none`
|
|
152
|
+
|
|
153
|
+
const tagWords = (tag: string | undefined, cut: Cut | undefined) => {
|
|
154
|
+
if (cut?.candidate === true)
|
|
155
|
+
return `The release is a release candidate of ${cut.version}, numbered again once it is tagged. Give as tag ${nextCandidateWords(cut.version)}.`
|
|
156
|
+
|
|
157
|
+
const given = tag ?? cut?.version
|
|
158
|
+
|
|
159
|
+
return given === undefined
|
|
160
|
+
? 'Propose the next version tag, following the scheme earlier tags use. With no earlier tag, propose v0.1.0 and say so in the notes.'
|
|
161
|
+
: `The release is tagged ${given}.`
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const draftPrompt = (
|
|
165
|
+
tag: string | undefined,
|
|
166
|
+
cut: Cut | undefined,
|
|
167
|
+
changeRequestId: string | undefined,
|
|
168
|
+
scope?: ReleaseScope
|
|
169
|
+
) =>
|
|
143
170
|
[
|
|
171
|
+
'Fetch the base branch and tags first (`git fetch origin --tags`).',
|
|
144
172
|
'Draft the release notes for the ChangeRequests merged since the last release tag on the base branch, including those with no linked Task.',
|
|
145
173
|
...scopePrompt(scope),
|
|
146
174
|
...(changeRequestId === undefined ? [] : [`The release ChangeRequest ${changeRequestId} is part of it.`]),
|
|
147
175
|
'Group them by what a user of the software notices, and name each ChangeRequest you cover.',
|
|
148
|
-
tag
|
|
149
|
-
? 'Propose the next version tag, following the scheme earlier tags use. With no earlier tag, propose v0.1.0 and say so in the notes.'
|
|
150
|
-
: `The release is tagged ${tag}.`,
|
|
176
|
+
tagWords(tag, cut),
|
|
151
177
|
'Give the latest earlier release tag as previousTag, or leave it out when there is none.'
|
|
152
178
|
].join('\n\n')
|
|
153
179
|
|
|
180
|
+
const regexSpecial = /[.*+?^$()|[\]{}\\]/g
|
|
181
|
+
|
|
182
|
+
const escaped = (text: string) => text.replaceAll(regexSpecial, '\\$&')
|
|
183
|
+
|
|
184
|
+
/** The number of `tag` as a release candidate of `version`; undefined when it is not one. */
|
|
185
|
+
const candidateNumber = (tag: string, version: string) => {
|
|
186
|
+
const [, number] = new RegExp(`^${escaped(version)}-rc\\.(\\d+)$`).exec(tag) ?? []
|
|
187
|
+
|
|
188
|
+
return number === undefined ? undefined : Number(number)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** `text` naming `tag` where it named `taken`; `-rc.1` is not read inside `-rc.10`. */
|
|
192
|
+
const renameTag = (text: string, taken: string, tag: string) =>
|
|
193
|
+
text.replaceAll(new RegExp(`${escaped(taken)}(?!\\d)`, 'g'), tag)
|
|
194
|
+
|
|
195
|
+
const isTagElsewhere = (failed: StepFailed) => failed.reason.includes('TAG_ELSEWHERE')
|
|
196
|
+
|
|
197
|
+
/** Another Run already published the tag at this revision. */
|
|
198
|
+
const isReleasedByOther = (failed: StepFailed) => failed.reason.includes('TAG_RELEASED')
|
|
199
|
+
|
|
154
200
|
const redraftPrompt = (drafted: Drafted, edit: string) =>
|
|
155
201
|
[
|
|
156
202
|
'Redraft these release notes as asked, keeping the tag and everything not mentioned.',
|
|
@@ -160,20 +206,31 @@ const redraftPrompt = (drafted: Drafted, edit: string) =>
|
|
|
160
206
|
'```'
|
|
161
207
|
].join('\n\n')
|
|
162
208
|
|
|
163
|
-
const
|
|
209
|
+
const pickInstructions = (drafted: Drafted, revision: string, givenTag: string | undefined, cut: Cut | undefined) => {
|
|
210
|
+
// A Milestone or Project cuts its own release even at a revision another tag contains, so its Tasks are published.
|
|
211
|
+
if (cut !== undefined)
|
|
212
|
+
return [
|
|
213
|
+
`Fetch the tags (\`git fetch origin --tags\`). ${cut.candidate ? `Give as tag ${nextCandidateWords(cut.version)}, naming it in the title and notes where they name ${drafted.tag}, and` : `The release is tagged ${cut.version}: give the draft unchanged but for`} the latest release tag as previousTag. It is released even when another tag already contains ${revision}: leave releasedIn out.`
|
|
214
|
+
]
|
|
215
|
+
|
|
164
216
|
const ownTag = givenTag ?? drafted.tag
|
|
165
217
|
|
|
166
218
|
return [
|
|
167
|
-
'This Release now holds the deploy target, so no other Release tags until it settles. Another Release may have tagged since these notes were drafted: pick their version again.',
|
|
168
219
|
`Fetch the tags (\`git fetch origin --tags\`) and list the release tags that contain ${revision} (\`git tag --contains ${revision}\`). ${ownTag} at ${revision} itself, as \`git rev-list -n 1 ${ownTag}\` tells, is this Release tagged on an earlier attempt: ignore it. Any other, ${ownTag} at another commit included, means ${revision} is released already: give that tag as releasedIn and the draft unchanged.`,
|
|
169
220
|
givenTag === undefined
|
|
170
221
|
? `Otherwise, when ${drafted.tag} is still free and the latest release tag is still ${drafted.previousTag ?? 'none'}, give the draft unchanged. When not, give the next version tag after the latest release tag, that latest tag as previousTag, and drop from the notes and changeRequests what it already released.`
|
|
171
|
-
: `Otherwise give the draft unchanged. The release is tagged ${givenTag}
|
|
222
|
+
: `Otherwise give the draft unchanged. The release is tagged ${givenTag}.`
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const pickPrompt = (drafted: Drafted, revision: string, givenTag: string | undefined, cut: Cut | undefined) =>
|
|
227
|
+
[
|
|
228
|
+
'This Release now holds the deploy target, so no other Release tags until it settles. Another Release may have tagged since these notes were drafted: pick their version again.',
|
|
229
|
+
...pickInstructions(drafted, revision, givenTag, cut),
|
|
172
230
|
'```json',
|
|
173
231
|
JSON.stringify(drafted, null, 2),
|
|
174
232
|
'```'
|
|
175
233
|
].join('\n\n')
|
|
176
|
-
}
|
|
177
234
|
|
|
178
235
|
const approval = ['Approve', 'Edit notes', 'Reject'] as const
|
|
179
236
|
|
|
@@ -273,18 +330,20 @@ const recovery = (previous: string | undefined) =>
|
|
|
273
330
|
* notes, which can be edited in place. On approval it merges the ChangeRequest when there is one, holds the deploy
|
|
274
331
|
* target so two Releases never tag or deploy over each other, taking it over from a Release that failed holding it,
|
|
275
332
|
* and picks the version again under it: a revision an existing tag already contains ends as nothing to release. It
|
|
276
|
-
* then tags and publishes once (
|
|
277
|
-
* moved) and waits for the deploy. A failed or late deploy asks whether
|
|
333
|
+
* then tags and publishes once (its own release of the tag at the same revision counts as done; one at another is
|
|
334
|
+
* never moved) and waits for the deploy. A failed or late deploy asks whether
|
|
278
335
|
* to retry (it runs the tag's failed pipeline again and waits), roll back to the previous tag (it runs that
|
|
279
336
|
* tag's pipeline again in full and waits for its deploy), or leave it, which it does by default.
|
|
280
337
|
*
|
|
281
338
|
* Under a Milestone or Project release trigger, it releases only when that Milestone's or Project's completion starts
|
|
282
|
-
* it, with the
|
|
283
|
-
*
|
|
339
|
+
* it, with the Project's version and the Tasks it ships, which it records; without a version it stops rather than
|
|
340
|
+
* choose one. A Milestone's release candidate is numbered under the deploy target, after the latest one the repository
|
|
341
|
+
* has, and gives way to the next when the forge finds it taken; the version itself is never moved. Either is released
|
|
342
|
+
* even at a revision another tag contains. A Run whose `releaseTrigger` is `merge` releases anyway.
|
|
284
343
|
*/
|
|
285
344
|
export default defineLoop({
|
|
286
345
|
id: 'release',
|
|
287
|
-
version: '2.
|
|
346
|
+
version: '2.3.0',
|
|
288
347
|
title: 'Release',
|
|
289
348
|
input: Input,
|
|
290
349
|
output: Output,
|
|
@@ -295,7 +354,8 @@ export default defineLoop({
|
|
|
295
354
|
{
|
|
296
355
|
event: 'release.due',
|
|
297
356
|
input: {
|
|
298
|
-
|
|
357
|
+
version: 'version',
|
|
358
|
+
candidate: 'candidate',
|
|
299
359
|
releaseScope: 'releaseScope',
|
|
300
360
|
releaseWhen: 'releaseWhen',
|
|
301
361
|
repoBindingId: 'repoBindingId'
|
|
@@ -322,7 +382,7 @@ export default defineLoop({
|
|
|
322
382
|
reason: `Release runs when ${triggerWords[when.trigger]}, as ${layerWords[when.layer]} says; this Run did not override that`
|
|
323
383
|
} satisfies Output
|
|
324
384
|
|
|
325
|
-
if (input.releaseScope !== undefined && input.tag === undefined)
|
|
385
|
+
if (input.releaseScope !== undefined && input.tag === undefined && input.version === undefined)
|
|
326
386
|
return {
|
|
327
387
|
status: 'no_version',
|
|
328
388
|
reason:
|
|
@@ -392,18 +452,44 @@ export default defineLoop({
|
|
|
392
452
|
gated = ready.passed
|
|
393
453
|
}
|
|
394
454
|
|
|
455
|
+
const cut: Cut | undefined =
|
|
456
|
+
input.tag === undefined && input.version !== undefined
|
|
457
|
+
? { version: input.version, candidate: input.candidate === true }
|
|
458
|
+
: undefined
|
|
459
|
+
|
|
460
|
+
/** The tag to cut: a given one, a Project's version, or a candidate of it the releaser numbered, else `fallback`. */
|
|
461
|
+
const tagOf = (proposed: string, fallback: string) => {
|
|
462
|
+
if (cut === undefined) return input.tag ?? proposed
|
|
463
|
+
|
|
464
|
+
if (!cut.candidate) return cut.version
|
|
465
|
+
|
|
466
|
+
return candidateNumber(proposed, cut.version) === undefined ? fallback : proposed
|
|
467
|
+
}
|
|
468
|
+
|
|
395
469
|
let drafted = yield* agentWork('draft-notes', {
|
|
396
470
|
agent: 'releaser',
|
|
397
|
-
prompt: draftPrompt(input.tag, changeRequestId, input.releaseScope),
|
|
471
|
+
prompt: draftPrompt(input.tag, cut, changeRequestId, input.releaseScope),
|
|
398
472
|
output: Drafted
|
|
399
473
|
})
|
|
400
474
|
|
|
401
|
-
let tag =
|
|
475
|
+
let tag = tagOf(drafted.tag, cut === undefined ? drafted.tag : `${cut.version}-rc.1`)
|
|
476
|
+
|
|
477
|
+
const recordNotes = (step: string) =>
|
|
478
|
+
artifact(step, {
|
|
479
|
+
kind: 'release_notes',
|
|
480
|
+
title: drafted.title,
|
|
481
|
+
text: drafted.notes,
|
|
482
|
+
data: {
|
|
483
|
+
tag,
|
|
484
|
+
changeRequests: drafted.changeRequests,
|
|
485
|
+
...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
|
|
486
|
+
}
|
|
487
|
+
})
|
|
402
488
|
|
|
403
489
|
// The question has no default: a release goes out only when someone says so.
|
|
404
490
|
for (let round = 1; ; round++) {
|
|
405
491
|
const answer = yield* ask(round === 1 ? 'approve' : `approve:${round}`, {
|
|
406
|
-
prompt: `Release ${tag} with these notes?\n\n${drafted.notes}`,
|
|
492
|
+
prompt: `Release ${cut?.candidate === true ? `${tag}, or the next release candidate of ${cut.version} still free when it is tagged,` : tag} with these notes?\n\n${drafted.notes}`,
|
|
407
493
|
options: [
|
|
408
494
|
{ value: 'Approve', description: 'Tags, publishes and deploys it.' },
|
|
409
495
|
{ value: 'Edit notes', description: 'Say what to change; the notes are redrafted.' },
|
|
@@ -429,16 +515,7 @@ export default defineLoop({
|
|
|
429
515
|
timeout: '1 day'
|
|
430
516
|
})
|
|
431
517
|
|
|
432
|
-
const kept = yield*
|
|
433
|
-
kind: 'release_notes',
|
|
434
|
-
title: drafted.title,
|
|
435
|
-
text: drafted.notes,
|
|
436
|
-
data: {
|
|
437
|
-
tag,
|
|
438
|
-
changeRequests: drafted.changeRequests,
|
|
439
|
-
...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
|
|
440
|
-
}
|
|
441
|
-
})
|
|
518
|
+
const kept = yield* recordNotes('notes')
|
|
442
519
|
|
|
443
520
|
return { status: 'rejected', reason: why, tag, notesArtifactId: kept.artifactId } satisfies Output
|
|
444
521
|
}
|
|
@@ -461,16 +538,7 @@ export default defineLoop({
|
|
|
461
538
|
})
|
|
462
539
|
}
|
|
463
540
|
|
|
464
|
-
let notes = yield*
|
|
465
|
-
kind: 'release_notes',
|
|
466
|
-
title: drafted.title,
|
|
467
|
-
text: drafted.notes,
|
|
468
|
-
data: {
|
|
469
|
-
tag,
|
|
470
|
-
changeRequests: drafted.changeRequests,
|
|
471
|
-
...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
|
|
472
|
-
}
|
|
473
|
-
})
|
|
541
|
+
let notes = yield* recordNotes('notes')
|
|
474
542
|
|
|
475
543
|
let revision = gated
|
|
476
544
|
|
|
@@ -518,43 +586,68 @@ export default defineLoop({
|
|
|
518
586
|
|
|
519
587
|
const { releasedIn, ...picked } = yield* agentWork('pick-version', {
|
|
520
588
|
agent: 'releaser',
|
|
521
|
-
prompt: pickPrompt({ ...drafted, tag }, revision, input.tag),
|
|
589
|
+
prompt: pickPrompt({ ...drafted, tag }, revision, input.tag, cut),
|
|
522
590
|
output: Picked
|
|
523
591
|
})
|
|
524
592
|
|
|
525
|
-
|
|
526
|
-
|
|
593
|
+
const alreadyReleased = (released: string, reason: string) =>
|
|
594
|
+
({
|
|
527
595
|
status: 'nothing_to_release',
|
|
528
|
-
reason
|
|
529
|
-
tag:
|
|
596
|
+
reason,
|
|
597
|
+
tag: released,
|
|
530
598
|
notesArtifactId: notes.artifactId,
|
|
531
599
|
revision
|
|
532
|
-
} satisfies Output
|
|
600
|
+
}) satisfies Output
|
|
533
601
|
|
|
534
|
-
|
|
602
|
+
if (cut === undefined && releasedIn !== undefined)
|
|
603
|
+
return alreadyReleased(releasedIn, `${revision} is already released in ${releasedIn}`)
|
|
535
604
|
|
|
536
|
-
|
|
537
|
-
notes = yield* artifact('notes:picked', {
|
|
538
|
-
kind: 'release_notes',
|
|
539
|
-
title: picked.title,
|
|
540
|
-
text: picked.notes,
|
|
541
|
-
data: {
|
|
542
|
-
tag: pickedTag,
|
|
543
|
-
changeRequests: picked.changeRequests,
|
|
544
|
-
...(input.releaseScope === undefined ? undefined : { shipped: shippedScope(input.releaseScope) })
|
|
545
|
-
}
|
|
546
|
-
})
|
|
547
|
-
}
|
|
605
|
+
const pickedTag = tagOf(picked.tag, tag)
|
|
548
606
|
|
|
549
|
-
|
|
607
|
+
const repicked =
|
|
608
|
+
cut === undefined
|
|
609
|
+
? picked
|
|
610
|
+
: {
|
|
611
|
+
...picked,
|
|
612
|
+
title: renameTag(picked.title, tag, pickedTag),
|
|
613
|
+
notes: renameTag(picked.notes, tag, pickedTag)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const changed = pickedTag !== tag || repicked.notes !== drafted.notes || repicked.title !== drafted.title
|
|
617
|
+
|
|
618
|
+
drafted = repicked
|
|
550
619
|
tag = pickedTag
|
|
551
620
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
title: drafted.title,
|
|
556
|
-
|
|
557
|
-
|
|
621
|
+
if (changed) notes = yield* recordNotes('notes:picked')
|
|
622
|
+
|
|
623
|
+
const publish = (step: string) =>
|
|
624
|
+
release(step, { tag, revision, title: drafted.title, notes: drafted.notes }).pipe(
|
|
625
|
+
Effect.catchTag('StepFailed', failed =>
|
|
626
|
+
isTagElsewhere(failed) || isReleasedByOther(failed) ? Effect.succeed(failed) : Effect.fail(failed)
|
|
627
|
+
)
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
const approved = { tag, title: drafted.title, notes: drafted.notes }
|
|
631
|
+
|
|
632
|
+
let released = yield* publish('tag')
|
|
633
|
+
|
|
634
|
+
if (released instanceof StepFailed && cut === undefined && isReleasedByOther(released))
|
|
635
|
+
return alreadyReleased(tag, `${tag} is already released at ${revision} by another Run`)
|
|
636
|
+
|
|
637
|
+
// A tag is never moved, so a release candidate already tagged gives way to the next; a version has no next.
|
|
638
|
+
for (let round = 2; released instanceof StepFailed; round++) {
|
|
639
|
+
if (cut?.candidate !== true || round > 20) return yield* released
|
|
640
|
+
|
|
641
|
+
tag = `${cut.version}-rc.${(candidateNumber(tag, cut.version) ?? 0) + 1}`
|
|
642
|
+
// Only the tag changes from what was approved, so nothing is published unreviewed.
|
|
643
|
+
drafted = {
|
|
644
|
+
...drafted,
|
|
645
|
+
title: renameTag(approved.title, approved.tag, tag),
|
|
646
|
+
notes: renameTag(approved.notes, approved.tag, tag)
|
|
647
|
+
}
|
|
648
|
+
notes = yield* recordNotes(`notes:${round}`)
|
|
649
|
+
released = yield* publish(`tag:${round}`)
|
|
650
|
+
}
|
|
558
651
|
|
|
559
652
|
const deployed = (step: string, deployTag: string) =>
|
|
560
653
|
waitFor(step, {
|
package/src/shepherd.ts
CHANGED