@intentius/chant 0.124.89 → 0.124.90
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/ci-comment-commands.d.ts +18 -2
- package/dist/ci-comment-commands.d.ts.map +1 -1
- package/dist/ci-comment-commands.js +30 -2
- package/dist/ci-job-guard.d.ts +42 -45
- package/dist/ci-job-guard.d.ts.map +1 -1
- package/dist/ci-job-guard.js +206 -3
- package/dist/ci-note-commands.d.ts +41 -1
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +64 -5
- package/dist/ci-product.d.ts +41 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +44 -7
- package/dist/cli/handlers/pr-comment.d.ts +13 -1
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
- package/dist/cli/handlers/pr-comment.js +90 -1
- package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
- package/dist/cli/handlers/pr-notes.js +23 -1
- package/dist/cli/handlers/pr.js +16 -14
- package/dist/cli/handlers/run-wave.d.ts.map +1 -1
- package/dist/cli/handlers/run-wave.js +154 -4
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +17 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +15 -0
- package/dist/cli/registry.d.ts +8 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-checks.d.ts +28 -1
- package/dist/components/pr-checks.d.ts.map +1 -1
- package/dist/components/pr-checks.js +35 -2
- package/dist/components/pr-pipeline.d.ts +3 -2
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +4 -2
- package/dist/components/product-pipeline.d.ts +54 -2
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +59 -5
- package/dist/components/product-plan.d.ts +13 -1
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +36 -10
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +32 -23
- package/dist/lexicon.d.ts +82 -4
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-applied.d.ts +9 -0
- package/dist/lifecycle/gate-applied.d.ts.map +1 -1
- package/dist/op/apply-status.d.ts +84 -0
- package/dist/op/apply-status.d.ts.map +1 -0
- package/dist/op/apply-status.js +106 -0
- package/dist/op/before-merge-decide.d.ts +102 -0
- package/dist/op/before-merge-decide.d.ts.map +1 -0
- package/dist/op/before-merge-decide.js +142 -0
- package/dist/op/before-merge-done.d.ts +56 -0
- package/dist/op/before-merge-done.d.ts.map +1 -0
- package/dist/op/before-merge-done.js +69 -0
- package/dist/op/before-merge-store.d.ts +20 -0
- package/dist/op/before-merge-store.d.ts.map +1 -0
- package/dist/op/before-merge-store.js +48 -0
- package/dist/op/before-merge.d.ts +150 -0
- package/dist/op/before-merge.d.ts.map +1 -0
- package/dist/op/before-merge.js +207 -0
- package/dist/op/follow-on-run.d.ts +117 -0
- package/dist/op/follow-on-run.d.ts.map +1 -0
- package/dist/op/follow-on-run.js +154 -0
- package/dist/op/follow-on-store.d.ts +17 -0
- package/dist/op/follow-on-store.d.ts.map +1 -0
- package/dist/op/follow-on-store.js +54 -0
- package/dist/op/gate.d.ts +6 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +10 -1
- package/dist/op/index.d.ts +3 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +1 -0
- package/dist/op/op-waves-after-plan.d.ts +13 -0
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.d.ts +4 -1
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.js +10 -2
- package/dist/op/op-waves-follow-on.d.ts +162 -0
- package/dist/op/op-waves-follow-on.d.ts.map +1 -0
- package/dist/op/op-waves-follow-on.js +355 -0
- package/dist/op/op-waves-run.d.ts +146 -6
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +871 -99
- package/dist/op/op-waves-split.d.ts +122 -0
- package/dist/op/op-waves-split.d.ts.map +1 -0
- package/dist/op/op-waves-split.js +166 -0
- package/dist/op/op-waves.d.ts +20 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +15 -1
- package/dist/op/schedule-overdue.d.ts +15 -1
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +18 -2
- package/dist/op/stage-hooks.d.ts +36 -1
- package/dist/op/stage-hooks.d.ts.map +1 -1
- package/dist/op/stage-hooks.js +17 -3
- package/dist/op/wave-stop.d.ts +4 -1
- package/dist/op/wave-stop.d.ts.map +1 -1
- package/dist/op/wave-stop.js +4 -2
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +2 -1
- package/dist/release-floors.d.ts +3 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +21 -19
- package/dist/wave-blocked.d.ts +7 -1
- package/dist/wave-blocked.d.ts.map +1 -1
- package/dist/wave-blocked.js +7 -2
- package/dist/wave-runtime.mjs +364 -351
- package/package.json +1 -1
- package/src/ci-comment-commands.test.ts +63 -0
- package/src/ci-comment-commands.ts +43 -4
- package/src/ci-image.test.ts +1 -2
- package/src/ci-job-guard.before-merge.test.ts +148 -0
- package/src/ci-job-guard.follow-on-record.test.ts +137 -0
- package/src/ci-job-guard.follow-on.test.ts +144 -0
- package/src/ci-job-guard.ts +221 -3
- package/src/ci-note-commands.test.ts +76 -1
- package/src/ci-note-commands.ts +96 -7
- package/src/ci-product.ts +55 -7
- package/src/cli/handlers/pr-comment.ts +85 -2
- package/src/cli/handlers/pr-notes.ts +30 -6
- package/src/cli/handlers/pr.ts +14 -11
- package/src/cli/handlers/run-wave.ts +144 -4
- package/src/cli/main.ts +17 -0
- package/src/cli/parse-args.ts +11 -0
- package/src/cli/registry.ts +8 -1
- package/src/components/pr-checks.ts +55 -2
- package/src/components/pr-pipeline.ts +5 -3
- package/src/components/product-pipeline.apply-status.test.ts +50 -0
- package/src/components/product-pipeline.ts +113 -8
- package/src/components/product-plan.test.ts +23 -5
- package/src/components/product-plan.ts +43 -12
- package/src/floor-table.data.ts +32 -23
- package/src/lexicon.ts +78 -1
- package/src/lifecycle/gate-applied.ts +7 -0
- package/src/op/apply-status.test.ts +83 -0
- package/src/op/apply-status.ts +132 -0
- package/src/op/before-merge-decide.ts +190 -0
- package/src/op/before-merge-done.ts +99 -0
- package/src/op/before-merge-store.ts +44 -0
- package/src/op/before-merge.test.ts +201 -0
- package/src/op/before-merge.ts +266 -0
- package/src/op/follow-on-run.ts +206 -0
- package/src/op/follow-on-store.ts +54 -0
- package/src/op/gate.ts +16 -1
- package/src/op/index.ts +5 -0
- package/src/op/op-waves-after-plan.ts +13 -0
- package/src/op/op-waves-evidence-jobs.ts +11 -3
- package/src/op/op-waves-follow-on-record.test.ts +152 -0
- package/src/op/op-waves-follow-on.test.ts +247 -0
- package/src/op/op-waves-follow-on.ts +385 -0
- package/src/op/op-waves-render-spec.test.ts +1 -2
- package/src/op/op-waves-run.ts +971 -93
- package/src/op/op-waves-split-product.test.ts +288 -0
- package/src/op/op-waves-split-step.test.ts +298 -0
- package/src/op/op-waves-split.test.ts +196 -0
- package/src/op/op-waves-split.ts +189 -0
- package/src/op/op-waves.ts +28 -3
- package/src/op/schedule-overdue.test.ts +29 -1
- package/src/op/schedule-overdue.ts +27 -3
- package/src/op/stage-hooks.ts +52 -4
- package/src/op/wave-stop.ts +5 -3
- package/src/pr-post.ts +2 -1
- package/src/release-floors.ts +22 -19
- package/src/wave-blocked.ts +9 -4
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The apply statuses of an Op waves run (#4987): `<product>/apply` on the
|
|
3
|
+
* commit the waves applied, after each wave and after the last.
|
|
4
|
+
*
|
|
5
|
+
* A job of its own posts each one, `apply-status-<n>`, after wave n's jobs,
|
|
6
|
+
* at the default branch's commit with the wave jobs' outcome files. It runs
|
|
7
|
+
* none of the change's code: a before-merge run's wave jobs run the pull
|
|
8
|
+
* request's head, and this job holds the status token they do not need.
|
|
9
|
+
* The commit is the push's, or a before-merge run's decided head.
|
|
10
|
+
*
|
|
11
|
+
* What it posts, from the outcomes of waves 1 to n (`applyOutcomeOf`):
|
|
12
|
+
*
|
|
13
|
+
* - every run applied or had nothing to apply: `wave n of N applied`,
|
|
14
|
+
* pending, until the last wave, whose status is the one success;
|
|
15
|
+
* - a run waits at its gate: pending, `wave n of N waits for an approval`
|
|
16
|
+
* (failed on GitLab, which refuses to move a running status back to
|
|
17
|
+
* pending and keeps the pipeline running while one is left running; a
|
|
18
|
+
* retry posts a new one);
|
|
19
|
+
* - a run failed, or was blocked by one that did: failed, with the counts.
|
|
20
|
+
*
|
|
21
|
+
* A wave that wrote no outcome (its job stopped before its command, or the
|
|
22
|
+
* waves stopped before it) gets no status: the one before it stands, and
|
|
23
|
+
* the run's own jobs say what stopped.
|
|
24
|
+
*
|
|
25
|
+
* A `rest` wave's status job (#4992) posts for the wave its run ran, which
|
|
26
|
+
* a follow-on run names in `CHANT_WAVES_WAVE`, counted out of the waves the
|
|
27
|
+
* plan found, from the rest wave's note (./op-waves-follow-on.ts): a run
|
|
28
|
+
* that started a follow-on is not the last, so its status stays pending.
|
|
29
|
+
* The last run's status adds up every run of the chain (#4998): the
|
|
30
|
+
* earlier runs' outcomes come in the note's `chain`.
|
|
31
|
+
*
|
|
32
|
+
* Kept free of the forge client and git, so the generators import the
|
|
33
|
+
* names and the command line alone.
|
|
34
|
+
*/
|
|
35
|
+
import { applyOutcomeOf } from "../control/applied.js";
|
|
36
|
+
import { earlierWaveOutcomes, passesThrough } from "../wave-blocked.js";
|
|
37
|
+
import { readOpWaveRestNote, withChainOutcomes } from "./op-waves-follow-on.js";
|
|
38
|
+
/** The job after wave `wave` that posts its apply status. */
|
|
39
|
+
export function applyStatusJobName(wave) {
|
|
40
|
+
return `apply-status-${wave}`;
|
|
41
|
+
}
|
|
42
|
+
/** Whether `context` is a status name a forge keeps: no spaces, quotes or shell characters, at most 255 characters. */
|
|
43
|
+
export function assertApplyStatusContext(context) {
|
|
44
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_./:-]{0,254}$/.test(context))
|
|
45
|
+
throw new Error(`applyStatus.context ${JSON.stringify(context)} is not a status name: letters, digits, '.', '_', '/', ':' and '-'`);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The status job's command, through the product's bin: `chant run wave --op
|
|
49
|
+
* <op> --wave <n> --of <count> --apply-status <context> --at <sha> --forge
|
|
50
|
+
* <forge>`. It names the op and the wave count rather than the spec file,
|
|
51
|
+
* which a spec rendered at run time (#4982) leaves uncommitted.
|
|
52
|
+
*/
|
|
53
|
+
export function applyStatusCommand(spec, wave, context, forge, at, bin) {
|
|
54
|
+
const words = (bin ?? "").split(/\s+/).filter(Boolean);
|
|
55
|
+
return [
|
|
56
|
+
...(words.length > 0 ? words : ["chant"]),
|
|
57
|
+
"run", "wave", "--op", spec.name, "--wave", String(wave), "--of", String(spec.waves.length),
|
|
58
|
+
"--apply-status", context, "--at", at, "--forge", forge,
|
|
59
|
+
].join(" ");
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The apply status after wave `wave` of `of`, from the outcome files under
|
|
63
|
+
* `dirs`. Undefined when wave `wave` wrote no outcome.
|
|
64
|
+
*/
|
|
65
|
+
export function opWaveApplyStatus(dirs, wave, of, forge) {
|
|
66
|
+
// #4998: a follow-on's note carries the outcomes of the chain's earlier runs, which the status adds up with this run's.
|
|
67
|
+
const members = withChainOutcomes(earlierWaveOutcomes(dirs, wave + 1).members, readOpWaveRestNote(dirs), wave + 1);
|
|
68
|
+
if (![...members.values()].some((m) => m.wave === wave))
|
|
69
|
+
return undefined;
|
|
70
|
+
const summary = applyOutcomeOf(members);
|
|
71
|
+
const where = `wave ${wave} of ${of}`;
|
|
72
|
+
if (summary.outcome === "applied" || summary.outcome === "unchanged") {
|
|
73
|
+
if (wave < of)
|
|
74
|
+
return { state: "running", description: `${where} applied` };
|
|
75
|
+
return { state: "success", description: of === 1 ? "the wave applied" : `all ${of} waves applied` };
|
|
76
|
+
}
|
|
77
|
+
// A run that waits, or one held by it, is not a failure; any other run that did not get through is.
|
|
78
|
+
const waits = (o) => o.status === "waiting" || (o.status === "blocked" && o.by !== undefined && members.get(o.by)?.status === "waiting");
|
|
79
|
+
const held = [...members.values()].filter((o) => !passesThrough(o));
|
|
80
|
+
if (held.length > 0 && held.every(waits))
|
|
81
|
+
return { state: forge === "gitlab" ? "failed" : "running", description: `${where} waits for an approval` };
|
|
82
|
+
const counts = Object.entries(summary.counts).sort(([a], [b]) => a.localeCompare(b)).map(([k, n]) => `${n} ${k}`).join(", ");
|
|
83
|
+
return { state: "failed", description: `${where}: ${counts}` };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Post the apply status after wave `wave` on `at` (#4987), linked to the
|
|
87
|
+
* run. Resolves to the line the job logs; a wave with no outcome posts
|
|
88
|
+
* nothing. The forge's refusal is thrown.
|
|
89
|
+
*/
|
|
90
|
+
export async function postOpWaveApplyStatus(i) {
|
|
91
|
+
if (!/^[0-9a-f]{40,64}$/.test(i.at))
|
|
92
|
+
throw new Error(`--at names the commit the waves applied, a full sha, not ${JSON.stringify(i.at)}`);
|
|
93
|
+
// #4992: the rest wave's note counts the waves its plan found, past the spec's. A follow-on's wave past them that
|
|
94
|
+
// wrote an outcome and whose record job left no note (its gate waits) is counted as the last one known.
|
|
95
|
+
const note = readOpWaveRestNote(i.dirs);
|
|
96
|
+
const ran = i.wave > i.of && [...earlierWaveOutcomes(i.dirs, i.wave + 1).members.values()].some((m) => m.wave === i.wave);
|
|
97
|
+
const of = note && note.wave === i.wave ? Math.max(i.of, note.found, note.wave) : ran ? i.wave : i.of;
|
|
98
|
+
if (i.wave > of)
|
|
99
|
+
throw new Error(`--wave ${i.wave} is past the run's ${of} waves`);
|
|
100
|
+
assertApplyStatusContext(i.context);
|
|
101
|
+
const status = opWaveApplyStatus(i.dirs, i.wave, of, i.forge.kind);
|
|
102
|
+
if (!status)
|
|
103
|
+
return `wave ${i.wave} of ${of} wrote no outcome, so ${i.context} stays as the wave before it left it`;
|
|
104
|
+
await i.forge.setStatus(i.at, { context: i.context, state: status.state, description: status.description, ...(i.forge.runUrl ? { url: i.forge.runUrl } : {}), ...(i.pipelineId !== undefined ? { pipelineId: i.pipelineId } : {}) });
|
|
105
|
+
return `${i.context} on ${i.at.slice(0, 12)}: ${status.state}: ${status.description}`;
|
|
106
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decision behind `/<product> apply [wave-<n>]` on an open pull request
|
|
3
|
+
* whose waves run before merge (#4984), moved from terragucci's
|
|
4
|
+
* `decideOpen` and `openChecks` (comment-apply.ts) and `decideGitLabApply`
|
|
5
|
+
* (comment-apply-gitlab.ts). The comment job runs it on GitHub and Forgejo
|
|
6
|
+
* (../ci-comment-commands.ts), the note poll on GitLab
|
|
7
|
+
* (../ci-note-commands.ts), each at the default branch's commit with the
|
|
8
|
+
* job's token, so none of the change's code runs here.
|
|
9
|
+
*
|
|
10
|
+
* In order, each refused with a reply that says why:
|
|
11
|
+
*
|
|
12
|
+
* - the pull request is from this repository, into the default branch, and
|
|
13
|
+
* the wave it names is one the waves have;
|
|
14
|
+
* - its head, fetched from the forge's pull request ref, is still the head
|
|
15
|
+
* the forge named while the comment was read;
|
|
16
|
+
* - the requires the product lists (`apply.requires`, chant's requires
|
|
17
|
+
* checks: approved, mergeable, undiverged, checks) pass at that head;
|
|
18
|
+
* - every plan status of the product plan (`<product>/plan`, or one per
|
|
19
|
+
* target) passed on that head: a policy denial fails it, and nothing
|
|
20
|
+
* waives one;
|
|
21
|
+
* - the change touches none of the pipeline's files (the forge's workflow
|
|
22
|
+
* directory and the waves spec by default): the run is the default
|
|
23
|
+
* branch's pipeline, so a change to it applies after it merges;
|
|
24
|
+
* - with the product's reach line, it takes the locks of what it reaches at
|
|
25
|
+
* stage `apply`, and no other open pull request holds one of them.
|
|
26
|
+
*
|
|
27
|
+
* Then it records the decision on `chant/lifecycle` (./before-merge.ts),
|
|
28
|
+
* writes a wave stop for the head when the comment named a wave, or clears
|
|
29
|
+
* one (./wave-stop.ts), and starts the waves for that head: GitHub and
|
|
30
|
+
* Forgejo dispatch the waves workflow on the default branch with the
|
|
31
|
+
* inputs `pr`, `head` and `digest`; GitLab starts a pipeline of the default
|
|
32
|
+
* branch with the same three as variables.
|
|
33
|
+
*/
|
|
34
|
+
import type { ApplyRetried, StartedRun } from "../ci-note-commands.js";
|
|
35
|
+
import type { CiProductWords } from "../ci-product-words.js";
|
|
36
|
+
import type { ForgeKind } from "../pr-forge.js";
|
|
37
|
+
import type { PullRequestDetail } from "../pr-forge-reads.js";
|
|
38
|
+
import type { PrApplyRequire } from "../pr-requires.js";
|
|
39
|
+
import { type ReachRun } from "../lifecycle/reach-locks.js";
|
|
40
|
+
import type { BeforeMergeDecision, BeforeMergeRecord } from "./before-merge.js";
|
|
41
|
+
/** The waves before merge, as the pipeline tells the comment job and the note poll (#4984), in `CHANT_COMMENT_JOBS`. */
|
|
42
|
+
export interface WavesBeforeMergeJobs {
|
|
43
|
+
/** GitHub and Forgejo: the waves workflow's file, which the comment job dispatches. */
|
|
44
|
+
workflow?: string;
|
|
45
|
+
/** The requires the forge is asked (`apply.requires`). Default every one. */
|
|
46
|
+
requires?: PrApplyRequire[];
|
|
47
|
+
/** The statuses that must have passed on the head: the product plan's `<product>/plan`, or one per target. */
|
|
48
|
+
plan: string[];
|
|
49
|
+
/** Paths the change must not touch; one that ends in `/` is a directory. */
|
|
50
|
+
pipelineFiles: string[];
|
|
51
|
+
/** With the product plan's reach line: the lock file the locks at stage apply go in. */
|
|
52
|
+
locks?: {
|
|
53
|
+
gate?: string;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The pipeline files a before-merge change may not touch by default, by forge: the workflows and the waves specs. */
|
|
57
|
+
export declare function defaultPipelineFiles(forge: ForgeKind): string[];
|
|
58
|
+
/** What {@link decideWavesBeforeMerge} takes: the comment, and what the job reads and writes with. */
|
|
59
|
+
export interface DecideBeforeMergeInput {
|
|
60
|
+
forge: ForgeKind;
|
|
61
|
+
pr: PullRequestDetail;
|
|
62
|
+
user: string;
|
|
63
|
+
/** The default branch. */
|
|
64
|
+
base: string;
|
|
65
|
+
/** The last wave, when the comment named one. */
|
|
66
|
+
wave?: number;
|
|
67
|
+
op: string;
|
|
68
|
+
/** How many waves there are. */
|
|
69
|
+
count: number;
|
|
70
|
+
jobs: WavesBeforeMergeJobs;
|
|
71
|
+
words: CiProductWords;
|
|
72
|
+
/** The requires that are not met at `head`, as one sentence, or null when they pass. */
|
|
73
|
+
requires(pr: number, head: string): Promise<string | null>;
|
|
74
|
+
/** The head's statuses, newest per context. */
|
|
75
|
+
statuses(sha: string): Promise<ReadonlyArray<{
|
|
76
|
+
context: string;
|
|
77
|
+
state: string;
|
|
78
|
+
}>>;
|
|
79
|
+
/** Git in the job's checkout of the default branch. */
|
|
80
|
+
git: ReachRun;
|
|
81
|
+
cwd?: string;
|
|
82
|
+
/** Take the locks of what the change reaches at stage apply, for `by`; a refusal is the reply. Absent: the pipeline has no reach line, so nothing is locked. */
|
|
83
|
+
lock?(pr: number, head: string, base: string, by: string): Promise<{
|
|
84
|
+
ok: true;
|
|
85
|
+
targets: string[];
|
|
86
|
+
} | {
|
|
87
|
+
ok: false;
|
|
88
|
+
text: string;
|
|
89
|
+
}>;
|
|
90
|
+
/** Write the decision on chant/lifecycle. */
|
|
91
|
+
record(d: BeforeMergeDecision): Promise<BeforeMergeRecord>;
|
|
92
|
+
/** Write the head's wave stop, or clear it (null). */
|
|
93
|
+
stop(head: string, through: number | null): Promise<void>;
|
|
94
|
+
/** Start the waves for the recorded decision. */
|
|
95
|
+
start(r: BeforeMergeRecord): Promise<StartedRun>;
|
|
96
|
+
now?: () => string;
|
|
97
|
+
}
|
|
98
|
+
/** Whether `file` is one of `paths`: equal to one, or under one that ends in `/`. */
|
|
99
|
+
export declare function touchesPipeline(file: string, paths: readonly string[]): boolean;
|
|
100
|
+
/** Decide the apply, record it and start the waves (#4984). */
|
|
101
|
+
export declare function decideWavesBeforeMerge(i: DecideBeforeMergeInput): Promise<ApplyRetried>;
|
|
102
|
+
//# sourceMappingURL=before-merge-decide.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-merge-decide.d.ts","sourceRoot":"","sources":["../../src/op/before-merge-decide.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decision behind `/<product> apply [wave-<n>]` on an open pull request
|
|
3
|
+
* whose waves run before merge (#4984), moved from terragucci's
|
|
4
|
+
* `decideOpen` and `openChecks` (comment-apply.ts) and `decideGitLabApply`
|
|
5
|
+
* (comment-apply-gitlab.ts). The comment job runs it on GitHub and Forgejo
|
|
6
|
+
* (../ci-comment-commands.ts), the note poll on GitLab
|
|
7
|
+
* (../ci-note-commands.ts), each at the default branch's commit with the
|
|
8
|
+
* job's token, so none of the change's code runs here.
|
|
9
|
+
*
|
|
10
|
+
* In order, each refused with a reply that says why:
|
|
11
|
+
*
|
|
12
|
+
* - the pull request is from this repository, into the default branch, and
|
|
13
|
+
* the wave it names is one the waves have;
|
|
14
|
+
* - its head, fetched from the forge's pull request ref, is still the head
|
|
15
|
+
* the forge named while the comment was read;
|
|
16
|
+
* - the requires the product lists (`apply.requires`, chant's requires
|
|
17
|
+
* checks: approved, mergeable, undiverged, checks) pass at that head;
|
|
18
|
+
* - every plan status of the product plan (`<product>/plan`, or one per
|
|
19
|
+
* target) passed on that head: a policy denial fails it, and nothing
|
|
20
|
+
* waives one;
|
|
21
|
+
* - the change touches none of the pipeline's files (the forge's workflow
|
|
22
|
+
* directory and the waves spec by default): the run is the default
|
|
23
|
+
* branch's pipeline, so a change to it applies after it merges;
|
|
24
|
+
* - with the product's reach line, it takes the locks of what it reaches at
|
|
25
|
+
* stage `apply`, and no other open pull request holds one of them.
|
|
26
|
+
*
|
|
27
|
+
* Then it records the decision on `chant/lifecycle` (./before-merge.ts),
|
|
28
|
+
* writes a wave stop for the head when the comment named a wave, or clears
|
|
29
|
+
* one (./wave-stop.ts), and starts the waves for that head: GitHub and
|
|
30
|
+
* Forgejo dispatch the waves workflow on the default branch with the
|
|
31
|
+
* inputs `pr`, `head` and `digest`; GitLab starts a pipeline of the default
|
|
32
|
+
* branch with the same three as variables.
|
|
33
|
+
*/
|
|
34
|
+
import { commentTerms, forkReply } from "../ci-comment-replies.js";
|
|
35
|
+
import { pullRequestHeadRef } from "../lifecycle/reach-locks.js";
|
|
36
|
+
/** The pipeline files a before-merge change may not touch by default, by forge: the workflows and the waves specs. */
|
|
37
|
+
export function defaultPipelineFiles(forge) {
|
|
38
|
+
const workflows = forge === "gitlab" ? [".gitlab-ci.yml", ".gitlab/"] : forge === "forgejo" ? [".forgejo/workflows/"] : [".github/workflows/"];
|
|
39
|
+
return [...workflows, ".chant/op-waves/"];
|
|
40
|
+
}
|
|
41
|
+
const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
42
|
+
const BRANCH = /^[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/;
|
|
43
|
+
const short = (sha) => sha.slice(0, 8);
|
|
44
|
+
const message = (e) => (e instanceof Error ? e.message : String(e)).split("\n")[0];
|
|
45
|
+
/** Whether `file` is one of `paths`: equal to one, or under one that ends in `/`. */
|
|
46
|
+
export function touchesPipeline(file, paths) {
|
|
47
|
+
return paths.some((p) => (p.endsWith("/") ? file.startsWith(p) : file === p));
|
|
48
|
+
}
|
|
49
|
+
/** Decide the apply, record it and start the waves (#4984). */
|
|
50
|
+
export async function decideWavesBeforeMerge(i) {
|
|
51
|
+
const t = commentTerms(i.forge);
|
|
52
|
+
const at = t.at(i.pr.number);
|
|
53
|
+
const verb = i.words.verbs.apply;
|
|
54
|
+
const typed = `/${i.words.product} ${Object.entries(i.words.commands).find(([, c]) => c === "apply")?.[0] ?? "apply"}`;
|
|
55
|
+
const reply = (text) => ({ kind: "reply", text });
|
|
56
|
+
const fail = (reason) => ({ kind: "fail", reason });
|
|
57
|
+
const run = (args) => i.git(["git", ...args], { ...(i.cwd ? { cwd: i.cwd } : {}) });
|
|
58
|
+
if (!i.pr.sameRepo)
|
|
59
|
+
return reply(forkReply(i.words, i.forge));
|
|
60
|
+
if (i.pr.base !== undefined && i.pr.base !== i.base)
|
|
61
|
+
return reply(`${at} targets ${i.pr.base}, not the default branch ${i.base}, so it is not ${verb[1]} before merge`);
|
|
62
|
+
if (i.wave !== undefined && i.wave > i.count)
|
|
63
|
+
return reply(`the ${verb[0]} of this ${t.place} runs in ${i.count} wave${i.count === 1 ? "" : "s"}, so there is no \`wave-${i.wave}\``);
|
|
64
|
+
const head = i.pr.headSha;
|
|
65
|
+
if (!head || !SHA.test(head))
|
|
66
|
+
return fail(`${at} names no head commit`);
|
|
67
|
+
if (!BRANCH.test(i.base) || i.base.split("/").some((s) => s === ".." || s === ""))
|
|
68
|
+
return fail(`the default branch ${JSON.stringify(i.base)} is not a branch name this job passes on`);
|
|
69
|
+
// The head as the forge's pull request ref has it now, and the default branch's commit the change is measured from.
|
|
70
|
+
const headRef = "refs/remotes/chant/before-merge-head";
|
|
71
|
+
const baseRef = `refs/remotes/origin/${i.base}`;
|
|
72
|
+
const fetched = run(["fetch", "-q", "--no-tags", "origin", `+refs/heads/${i.base}:${baseRef}`, `+${pullRequestHeadRef(i.forge, i.pr.number)}:${headRef}`]);
|
|
73
|
+
if (fetched.status !== 0)
|
|
74
|
+
return fail(`could not fetch ${i.base} and the head of ${at} (${fetched.stderr.trim() || `git exited ${fetched.status}`})`);
|
|
75
|
+
const now = run(["rev-parse", headRef]).stdout.trim();
|
|
76
|
+
if (now !== head)
|
|
77
|
+
return reply(`${at} moved while this comment was read (its head is now ${short(now) || "unknown"}); comment again once its checks pass`);
|
|
78
|
+
const baseSha = run(["rev-parse", baseRef]).stdout.trim();
|
|
79
|
+
if (!SHA.test(baseSha))
|
|
80
|
+
return fail(`could not read the commit of ${i.base}`);
|
|
81
|
+
let unmet;
|
|
82
|
+
try {
|
|
83
|
+
unmet = await i.requires(i.pr.number, head);
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
return fail(`could not ask whether ${at} is ready (${message(e)})`);
|
|
87
|
+
}
|
|
88
|
+
if (unmet)
|
|
89
|
+
return reply(`${at} is not ready at ${short(head)}, so nothing is ${verb[1]}: ${unmet}. Comment again once that is fixed and its plan passes`);
|
|
90
|
+
let statuses;
|
|
91
|
+
try {
|
|
92
|
+
statuses = await i.statuses(head);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
return fail(`could not read the statuses of ${short(head)} (${message(e)})`);
|
|
96
|
+
}
|
|
97
|
+
const unplanned = i.jobs.plan.filter((c) => statuses.find((s) => s.context === c)?.state !== "success");
|
|
98
|
+
if (unplanned.length > 0) {
|
|
99
|
+
return reply(`the plan of ${at} has not passed on its head ${short(head)} (${unplanned.map((c) => `\`${c}\``).join(", ")}), so nothing is ${verb[1]}; push to it or comment the plan again, then comment \`${typed}\` again`);
|
|
100
|
+
}
|
|
101
|
+
const diff = run(["diff", "--name-only", "--no-renames", `${baseSha}...${head}`]);
|
|
102
|
+
if (diff.status !== 0)
|
|
103
|
+
return fail(`could not list the files ${at} changes (${diff.stderr.trim()})`);
|
|
104
|
+
const touched = diff.stdout.split("\n").map((l) => l.trim()).filter((f) => f && touchesPipeline(f, i.jobs.pipelineFiles));
|
|
105
|
+
if (touched.length > 0) {
|
|
106
|
+
return reply(`${at} changes \`${touched[0]}\`, and the ${verb[0]} runs the pipeline of ${i.base}, so it is not ${verb[1]} before merge. Merge it, then comment \`${typed}\` on it to ${verb[0]} from the merge commit`);
|
|
107
|
+
}
|
|
108
|
+
let locked = [];
|
|
109
|
+
if (i.lock) {
|
|
110
|
+
let l;
|
|
111
|
+
try {
|
|
112
|
+
l = await i.lock(i.pr.number, head, baseSha, i.user);
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
return fail(`could not take the locks of ${at} (${message(e)})`);
|
|
116
|
+
}
|
|
117
|
+
if (!l.ok)
|
|
118
|
+
return reply(l.text);
|
|
119
|
+
locked = l.targets;
|
|
120
|
+
}
|
|
121
|
+
const decision = { pr: i.pr.number, head, base: baseSha, ...(i.wave !== undefined ? { through: i.wave } : {}), at: (i.now ?? (() => new Date().toISOString()))(), by: i.user };
|
|
122
|
+
let record;
|
|
123
|
+
try {
|
|
124
|
+
record = await i.record(decision);
|
|
125
|
+
// A wave-<n> stops the waves after it at this head; an apply without one clears an earlier stop.
|
|
126
|
+
await i.stop(head, i.wave !== undefined && i.wave < i.count ? i.wave : null);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
return fail(`could not record the decision for ${short(head)}, so nothing was started (${message(e)})`);
|
|
130
|
+
}
|
|
131
|
+
let started;
|
|
132
|
+
try {
|
|
133
|
+
started = await i.start(record);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
return fail(`recorded the decision for ${short(head)}, and could not start the waves (${message(e)})`);
|
|
137
|
+
}
|
|
138
|
+
const through = i.wave !== undefined && i.wave < i.count ? ` through wave ${i.wave}` : "";
|
|
139
|
+
const locks = locked.length > 0 ? `, holding ${locked.map((x) => `\`${x}\``).join(", ")}` : "";
|
|
140
|
+
const link = started.url ? ` (${started.url})` : "";
|
|
141
|
+
return { kind: "ran", text: `started the waves of ${i.op}${link} on ${at}'s head ${short(head)}${through} for ${i.user}${locks}; each wave's gate decides, and the run says when the head applied`, ...(started.url ? { url: started.url } : {}) };
|
|
142
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The job after a before-merge run's last wave (#4984): `chant run wave --op
|
|
3
|
+
* <op> --wave <last> --merge auto|manual --forge <kind>`, at the default
|
|
4
|
+
* branch's commit, with every wave job's outcome file.
|
|
5
|
+
*
|
|
6
|
+
* It reads the decision the run names again (./before-merge.ts) and checks
|
|
7
|
+
* every wave applied: the outcomes add up to `applied` or `unchanged`, and
|
|
8
|
+
* the decision ran every wave. Then, with `auto`, it asks the forge whether
|
|
9
|
+
* the pull request is still approved at the decided head, merges it only
|
|
10
|
+
* at that head (`mergeAfterApply`, ../pr-merge.ts: open, head unmoved),
|
|
11
|
+
* releases the change's locks and replies. With `manual` it replies that
|
|
12
|
+
* the head applied, and the locks hold until the pull request merges or
|
|
13
|
+
* closes, when the unlock job releases them. A refusal is posted on the
|
|
14
|
+
* pull request and the job exits `waiting` (3), so the run shows it.
|
|
15
|
+
*
|
|
16
|
+
* A run whose `rest` wave started a follow-on run for the next wave the
|
|
17
|
+
* plan found (#4992, ./op-waves-follow-on.ts) is not the last: the job says
|
|
18
|
+
* so and does nothing more, and the follow-on's done job merges.
|
|
19
|
+
*/
|
|
20
|
+
import type { CiProductWords } from "../ci-product-words.js";
|
|
21
|
+
import type { ApplyOutcomeSummary } from "../control/applied.js";
|
|
22
|
+
import type { PrForge } from "../pr-forge.js";
|
|
23
|
+
import { type BeforeMergeRecord, type BeforeMergeRun } from "./before-merge.js";
|
|
24
|
+
/** What {@link beforeMergeDone} takes. */
|
|
25
|
+
export interface BeforeMergeDoneInput {
|
|
26
|
+
op: string;
|
|
27
|
+
/** How many waves the spec has. */
|
|
28
|
+
waves: number;
|
|
29
|
+
run: BeforeMergeRun;
|
|
30
|
+
record: BeforeMergeRecord | undefined;
|
|
31
|
+
/** The waves' outcome, from every job's outcome file. */
|
|
32
|
+
outcome: ApplyOutcomeSummary;
|
|
33
|
+
/** The rest wave of this run started a follow-on run for wave `next` (#4992): that run merges, so this one does nothing more. */
|
|
34
|
+
followOn?: {
|
|
35
|
+
wave: number;
|
|
36
|
+
next: number;
|
|
37
|
+
found: number;
|
|
38
|
+
};
|
|
39
|
+
merge: "auto" | "manual";
|
|
40
|
+
/** The job's client: it replies and reads the approval. */
|
|
41
|
+
forge: Pick<PrForge, "kind" | "addComment"> & Partial<Pick<PrForge, "prApproved">>;
|
|
42
|
+
/** The client holding the merge token (`auto`); default `forge`. */
|
|
43
|
+
merger?: Pick<PrForge, "kind" | "mergePullRequest" | "pullRequestHead" | "upsertComment">;
|
|
44
|
+
/** Release every lock the pull request holds; the targets released. */
|
|
45
|
+
release(pr: number): Promise<string[]>;
|
|
46
|
+
words: CiProductWords;
|
|
47
|
+
}
|
|
48
|
+
/** What the job did: its exit and its line. */
|
|
49
|
+
export interface BeforeMergeDone {
|
|
50
|
+
code: number;
|
|
51
|
+
text: string;
|
|
52
|
+
merged?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Check the run and its waves, then merge or say it is ready (#4984). Throws only when the reply cannot be posted. */
|
|
55
|
+
export declare function beforeMergeDone(i: BeforeMergeDoneInput): Promise<BeforeMergeDone>;
|
|
56
|
+
//# sourceMappingURL=before-merge-done.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-merge-done.d.ts","sourceRoot":"","sources":["../../src/op/before-merge-done.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAuB,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElG,0CAA0C;AAC1C,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,cAAc,CAAC;IACpB,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACtC,yDAAyD;IACzD,OAAO,EAAE,mBAAmB,CAAC;IAC7B,iIAAiI;IACjI,QAAQ,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB,2DAA2D;IAC3D,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IACnF,oEAAoE;IACpE,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,eAAe,CAAC,CAAC;IAC1F,uEAAuE;IACvE,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,+CAA+C;AAC/C,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAID,uHAAuH;AACvH,wBAAsB,eAAe,CAAC,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,CAwCvF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The job after a before-merge run's last wave (#4984): `chant run wave --op
|
|
3
|
+
* <op> --wave <last> --merge auto|manual --forge <kind>`, at the default
|
|
4
|
+
* branch's commit, with every wave job's outcome file.
|
|
5
|
+
*
|
|
6
|
+
* It reads the decision the run names again (./before-merge.ts) and checks
|
|
7
|
+
* every wave applied: the outcomes add up to `applied` or `unchanged`, and
|
|
8
|
+
* the decision ran every wave. Then, with `auto`, it asks the forge whether
|
|
9
|
+
* the pull request is still approved at the decided head, merges it only
|
|
10
|
+
* at that head (`mergeAfterApply`, ../pr-merge.ts: open, head unmoved),
|
|
11
|
+
* releases the change's locks and replies. With `manual` it replies that
|
|
12
|
+
* the head applied, and the locks hold until the pull request merges or
|
|
13
|
+
* closes, when the unlock job releases them. A refusal is posted on the
|
|
14
|
+
* pull request and the job exits `waiting` (3), so the run shows it.
|
|
15
|
+
*
|
|
16
|
+
* A run whose `rest` wave started a follow-on run for the next wave the
|
|
17
|
+
* plan found (#4992, ./op-waves-follow-on.ts) is not the last: the job says
|
|
18
|
+
* so and does nothing more, and the follow-on's done job merges.
|
|
19
|
+
*/
|
|
20
|
+
import { CHANT_EXIT } from "../exit-codes.js";
|
|
21
|
+
import { mergeAfterApply } from "../pr-merge.js";
|
|
22
|
+
import { beforeMergeProblems } from "./before-merge.js";
|
|
23
|
+
const short = (sha) => sha.slice(0, 12);
|
|
24
|
+
/** Check the run and its waves, then merge or say it is ready (#4984). Throws only when the reply cannot be posted. */
|
|
25
|
+
export async function beforeMergeDone(i) {
|
|
26
|
+
const problems = beforeMergeProblems(i.op, i.run, i.record);
|
|
27
|
+
if (problems.length > 0)
|
|
28
|
+
return { code: CHANT_EXIT.misplaced, text: problems.join("; ") };
|
|
29
|
+
const r = i.record;
|
|
30
|
+
const at = i.forge.kind === "gitlab" ? `!${r.pr}` : `pull request ${r.pr}`;
|
|
31
|
+
const verb = i.words.verbs.apply;
|
|
32
|
+
const say = async (text, code, merged) => {
|
|
33
|
+
await i.forge.addComment(r.pr, `${i.words.product}: ${text}`);
|
|
34
|
+
return { code, text, ...(merged !== undefined ? { merged } : {}) };
|
|
35
|
+
};
|
|
36
|
+
// #4992: not the last run of the head's waves; the follow-on's done job merges and replies.
|
|
37
|
+
if (i.followOn) {
|
|
38
|
+
return { code: CHANT_EXIT.done, text: `wave ${i.followOn.wave} of ${i.followOn.found} ${verb[1]} ${at}'s head ${short(r.head)}, and a follow-on run goes on with wave ${i.followOn.next}; its done job merges, so nothing is merged here` };
|
|
39
|
+
}
|
|
40
|
+
if (r.through !== undefined && r.through < i.waves) {
|
|
41
|
+
return say(`${verb[1]} ${i.op} through wave ${r.through} of ${i.waves} at ${at}'s head ${short(r.head)}; the waves after it wait until the ${verb[0]} is asked for again without a wave, so nothing is merged`, CHANT_EXIT.done);
|
|
42
|
+
}
|
|
43
|
+
if (i.outcome.outcome !== "applied" && i.outcome.outcome !== "unchanged") {
|
|
44
|
+
return say(`the waves of ${i.op} at ${at}'s head ${short(r.head)} ended ${i.outcome.outcome}, so nothing is merged; each wave's job says why`, CHANT_EXIT.waiting);
|
|
45
|
+
}
|
|
46
|
+
if (i.merge === "manual") {
|
|
47
|
+
return say(`every wave of ${i.op} ${verb[1]} ${at}'s head ${short(r.head)}. Merge it when you are ready; its locks hold until it merges or closes`, CHANT_EXIT.done);
|
|
48
|
+
}
|
|
49
|
+
// The approval is read again for the head that applied: one taken back since does not merge.
|
|
50
|
+
if (i.forge.prApproved) {
|
|
51
|
+
const approval = await i.forge.prApproved(r.pr, r.head);
|
|
52
|
+
if (!approval.passed)
|
|
53
|
+
return say(`every wave of ${i.op} ${verb[1]} ${at}'s head ${short(r.head)}, and it was not merged: it is not approved at that head (${approval.reason}). Merge it by hand once it is`, CHANT_EXIT.waiting, false);
|
|
54
|
+
}
|
|
55
|
+
const merger = i.merger ?? i.forge;
|
|
56
|
+
const merged = await mergeAfterApply({ forge: merger, pr: r.pr, head: r.head, recorded: { pushed: true }, words: i.words });
|
|
57
|
+
if (!merged.merged)
|
|
58
|
+
return { code: CHANT_EXIT.waiting, text: `${at} was not merged: ${merged.reason ?? "the forge refused"}${merged.posted ? "; the reason is posted on it" : ""}`, merged: false };
|
|
59
|
+
let released = [];
|
|
60
|
+
let kept = "";
|
|
61
|
+
try {
|
|
62
|
+
released = await i.release(r.pr);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
kept = `; its locks could not be released (${e instanceof Error ? e.message : String(e)}), and the unlock job releases them on close`;
|
|
66
|
+
}
|
|
67
|
+
const locks = released.length > 0 ? ` and released its locks on ${released.join(", ")}` : "";
|
|
68
|
+
return say(`every wave of ${i.op} ${verb[1]} ${at}'s head ${short(r.head)}: merged it${merged.sha ? ` as ${short(merged.sha)}` : ""}${locks}${kept}`, CHANT_EXIT.done, true);
|
|
69
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The before-merge decisions on `chant/lifecycle` (#4984): read and written
|
|
3
|
+
* through the ledger's git, at `_waves/<op>.before-merge.json` from the top
|
|
4
|
+
* of the branch (./before-merge.ts says what a decision is). Kept apart from
|
|
5
|
+
* ./before-merge.ts so the generators and the guard load no git code.
|
|
6
|
+
*/
|
|
7
|
+
import { type BeforeMergeDecision, type BeforeMergeRecord } from "./before-merge.js";
|
|
8
|
+
/** The decision of op `op` for `head`, from `chant/lifecycle` as the remote has it. Undefined when there is none. */
|
|
9
|
+
export declare function beforeMergeRecordAt(op: string, head: string, opts?: {
|
|
10
|
+
cwd?: string;
|
|
11
|
+
}): Promise<BeforeMergeRecord | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Write a decision for op `op` and push `chant/lifecycle`: the record the
|
|
14
|
+
* run's guard reads. Read, written and pushed again when another writer
|
|
15
|
+
* pushed first, up to three times. Returns the record, digest included.
|
|
16
|
+
*/
|
|
17
|
+
export declare function recordBeforeMerge(op: string, decision: BeforeMergeDecision, opts?: {
|
|
18
|
+
cwd?: string;
|
|
19
|
+
}): Promise<BeforeMergeRecord>;
|
|
20
|
+
//# sourceMappingURL=before-merge-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-merge-store.d.ts","sourceRoot":"","sources":["../../src/op/before-merge-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAoH,KAAK,mBAAmB,EAAwB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE1N,qHAAqH;AACrH,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAOvI;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAkB1I"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The before-merge decisions on `chant/lifecycle` (#4984): read and written
|
|
3
|
+
* through the ledger's git, at `_waves/<op>.before-merge.json` from the top
|
|
4
|
+
* of the branch (./before-merge.ts says what a decision is). Kept apart from
|
|
5
|
+
* ./before-merge.ts so the generators and the guard load no git code.
|
|
6
|
+
*/
|
|
7
|
+
import { fetchLifecycleStatus, pushLifecycleStatus, readBlobBySha, readPathSha, writeBlobToPath } from "../lifecycle/git.js";
|
|
8
|
+
import { BEFORE_MERGE_DIR, beforeMergeDigest, beforeMergeFile, beforeMergeKeyProblem, parseBeforeMerge, renderBeforeMerge } from "./before-merge.js";
|
|
9
|
+
/** The decision of op `op` for `head`, from `chant/lifecycle` as the remote has it. Undefined when there is none. */
|
|
10
|
+
export async function beforeMergeRecordAt(op, head, opts = {}) {
|
|
11
|
+
if (beforeMergeKeyProblem(op, head))
|
|
12
|
+
return undefined;
|
|
13
|
+
const fetched = await fetchLifecycleStatus(opts);
|
|
14
|
+
if (fetched.status === "unreachable")
|
|
15
|
+
throw new Error("chant/lifecycle could not be fetched, so the decision cannot be read");
|
|
16
|
+
const blob = await readPathSha(BEFORE_MERGE_DIR, beforeMergeFile(op), { ...opts, ledgerPrefix: "" });
|
|
17
|
+
if (!blob)
|
|
18
|
+
return undefined;
|
|
19
|
+
return parseBeforeMerge(await readBlobBySha(blob, opts)).heads[head];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Write a decision for op `op` and push `chant/lifecycle`: the record the
|
|
23
|
+
* run's guard reads. Read, written and pushed again when another writer
|
|
24
|
+
* pushed first, up to three times. Returns the record, digest included.
|
|
25
|
+
*/
|
|
26
|
+
export async function recordBeforeMerge(op, decision, opts = {}) {
|
|
27
|
+
const problem = beforeMergeKeyProblem(op, decision.head) ?? beforeMergeKeyProblem(op, decision.base);
|
|
28
|
+
if (problem)
|
|
29
|
+
throw new Error(problem);
|
|
30
|
+
const record = { ...decision, digest: beforeMergeDigest(op, decision) };
|
|
31
|
+
const where = { ...opts, ledgerPrefix: "" };
|
|
32
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
33
|
+
const fetched = await fetchLifecycleStatus(opts);
|
|
34
|
+
if (fetched.status === "unreachable")
|
|
35
|
+
throw new Error("chant/lifecycle could not be fetched, so the decision was not written");
|
|
36
|
+
const blob = await readPathSha(BEFORE_MERGE_DIR, beforeMergeFile(op), where);
|
|
37
|
+
const file = parseBeforeMerge(blob ? await readBlobBySha(blob, opts) : null);
|
|
38
|
+
const next = { version: 1, heads: { ...file.heads, [decision.head]: record } };
|
|
39
|
+
await writeBlobToPath(BEFORE_MERGE_DIR, beforeMergeFile(op), renderBeforeMerge(next), `Decide ${op} before merge: pull request ${decision.pr} at ${decision.head.slice(0, 12)}`, { ...where, expectPriorPathSha: blob });
|
|
40
|
+
const pushed = await pushLifecycleStatus(opts);
|
|
41
|
+
if (pushed.status === "stale")
|
|
42
|
+
continue;
|
|
43
|
+
if (pushed.status === "failed")
|
|
44
|
+
throw new Error(`could not push the decision to chant/lifecycle (${pushed.stderr.trim()})`);
|
|
45
|
+
return record;
|
|
46
|
+
}
|
|
47
|
+
throw new Error("chant/lifecycle kept moving, so the decision was not written; comment again");
|
|
48
|
+
}
|