@intentius/chant 0.124.61 → 0.124.63
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/cli/handlers/approve.d.ts +18 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +142 -16
- package/dist/cli/handlers/plan.d.ts +10 -0
- package/dist/cli/handlers/plan.d.ts.map +1 -0
- package/dist/cli/handlers/plan.js +71 -0
- package/dist/cli/handlers/release.d.ts +6 -4
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +13 -7
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +34 -5
- package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
- package/dist/cli/mcp/workspace-tools.js +2 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +31 -0
- package/dist/cli/registry.d.ts +13 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/config.d.ts +32 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/gate-decision.d.ts +1 -1
- package/dist/gate-decision.d.ts.map +1 -1
- package/dist/gate-decision.js +4 -2
- package/dist/gate-statement.schema.json +44 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
- package/dist/lifecycle/gate-ledger.d.ts +17 -3
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.d.ts +39 -3
- package/dist/lifecycle/gate-seal.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.js +50 -10
- package/dist/lifecycle/gate-statement.d.ts +70 -0
- package/dist/lifecycle/gate-statement.d.ts.map +1 -0
- package/dist/lifecycle/gate-statement.js +74 -0
- package/dist/lifecycle/gate-webauthn.d.ts +79 -0
- package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
- package/dist/lifecycle/gate-webauthn.js +105 -0
- package/dist/lifecycle/git.d.ts +1 -1
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +24 -19
- package/dist/lifecycle/ledger-remote.d.ts +37 -0
- package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
- package/dist/lifecycle/ledger-remote.js +42 -0
- package/dist/lifecycle/plan-stale.d.ts +76 -0
- package/dist/lifecycle/plan-stale.d.ts.map +1 -0
- package/dist/lifecycle/plan-stale.js +121 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
- package/dist/lifecycle/publish-credentials.js +2 -0
- package/dist/lifecycle/publish-declaration.d.ts +87 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +87 -1
- package/dist/lifecycle/publish-forge.d.ts +5 -1
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +14 -4
- package/dist/lifecycle/publish-github.d.ts +69 -0
- package/dist/lifecycle/publish-github.d.ts.map +1 -0
- package/dist/lifecycle/publish-github.js +153 -0
- package/dist/lifecycle/publish-homebrew.d.ts +66 -0
- package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
- package/dist/lifecycle/publish-homebrew.js +173 -0
- package/dist/lifecycle/publish-marketplace.d.ts +51 -0
- package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
- package/dist/lifecycle/publish-marketplace.js +254 -0
- package/dist/lifecycle/publish-targets.d.ts +6 -0
- package/dist/lifecycle/publish-targets.d.ts.map +1 -1
- package/dist/lifecycle/publish-targets.js +15 -0
- package/dist/lifecycle/publish-tauri.d.ts +61 -0
- package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
- package/dist/lifecycle/publish-tauri.js +182 -0
- package/dist/lifecycle/release-publish.d.ts +5 -2
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
- package/dist/lifecycle/snapshot-store.js +17 -9
- package/dist/lifecycle/test-passkey.d.ts +25 -0
- package/dist/lifecycle/test-passkey.d.ts.map +1 -0
- package/dist/lifecycle/test-passkey.js +39 -0
- package/dist/notify.d.ts +23 -3
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +8 -2
- package/dist/notify.schema.json +12 -3
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/pr-forge.d.ts +20 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +61 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +331 -330
- package/dist/workspace/ci-builds.d.ts +21 -0
- package/dist/workspace/ci-builds.d.ts.map +1 -1
- package/dist/workspace/ci-builds.js +14 -0
- package/dist/workspace/ci-green-workflow.d.ts +2 -0
- package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
- package/dist/workspace/ci-green-workflow.js +9 -0
- package/dist/workspace/ci-green.d.ts +45 -2
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +127 -9
- package/dist/workspace/ci-quarantine-report.d.ts +80 -0
- package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine-report.js +205 -0
- package/dist/workspace/ci-quarantine.d.ts +73 -0
- package/dist/workspace/ci-quarantine.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine.js +171 -0
- package/dist/workspace/ci-serve.d.ts.map +1 -1
- package/dist/workspace/ci-serve.js +7 -4
- package/dist/workspace/class-data.d.ts +3 -1
- package/dist/workspace/class-data.d.ts.map +1 -1
- package/dist/workspace/class-data.js +4 -1
- package/dist/workspace/declaration.d.ts +45 -2
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +45 -2
- package/dist/workspace/declaration.schema.json +51 -3
- package/dist/workspace/forge-work.d.ts +76 -0
- package/dist/workspace/forge-work.d.ts.map +1 -0
- package/dist/workspace/forge-work.js +160 -0
- package/dist/workspace/identity-gate-rule.d.ts +3 -2
- package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
- package/dist/workspace/identity-gate-rule.js +5 -7
- package/dist/workspace/identity.d.ts +3 -2
- package/dist/workspace/identity.d.ts.map +1 -1
- package/dist/workspace/identity.js +6 -3
- package/dist/workspace/intent-cli.d.ts +3 -2
- package/dist/workspace/intent-cli.d.ts.map +1 -1
- package/dist/workspace/intent-cli.js +26 -5
- package/dist/workspace/intent-record.d.ts +3 -0
- package/dist/workspace/intent-record.d.ts.map +1 -1
- package/dist/workspace/intent-record.schema.json +32 -0
- package/dist/workspace/intent.d.ts +9 -0
- package/dist/workspace/intent.d.ts.map +1 -1
- package/dist/workspace/intent.js +3 -0
- package/dist/workspace/intent.schema.json +32 -0
- package/dist/workspace/kind-readers.d.ts.map +1 -1
- package/dist/workspace/kind-readers.js +2 -1
- package/dist/workspace/kinds.d.ts +6 -1
- package/dist/workspace/kinds.d.ts.map +1 -1
- package/dist/workspace/kinds.js +8 -3
- package/dist/workspace/plan-stale.schema.json +286 -0
- package/dist/workspace/release-candidates.d.ts +33 -6
- package/dist/workspace/release-candidates.d.ts.map +1 -1
- package/dist/workspace/release-candidates.js +49 -20
- package/dist/workspace/release-candidates.schema.json +48 -2
- package/dist/workspace/trust/policy.d.ts +10 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +19 -1
- package/dist/workspace/trust/run-commits.d.ts.map +1 -1
- package/dist/workspace/trust/run-commits.js +2 -1
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/seal.js +34 -3
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +6 -1
- package/package.json +2 -1
- package/src/cli/handlers/approve-external-signature.test.ts +226 -0
- package/src/cli/handlers/approve.ts +174 -16
- package/src/cli/handlers/plan.ts +74 -0
- package/src/cli/handlers/release.ts +12 -7
- package/src/cli/main.ts +34 -5
- package/src/cli/mcp/workspace-tools.ts +2 -1
- package/src/cli/parse-args.ts +24 -0
- package/src/cli/registry.ts +13 -1
- package/src/gate-decision-bundle.test.ts +4 -2
- package/src/gate-decision.ts +11 -2
- package/src/gate-statement.schema.json +44 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
- package/src/lifecycle/gate-ledger.ts +17 -3
- package/src/lifecycle/gate-seal.ts +62 -9
- package/src/lifecycle/gate-statement.ts +107 -0
- package/src/lifecycle/gate-webauthn.test.ts +77 -0
- package/src/lifecycle/gate-webauthn.ts +133 -0
- package/src/lifecycle/git.ts +23 -19
- package/src/lifecycle/ledger-remote.test.ts +183 -0
- package/src/lifecycle/ledger-remote.ts +46 -0
- package/src/lifecycle/plan-stale.test.ts +150 -0
- package/src/lifecycle/plan-stale.ts +173 -0
- package/src/lifecycle/publish-credentials.ts +2 -0
- package/src/lifecycle/publish-declaration.ts +93 -1
- package/src/lifecycle/publish-forge.ts +15 -4
- package/src/lifecycle/publish-github.ts +174 -0
- package/src/lifecycle/publish-homebrew.test.ts +179 -0
- package/src/lifecycle/publish-homebrew.ts +187 -0
- package/src/lifecycle/publish-marketplace.test.ts +254 -0
- package/src/lifecycle/publish-marketplace.ts +259 -0
- package/src/lifecycle/publish-target-context.test.ts +2 -2
- package/src/lifecycle/publish-targets.test.ts +23 -0
- package/src/lifecycle/publish-targets.ts +15 -0
- package/src/lifecycle/publish-tauri.test.ts +163 -0
- package/src/lifecycle/publish-tauri.ts +199 -0
- package/src/lifecycle/release-publish.ts +5 -3
- package/src/lifecycle/snapshot-store.ts +16 -9
- package/src/lifecycle/test-passkey.ts +55 -0
- package/src/notify-bundle.test.ts +3 -1
- package/src/notify.schema.json +12 -3
- package/src/notify.ts +20 -3
- package/src/override-gate-bundle.test.ts +2 -0
- package/src/pr-forge-bundle.test.ts +2 -2
- package/src/pr-forge.test.ts +38 -0
- package/src/pr-forge.ts +68 -5
- package/src/release-floors.ts +1 -1
- package/src/stage-hooks-bundle.test.ts +2 -0
- package/src/wave-runtime-bundle.test.ts +3 -2
- package/src/workspace/ci-builds.ts +27 -0
- package/src/workspace/ci-green-stale.test.ts +193 -0
- package/src/workspace/ci-green-workflow.test.ts +9 -0
- package/src/workspace/ci-green-workflow.ts +9 -0
- package/src/workspace/ci-green.ts +141 -10
- package/src/workspace/ci-quarantine-report.test.ts +146 -0
- package/src/workspace/ci-quarantine-report.ts +235 -0
- package/src/workspace/ci-quarantine.test.ts +161 -0
- package/src/workspace/ci-quarantine.ts +189 -0
- package/src/workspace/ci-serve.ts +7 -4
- package/src/workspace/class-data.ts +5 -1
- package/src/workspace/declaration.schema.json +51 -3
- package/src/workspace/declaration.test.ts +1 -0
- package/src/workspace/declaration.ts +88 -5
- package/src/workspace/forge-work.test.ts +143 -0
- package/src/workspace/forge-work.ts +195 -0
- package/src/workspace/identity-gate-rule.ts +6 -8
- package/src/workspace/identity.ts +6 -3
- package/src/workspace/intent-cli.ts +24 -5
- package/src/workspace/intent-record.schema.json +32 -0
- package/src/workspace/intent-record.ts +3 -0
- package/src/workspace/intent.schema.json +32 -0
- package/src/workspace/intent.ts +10 -0
- package/src/workspace/kind-readers.ts +2 -1
- package/src/workspace/kinds.test.ts +13 -0
- package/src/workspace/kinds.ts +12 -3
- package/src/workspace/plan-stale.schema.json +286 -0
- package/src/workspace/release-candidates.schema.json +48 -2
- package/src/workspace/release-candidates.test.ts +77 -4
- package/src/workspace/release-candidates.ts +62 -20
- package/src/workspace/trust/policy.ts +24 -1
- package/src/workspace/trust/run-commits.ts +2 -1
- package/src/workspace/trust/seal.ts +35 -3
- package/src/workspace/trust/trust-files.test.ts +5 -0
- package/src/workspace/trust/trust-files.ts +15 -1
|
@@ -64,7 +64,8 @@ describe("the wave-job runtime bundle (#3896)", () => {
|
|
|
64
64
|
test("carries its version and stays small", () => {
|
|
65
65
|
expect(built.text).toContain('"workspace points"');
|
|
66
66
|
expect(built.text.startsWith("#!/usr/bin/env node\n")).toBe(true);
|
|
67
|
-
// About
|
|
68
|
-
|
|
67
|
+
// About 2.0 MB minified at #4678, which took it past 2 MiB; the declaration schema and zod's inlined
|
|
68
|
+
// schemas are a large part of it. The cap catches the 33 MB of the left-out packages, so 2.5 MiB keeps that.
|
|
69
|
+
expect(built.bytes).toBeLessThan(2.5 * 1024 * 1024);
|
|
69
70
|
});
|
|
70
71
|
});
|
|
@@ -102,6 +102,20 @@ export interface CiRecord {
|
|
|
102
102
|
notified?: { red?: string; culprit?: string; green?: string };
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* What the tick remembers about a branch rather than a commit (#4678),
|
|
107
|
+
* `_ci/branch/<branch>.json` on `chant/lifecycle`, the branch name
|
|
108
|
+
* URI-encoded. `stale` is the `ci.stale` it sent last: the stretch's oldest
|
|
109
|
+
* commit above the newest green one (`since`), that green commit, when, and
|
|
110
|
+
* once a newer commit is green, the green commit that ended the stretch.
|
|
111
|
+
* A stretch without `ended` has been told, however long it lasts.
|
|
112
|
+
*/
|
|
113
|
+
export interface CiBranchRecord {
|
|
114
|
+
schema: 1;
|
|
115
|
+
branch: string;
|
|
116
|
+
stale?: { since: string; lastGreen: string | null; at: string; ended?: string };
|
|
117
|
+
}
|
|
118
|
+
|
|
105
119
|
export interface CiRecordRun {
|
|
106
120
|
name: string;
|
|
107
121
|
id: number | null;
|
|
@@ -348,6 +362,19 @@ export function sameRecord(a: CiRecord | undefined, b: CiRecord): boolean {
|
|
|
348
362
|
}
|
|
349
363
|
|
|
350
364
|
export const recordPath = (sha: string) => `${CI_RECORDS_DIR}/${sha}.json`;
|
|
365
|
+
export const branchRecordPath = (branch: string) => `${CI_RECORDS_DIR}/branch/${encodeURIComponent(branch)}.json`;
|
|
366
|
+
|
|
367
|
+
/** A branch's record (#4678), from the local `chant/lifecycle` (or `ref`). Undefined when there is none or it doesn't parse. */
|
|
368
|
+
export function readCiBranchRecord(top: string, branch: string, ref: string = LEDGER_REF): CiBranchRecord | undefined {
|
|
369
|
+
const text = tryGit(top, ["show", `${ref}:${branchRecordPath(branch)}`]);
|
|
370
|
+
if (!text) return undefined;
|
|
371
|
+
try {
|
|
372
|
+
const r = JSON.parse(text) as CiBranchRecord;
|
|
373
|
+
return r && r.schema === 1 && r.branch === branch ? r : undefined;
|
|
374
|
+
} catch {
|
|
375
|
+
return undefined;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
351
378
|
|
|
352
379
|
function tryGit(top: string, args: string[]): string | null {
|
|
353
380
|
try {
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4678 — ci.stale: the branch has had no green commit for staleAfter hours.
|
|
3
|
+
* Sent once per red stretch, remembered in _ci/branch/<branch>.json, and
|
|
4
|
+
* ended by the ci.green of a newer green commit.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { afterAll, describe, expect, test } from "vitest";
|
|
9
|
+
import { cleanScratch, declaration, git, scratchDir, writeFiles } from "./__fixtures__/contract-repo";
|
|
10
|
+
import { ciTick, readGreen, staleEvents, type StaleWalkCommit } from "./ci-green";
|
|
11
|
+
import type { CheckRun, CiForge } from "./ci-green-forge";
|
|
12
|
+
import { readCiBranchRecord, type CiBranchRecord } from "./ci-builds";
|
|
13
|
+
import type { CiGreen } from "./declaration";
|
|
14
|
+
import type { NotifyConfig, NotifyEvent } from "../notify";
|
|
15
|
+
|
|
16
|
+
afterAll(cleanScratch);
|
|
17
|
+
|
|
18
|
+
const NOW = new Date("2026-10-20T12:00:00Z");
|
|
19
|
+
const hoursAgo = (h: number, now = NOW) => new Date(now.getTime() - h * 3_600_000).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
20
|
+
const later = (h: number) => new Date(NOW.getTime() + h * 3_600_000);
|
|
21
|
+
const sha = (n: number) => n.toString(16).padStart(40, "0");
|
|
22
|
+
|
|
23
|
+
const GREEN: CiGreen = { branch: "main", window: "24h", phases: [], require: [], signedSince: null, source: "checks", notify: { slack: "SLACK", staleAfter: 6 }, pointer: "/ci/green" };
|
|
24
|
+
|
|
25
|
+
/** Commits newest first, `hours` ago each. */
|
|
26
|
+
const walkOf = (...hours: number[]): StaleWalkCommit[] => hours.map((h, i) => ({ sha: sha(hours.length - i), committed: hoursAgo(h) }));
|
|
27
|
+
|
|
28
|
+
function decide(walk: StaleWalkCommit[], green: number[], more: { stale?: CiBranchRecord["stale"]; answering?: string; judged?: (s: string) => boolean; staleAfter?: number | null } = {}) {
|
|
29
|
+
return staleEvents({
|
|
30
|
+
green: { ...GREEN, notify: { slack: "SLACK", ...(more.staleAfter === null ? {} : { staleAfter: more.staleAfter ?? 6 }) } },
|
|
31
|
+
walk,
|
|
32
|
+
isGreen: (s) => green.map(sha).includes(s),
|
|
33
|
+
judged: more.judged ?? (() => true),
|
|
34
|
+
stale: more.stale,
|
|
35
|
+
answering: more.answering,
|
|
36
|
+
now: NOW,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("which stretch is stale (#4678)", () => {
|
|
41
|
+
test("ci.stale when the oldest commit above the newest green one is staleAfter hours old, naming the tip, it and the green commit", () => {
|
|
42
|
+
// 4 is the tip, 1 is green; 2 landed 7 hours ago.
|
|
43
|
+
const { events } = decide(walkOf(1, 5, 7, 30), [1]);
|
|
44
|
+
expect(events).toHaveLength(1);
|
|
45
|
+
expect(events[0]!.fields).toMatchObject({
|
|
46
|
+
event: "ci.stale",
|
|
47
|
+
summary: `main has had no green commit for 7 hours: 3 commits since ${sha(2).slice(0, 12)}, above the green ${sha(1).slice(0, 12)}`,
|
|
48
|
+
ci: { branch: "main", commit: sha(4), since: sha(2), lastGreen: sha(1), hours: 7 },
|
|
49
|
+
run: { commit: sha(4) },
|
|
50
|
+
});
|
|
51
|
+
expect(events[0]!.stale).toEqual({ since: sha(2), lastGreen: sha(1), at: "2026-10-20T12:00:00Z" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("nothing before staleAfter, with a green tip, or without staleAfter", () => {
|
|
55
|
+
expect(decide(walkOf(1, 5, 30), [1]).events).toEqual([]);
|
|
56
|
+
expect(decide(walkOf(10, 30), [2]).events).toEqual([]);
|
|
57
|
+
expect(decide(walkOf(1, 7, 30), [1], { staleAfter: null }).events).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("with no green commit in the walk, the stretch starts at the oldest commit the tick judged", () => {
|
|
61
|
+
const judged = (s: string) => s !== sha(1);
|
|
62
|
+
// 1 (100 hours ago) was never judged, so the stretch is 3 and 2, from 8 hours ago.
|
|
63
|
+
const { events } = decide(walkOf(1, 8, 100), [], { judged });
|
|
64
|
+
expect(events[0]!.fields.ci).toEqual({ branch: "main", commit: sha(3), since: sha(2), hours: 8 });
|
|
65
|
+
expect(decide(walkOf(1, 8, 100), [], { judged: () => false }).events).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("an open stretch is told once, however long it lasts and wherever its first commit has gone", () => {
|
|
69
|
+
const open = { since: sha(2), lastGreen: sha(1), at: hoursAgo(1) };
|
|
70
|
+
expect(decide(walkOf(1, 5, 7, 30), [1], { stale: open }).events).toEqual([]);
|
|
71
|
+
// No green commit within the walk: still the same stretch.
|
|
72
|
+
expect(decide(walkOf(1, 5, 7), [], { stale: { ...open, since: sha(99) } }).events).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("a newer green commit ends the stretch with ci.green naming its since", () => {
|
|
76
|
+
const open = { since: sha(2), lastGreen: sha(1), at: hoursAgo(1) };
|
|
77
|
+
// 3 turned green.
|
|
78
|
+
const { events, endedBy } = decide(walkOf(1, 5, 7, 30), [1, 3], { stale: open });
|
|
79
|
+
expect(endedBy).toBeUndefined();
|
|
80
|
+
expect(events.map((e) => [e.fields.event, e.fields.ci])).toEqual([["ci.green", { branch: "main", commit: sha(3), since: sha(2) }]]);
|
|
81
|
+
expect(events[0]!.stale).toEqual({ ...open, ended: sha(3) });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("when the tick sends ci.green anyway, that one ends the stretch and no second is sent", () => {
|
|
85
|
+
const open = { since: sha(2), lastGreen: sha(1), at: hoursAgo(1) };
|
|
86
|
+
const { events, endedBy } = decide(walkOf(1, 5, 7, 30), [1, 4], { stale: open, answering: sha(4) });
|
|
87
|
+
expect(events).toEqual([]);
|
|
88
|
+
expect(endedBy).toEqual({ ...open, ended: sha(4) });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("an ended stretch doesn't hold back the next one", () => {
|
|
92
|
+
const ended = { since: sha(2), lastGreen: sha(1), at: hoursAgo(20), ended: sha(3) };
|
|
93
|
+
// 3 was green; 4 and 5 came after it, 4 nine hours ago.
|
|
94
|
+
const { events } = decide(walkOf(2, 9, 12, 13, 30), [1, 3], { stale: ended });
|
|
95
|
+
expect(events.map((e) => [e.fields.event, e.fields.ci?.since])).toEqual([["ci.stale", sha(4)]]);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// ── through the tick ─────────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
const NOTIFY = { webhook: "HOOK_URL", key: "HOOK_KEY", staleAfter: 6 };
|
|
102
|
+
const DECLARED = { branch: "main", phases: { lint: ["lint"], test: ["test"] }, require: ["lint", "test"], notify: NOTIFY };
|
|
103
|
+
|
|
104
|
+
function commitAt(root: string, hours: number, file: string): string {
|
|
105
|
+
writeFiles(root, { [file]: `${file} ${hours}\n` });
|
|
106
|
+
const env = { ...process.env, GIT_AUTHOR_DATE: hoursAgo(hours), GIT_COMMITTER_DATE: hoursAgo(hours) };
|
|
107
|
+
const g = (...args: string[]) => execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", ...args], { cwd: root, env, stdio: ["ignore", "pipe", "pipe"] });
|
|
108
|
+
g("add", "-A");
|
|
109
|
+
g("commit", "-q", "-m", file);
|
|
110
|
+
return git(root, "rev-parse", "HEAD");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function workspace(green: unknown = DECLARED): string {
|
|
114
|
+
const origin = scratchDir("chant-stale-origin-");
|
|
115
|
+
git(origin, "init", "-q", "--bare");
|
|
116
|
+
const root = scratchDir("chant-stale-work-");
|
|
117
|
+
git(root, "init", "-q");
|
|
118
|
+
git(root, "symbolic-ref", "HEAD", "refs/heads/main");
|
|
119
|
+
writeFiles(root, { "chant.workspace.json": declaration([{ name: "app", dir: "app", kind: "other", because: "the app" }], { ci: { green } }), "app/a.txt": "a\n" });
|
|
120
|
+
git(root, "remote", "add", "origin", origin);
|
|
121
|
+
return root;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let id = 1;
|
|
125
|
+
const run = (name: string, conclusion: string | null): CheckRun => ({ id: id++, name, status: conclusion === null ? "in_progress" : "completed", conclusion, completedAt: null, url: null });
|
|
126
|
+
const pass = () => [run("lint", "success"), run("test", "success")];
|
|
127
|
+
const stuck = () => [run("lint", "success"), run("test", null)];
|
|
128
|
+
|
|
129
|
+
function sink() {
|
|
130
|
+
const sent: NotifyEvent[] = [];
|
|
131
|
+
const send = async (config: NotifyConfig | undefined, e: NotifyEvent | undefined) => {
|
|
132
|
+
if (!config || !e) return [];
|
|
133
|
+
sent.push(e);
|
|
134
|
+
return [{ target: "webhook" as const, ok: true, detail: "delivered" }];
|
|
135
|
+
};
|
|
136
|
+
return { sent, send };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const tick = (root: string, runs: Map<string, CheckRun[]>, s: ReturnType<typeof sink>, now: Date, more: { dryRun?: boolean } = {}) =>
|
|
140
|
+
ciTick({ cwd: root, forge: { kind: "github", checkRuns: async (c) => runs.get(c) ?? [] }, now, env: {}, sendNotify: s.send, ...more });
|
|
141
|
+
|
|
142
|
+
describe("ci.stale through the tick (#4678)", () => {
|
|
143
|
+
test("staleAfter is read with notify's settings, and must be more than 0 hours", () => {
|
|
144
|
+
expect(readGreen(workspace()).green.notify).toEqual(NOTIFY);
|
|
145
|
+
for (const staleAfter of [0, "6h"]) expect(() => readGreen(workspace({ ...DECLARED, notify: { ...NOTIFY, staleAfter } }))).toThrow(/staleAfter/);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
/** a is green; b, 4 hours old at NOW, has a run that never finishes. */
|
|
149
|
+
function stuckBranch() {
|
|
150
|
+
const root = workspace();
|
|
151
|
+
const a = commitAt(root, 10, "app/a.txt");
|
|
152
|
+
const b = commitAt(root, 4, "app/b.txt");
|
|
153
|
+
git(root, "push", "-q", "origin", "main");
|
|
154
|
+
const runs = new Map([
|
|
155
|
+
[a, pass()],
|
|
156
|
+
[b, stuck()],
|
|
157
|
+
]);
|
|
158
|
+
return { root, a, b, runs };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
test("later ticks with no new commit send ci.stale once, marked in the branch's record", async () => {
|
|
162
|
+
const { root, a, b, runs } = stuckBranch();
|
|
163
|
+
const s = sink();
|
|
164
|
+
await tick(root, runs, s, NOW);
|
|
165
|
+
expect(s.sent).toEqual([]);
|
|
166
|
+
// Three hours on, nothing has landed and b is still running.
|
|
167
|
+
const dry = await tick(root, runs, s, later(3), { dryRun: true });
|
|
168
|
+
expect(dry.notified).toEqual([{ event: "ci.stale", commit: b, sent: false }]);
|
|
169
|
+
const told = await tick(root, runs, s, later(3));
|
|
170
|
+
expect(s.sent.map((e) => [e.event, e.ci])).toEqual([["ci.stale", { branch: "main", commit: b, since: b, lastGreen: a, hours: 7 }]]);
|
|
171
|
+
expect(told.recorded).toContain("_ci/branch/main.json");
|
|
172
|
+
expect(readCiBranchRecord(root, "main")?.stale).toEqual({ since: b, lastGreen: a, at: hoursAgo(-3) });
|
|
173
|
+
await tick(root, runs, s, later(5));
|
|
174
|
+
expect(s.sent).toHaveLength(1);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("a newer green commit ends the stretch with one ci.green naming since", async () => {
|
|
178
|
+
const { root, b, runs } = stuckBranch();
|
|
179
|
+
const s = sink();
|
|
180
|
+
await tick(root, runs, s, later(3));
|
|
181
|
+
const c = commitAt(root, -6, "app/c.txt");
|
|
182
|
+
git(root, "push", "-q", "origin", "main");
|
|
183
|
+
runs.set(c, pass());
|
|
184
|
+
await tick(root, runs, s, later(7));
|
|
185
|
+
expect(s.sent.map((e) => [e.event, e.ci?.commit, e.ci?.since])).toEqual([
|
|
186
|
+
["ci.stale", b, b],
|
|
187
|
+
["ci.green", c, b],
|
|
188
|
+
]);
|
|
189
|
+
expect(readCiBranchRecord(root, "main")?.stale?.ended).toBe(c);
|
|
190
|
+
await tick(root, runs, s, later(8));
|
|
191
|
+
expect(s.sent).toHaveLength(2);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -220,6 +220,15 @@ describe("chant ci workflow (#3573)", () => {
|
|
|
220
220
|
}
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
+
test("ci.green.notify's variables reach the tick from secrets of the same names (#4645)", () => {
|
|
224
|
+
const told = parseDeclaration(JSON.stringify({ name: "w", schema: 1, members: [], ci: { green: { ...GREEN, notify: { webhook: "CI_HOOK", key: "CI_HOOK_KEY", slack: "CI_SLACK" } } } }), "chant.workspace.json").ci!.green!;
|
|
225
|
+
const env = (parseYAMLDocument(renderCiGreenWorkflow({ green: told, workflows: ["ci"], chantVersion: "0.124.61", workspaceRoot: "." })) as Yaml).jobs.tick.steps.at(-1).env;
|
|
226
|
+
expect(env).toMatchObject({ CI_HOOK: "${{ secrets.CI_HOOK }}", CI_HOOK_KEY: "${{ secrets.CI_HOOK_KEY }}", CI_SLACK: "${{ secrets.CI_SLACK }}" });
|
|
227
|
+
// Without notify the step is as it was.
|
|
228
|
+
const plain = (parseYAMLDocument(renderCiGreenWorkflow({ green, workflows: ["ci"], chantVersion: "0.124.61", workspaceRoot: "." })) as Yaml).jobs.tick.steps.at(-1).env;
|
|
229
|
+
expect(Object.keys(plain).sort()).toEqual(["GITHUB_TOKEN", "GIT_COMMITTER_EMAIL", "GIT_COMMITTER_NAME"]);
|
|
230
|
+
});
|
|
231
|
+
|
|
223
232
|
test("mergeQueue writes the verdict workflow and adds merge_group to the phases' workflows, byte-identically again (#4644)", async () => {
|
|
224
233
|
const root = scratchDir("chant-ci-workflow-");
|
|
225
234
|
git(root, "init", "-q");
|
|
@@ -295,6 +295,8 @@ export function renderCiGreenWorkflow(input: WorkflowInput): string {
|
|
|
295
295
|
" GIT_COMMITTER_NAME: github-actions[bot]",
|
|
296
296
|
" GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com",
|
|
297
297
|
...(input.runnerKeySecret ? [` CHANT_RUNNER_KEY: \${{ secrets.${input.runnerKeySecret} }}`] : []),
|
|
298
|
+
// #4645: each variable ci.green.notify names, from the repository secret of the same name, as chant run --generate maps an Op waves spec's.
|
|
299
|
+
...notifyVariables(green).map((v) => ` ${v}: \${{ secrets.${v} }}`),
|
|
298
300
|
` run: ${tick}`,
|
|
299
301
|
];
|
|
300
302
|
return tagComments(lines.join("\n") + "\n");
|
|
@@ -345,6 +347,13 @@ export function renderMergeQueueWorkflow(input: Omit<WorkflowInput, "workflows"
|
|
|
345
347
|
return tagComments(lines.join("\n") + "\n");
|
|
346
348
|
}
|
|
347
349
|
|
|
350
|
+
/** The variables `ci.green.notify` names (#4645), sorted and once each: the tick's step reads them from secrets. */
|
|
351
|
+
export function notifyVariables(green: CiGreen): string[] {
|
|
352
|
+
const n = green.notify;
|
|
353
|
+
if (!n) return [];
|
|
354
|
+
return [...new Set([n.webhook, n.key, n.slack, n.teams].filter((v): v is string => typeof v === "string"))].sort();
|
|
355
|
+
}
|
|
356
|
+
|
|
348
357
|
/** Whether any phase sets `build` (#4169): then the tick may re-run jobs and start workflows. */
|
|
349
358
|
export const declaresBuild = (green: CiGreen) => green.phases.some((p) => p.build !== undefined);
|
|
350
359
|
/** Whether a required phase builds only the newest commit (#4169). */
|
|
@@ -56,14 +56,15 @@
|
|
|
56
56
|
import { judgeCommits, mergeCommits, readWorkIndex, type CommitLink } from "./commit-links";
|
|
57
57
|
import { execFileSync } from "node:child_process";
|
|
58
58
|
import { greenBranches, laneOf, laneTagPrefixes, readDeclaration, readerVersion, WORKSPACE_ERROR_CODES, WorkspaceReadError, type CiGreen, type CiPhase, type CiSource } from "./declaration";
|
|
59
|
-
import { NEXT_RELEASE } from "../release-floors";
|
|
60
59
|
import { makeNotifyEvent, sendNotify, type NotifyFields } from "../notify";
|
|
60
|
+
import { lifecycleRemoteOverride } from "../lifecycle/ledger-remote";
|
|
61
61
|
import type { CheckRun, CiForge, OpRunRef } from "./ci-green-forge";
|
|
62
62
|
import type { OpRunRecord } from "../op/runtime";
|
|
63
63
|
import { readRunLedger } from "../lifecycle/run-ledger";
|
|
64
64
|
import { fetchLifecycleStatus, listFilesInDir, listLedgerTrees, pushLifecycleStatus, writeLedgerFiles } from "../lifecycle/git";
|
|
65
65
|
import { ledgerRecordingOff } from "../lifecycle/no-record";
|
|
66
|
-
import {
|
|
66
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
67
|
+
import { agedOut, branchRecordPath, buildRequestAnnotation, CI_BUILD_TAG_PREFIX, CI_LEDGER_REF, planBuilds, readBuildRequests, readCiBranchRecord, readCiRecords, recordOf, recordPath, requestedBuild, sameRecord, type BuildRequest, type CiBranchRecord, type CiRecord } from "./ci-builds";
|
|
67
68
|
import { dispatchableWorkflows, MERGE_QUEUE_VERDICT_JOB, readWorkflowSources } from "./ci-green-workflow";
|
|
68
69
|
import { signOpRunRecord, verifyOpRunStatement } from "./trust/op-run-statement";
|
|
69
70
|
import type { ReasonCode } from "./reason-codes";
|
|
@@ -81,11 +82,15 @@ export const RUNNER_KEY_ENV = "CHANT_RUNNER_KEY";
|
|
|
81
82
|
export const CI_GREEN_TAG_PREFIX = "ci/green/";
|
|
82
83
|
export const CI_REVOKED_TAG_PREFIX = "ci/revoked/";
|
|
83
84
|
/** The first chant that reads and writes green lanes, `ci.green.lanes` (#4662). */
|
|
84
|
-
export const CI_GREEN_LANES_FLOOR =
|
|
85
|
+
export const CI_GREEN_LANES_FLOOR = "0.124.61";
|
|
85
86
|
/** The first chant whose tick sends `ci.red`, `ci.culprit` and `ci.green` through `ci.green.notify` (#4645). */
|
|
86
|
-
export const CI_TICK_NOTIFY_FLOOR =
|
|
87
|
+
export const CI_TICK_NOTIFY_FLOOR = "0.124.61";
|
|
88
|
+
/** The first chant whose tick sends `ci.stale` after `ci.green.notify.staleAfter` hours without a green commit (#4678). */
|
|
89
|
+
export const CI_STALE_NOTIFY_FLOOR = NEXT_RELEASE;
|
|
90
|
+
/** How many first-parent commits the tick reads back looking for the newest green one, for `ci.stale` (#4678). */
|
|
91
|
+
export const CI_STALE_WALK = 200;
|
|
87
92
|
/** The first chant that writes a merge queue's trigger and verdict job, and reads `chant ci verdict` (#4644). */
|
|
88
|
-
export const CI_MERGE_QUEUE_FLOOR =
|
|
93
|
+
export const CI_MERGE_QUEUE_FLOOR = "0.124.61";
|
|
89
94
|
|
|
90
95
|
export const CI_LAST_GREEN_CONTRACT_VERSION = 1;
|
|
91
96
|
export const CI_LAST_GREEN_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/ci-last-green/v1/ci-last-green.schema.json";
|
|
@@ -807,7 +812,35 @@ export async function ciTick(req: TickRequest): Promise<TickResult> {
|
|
|
807
812
|
// #4645: what to tell people, decided from the records this tick writes. Without records a tick can't
|
|
808
813
|
// remember what it sent, so it sends nothing rather than the same event every time.
|
|
809
814
|
const canRecord = ledgerOk && !ledgerRecordingOff();
|
|
810
|
-
const events
|
|
815
|
+
const events: { fields: NotifyFields; mark?: ReturnType<typeof tickEvents>[number]["mark"]; stale?: CiBranchRecord["stale"] }[] =
|
|
816
|
+
green.notify && canRecord ? tickEvents({ green, planned, records, builds, requests, now }) : [];
|
|
817
|
+
// #4678: ci.stale, from the tags as this tick leaves them, and the ci.green that ends its stretch.
|
|
818
|
+
const branchBefore = green.notify && canRecord ? readCiBranchRecord(top, green.branch) : undefined;
|
|
819
|
+
let branchAfter = branchBefore;
|
|
820
|
+
if (green.notify && canRecord && (green.notify.staleAfter !== undefined || (branchBefore?.stale && !branchBefore.stale.ended))) {
|
|
821
|
+
const greenNow = new Set(tags.green.keys());
|
|
822
|
+
const revokedNow = new Set(tags.revoked.keys());
|
|
823
|
+
for (const c of planned) {
|
|
824
|
+
if (c.made?.tag === `${CI_GREEN_TAG_PREFIX}${c.sha}`) greenNow.add(c.sha);
|
|
825
|
+
if (c.made?.tag === `${CI_REVOKED_TAG_PREFIX}${c.sha}`) revokedNow.add(c.sha);
|
|
826
|
+
}
|
|
827
|
+
const inWindow = new Set(planned.map((c) => c.sha));
|
|
828
|
+
const answering = events.find((e) => e.fields.event === "ci.green");
|
|
829
|
+
const stale = staleEvents({
|
|
830
|
+
green,
|
|
831
|
+
walk: firstParents(top, tracking, CI_STALE_WALK),
|
|
832
|
+
isGreen: (sha) => greenNow.has(sha) && !revokedNow.has(sha),
|
|
833
|
+
judged: (sha) => inWindow.has(sha) || records.has(sha),
|
|
834
|
+
stale: branchBefore?.stale,
|
|
835
|
+
answering: answering?.fields.ci!.commit,
|
|
836
|
+
now,
|
|
837
|
+
});
|
|
838
|
+
if (stale.endedBy && answering) {
|
|
839
|
+
answering.fields = { ...answering.fields, ci: { ...answering.fields.ci!, since: stale.endedBy.since } };
|
|
840
|
+
answering.stale = stale.endedBy;
|
|
841
|
+
}
|
|
842
|
+
events.push(...stale.events);
|
|
843
|
+
}
|
|
811
844
|
const notified: TickResult["notified"] = [];
|
|
812
845
|
const marks = new Map<string, NonNullable<CiRecord["notified"]>>();
|
|
813
846
|
for (const e of events) {
|
|
@@ -824,12 +857,15 @@ export async function ciTick(req: TickRequest): Promise<TickResult> {
|
|
|
824
857
|
continue;
|
|
825
858
|
}
|
|
826
859
|
notified.push({ event: e.fields.event, commit: e.fields.ci!.commit, sent: deliveries.length > 0 });
|
|
827
|
-
marks.set(e.mark.sha, { ...(marks.get(e.mark.sha) ?? {}), ...e.mark.notified });
|
|
860
|
+
if (e.mark) marks.set(e.mark.sha, { ...(marks.get(e.mark.sha) ?? {}), ...e.mark.notified });
|
|
861
|
+
if (e.stale) branchAfter = { schema: 1, branch: green.branch, stale: e.stale };
|
|
828
862
|
}
|
|
829
863
|
let recorded: string[] = [];
|
|
830
864
|
if (!req.dryRun) {
|
|
831
865
|
const asked = await askForBuilds({ top, remote, green, forge, builds, requests, records, planned, warnings });
|
|
832
|
-
recorded = canRecord
|
|
866
|
+
recorded = canRecord
|
|
867
|
+
? await writeRecords({ top, green, planned, records, builds, requests: asked.live, dispatched: asked.dispatched, now, warnings, notified: marks, branchRecord: branchAfter !== branchBefore ? branchAfter : undefined })
|
|
868
|
+
: [];
|
|
833
869
|
}
|
|
834
870
|
return {
|
|
835
871
|
branch: green.branch,
|
|
@@ -910,6 +946,97 @@ export function tickEvents(input: {
|
|
|
910
946
|
return out;
|
|
911
947
|
}
|
|
912
948
|
|
|
949
|
+
/** A first-parent commit and when it was committed, ISO 8601. */
|
|
950
|
+
export interface StaleWalkCommit {
|
|
951
|
+
sha: string;
|
|
952
|
+
committed: string;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/** `ref`'s first-parent commits, newest first, `max` at most, with their commit times. */
|
|
956
|
+
function firstParents(top: string, ref: string, max: number): StaleWalkCommit[] {
|
|
957
|
+
return git(top, ["log", "--first-parent", `--max-count=${max}`, "--format=%H %ct", ref])
|
|
958
|
+
.split("\n")
|
|
959
|
+
.filter(Boolean)
|
|
960
|
+
.map((line) => line.split(" "))
|
|
961
|
+
.map(([sha, ct]) => ({ sha: sha!, committed: iso(new Date(Number(ct) * 1000)) }));
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* `ci.stale` and the `ci.green` that ends its stretch (#4678). The red
|
|
966
|
+
* stretch is the first-parent commits above the newest green one in `walk`;
|
|
967
|
+
* with no green one there, the commits down to the oldest the tick judged,
|
|
968
|
+
* so commits from before the tick ran don't count. When the stretch's
|
|
969
|
+
* oldest commit (`since`) was committed `staleAfter` hours ago or more and
|
|
970
|
+
* the branch's record has no open stretch, it sends `ci.stale` and opens
|
|
971
|
+
* one. An open stretch whose `since` is no longer above the newest green
|
|
972
|
+
* commit has ended: the `ci.green` the tick sends anyway (`answering`)
|
|
973
|
+
* names `since` and closes it (`endedBy`), or else this sends a `ci.green`
|
|
974
|
+
* for the newest green commit. Each event carries the branch record's
|
|
975
|
+
* `stale` as it is once the event is told. Pure.
|
|
976
|
+
*/
|
|
977
|
+
export function staleEvents(input: {
|
|
978
|
+
green: CiGreen;
|
|
979
|
+
/** The branch's first-parent commits, newest first. */
|
|
980
|
+
walk: readonly StaleWalkCommit[];
|
|
981
|
+
/** A green tag, this tick's included, and no revoked one. */
|
|
982
|
+
isGreen: (sha: string) => boolean;
|
|
983
|
+
/** The tick judged it: it is in the window or has a record. */
|
|
984
|
+
judged: (sha: string) => boolean;
|
|
985
|
+
/** The branch record's `stale`. */
|
|
986
|
+
stale: CiBranchRecord["stale"];
|
|
987
|
+
/** The commit of the `ci.green` the tick sends anyway, if it does. */
|
|
988
|
+
answering?: string;
|
|
989
|
+
now: Date;
|
|
990
|
+
}): { events: { fields: NotifyFields; stale: NonNullable<CiBranchRecord["stale"]> }[]; endedBy?: NonNullable<CiBranchRecord["stale"]> } {
|
|
991
|
+
const { green, walk, now } = input;
|
|
992
|
+
const branch = green.branch;
|
|
993
|
+
const at = walk.findIndex((c) => input.isGreen(c.sha));
|
|
994
|
+
const lastGreen = at >= 0 ? walk[at]!.sha : null;
|
|
995
|
+
let end = at;
|
|
996
|
+
if (at < 0) for (let i = 0; i < walk.length; i++) if (input.judged(walk[i]!.sha)) end = i + 1;
|
|
997
|
+
const stretch = walk.slice(0, Math.max(end, 0));
|
|
998
|
+
const out: ReturnType<typeof staleEvents> = { events: [] };
|
|
999
|
+
const short = (sha: string) => sha.slice(0, 12);
|
|
1000
|
+
let open = input.stale && !input.stale.ended ? input.stale : undefined;
|
|
1001
|
+
if (open && lastGreen && !stretch.some((c) => c.sha === open!.since)) {
|
|
1002
|
+
const ended = { ...open, ended: input.answering ?? lastGreen };
|
|
1003
|
+
if (input.answering) out.endedBy = ended;
|
|
1004
|
+
else {
|
|
1005
|
+
out.events.push({
|
|
1006
|
+
fields: {
|
|
1007
|
+
source: "chant",
|
|
1008
|
+
event: "ci.green",
|
|
1009
|
+
summary: `${branch} is green again at ${short(lastGreen)}, after no green commit since ${short(open.since)}`,
|
|
1010
|
+
targets: [],
|
|
1011
|
+
ci: { branch, commit: lastGreen, since: open.since },
|
|
1012
|
+
run: { commit: lastGreen },
|
|
1013
|
+
},
|
|
1014
|
+
stale: ended,
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
open = undefined;
|
|
1018
|
+
}
|
|
1019
|
+
const staleAfter = green.notify?.staleAfter;
|
|
1020
|
+
const since = stretch.at(-1);
|
|
1021
|
+
if (open || staleAfter === undefined || !since) return out;
|
|
1022
|
+
const age = now.getTime() - Date.parse(since.committed);
|
|
1023
|
+
if (age < staleAfter * 3_600_000) return out;
|
|
1024
|
+
const hours = Math.floor(age / 3_600_000);
|
|
1025
|
+
const tip = walk[0]!.sha;
|
|
1026
|
+
out.events.push({
|
|
1027
|
+
fields: {
|
|
1028
|
+
source: "chant",
|
|
1029
|
+
event: "ci.stale",
|
|
1030
|
+
summary: `${branch} has had no green commit for ${hours} hours: ${stretch.length} commit${stretch.length === 1 ? "" : "s"} since ${short(since.sha)}${lastGreen ? `, above the green ${short(lastGreen)}` : ""}`,
|
|
1031
|
+
targets: [],
|
|
1032
|
+
ci: { branch, commit: tip, since: since.sha, ...(lastGreen ? { lastGreen } : {}), hours },
|
|
1033
|
+
run: { commit: tip },
|
|
1034
|
+
},
|
|
1035
|
+
stale: { since: since.sha, lastGreen, at: iso(now) },
|
|
1036
|
+
});
|
|
1037
|
+
return out;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
913
1040
|
/** The tick's environment for an event's run fields: its repository and forge, without the tick's own run link, which says nothing about the commit. */
|
|
914
1041
|
function tickEventEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
915
1042
|
const { GITHUB_RUN_ID: _r, CI_JOB_URL: _j, CI_PIPELINE_URL: _p, GITHUB_SHA: _s, CI_COMMIT_SHA: _c, ...rest } = env;
|
|
@@ -1016,6 +1143,8 @@ async function writeRecords(input: {
|
|
|
1016
1143
|
warnings: string[];
|
|
1017
1144
|
/** What the tick told people this time (#4645), merged into each commit's `notified`. */
|
|
1018
1145
|
notified?: ReadonlyMap<string, NonNullable<CiRecord["notified"]>>;
|
|
1146
|
+
/** The branch's record, when what it told about a stretch changed (#4678). */
|
|
1147
|
+
branchRecord?: CiBranchRecord;
|
|
1019
1148
|
}): Promise<string[]> {
|
|
1020
1149
|
const { top, green, planned, records, builds, requests, now, warnings } = input;
|
|
1021
1150
|
const writes: { path: string; content: string }[] = [];
|
|
@@ -1036,6 +1165,7 @@ async function writeRecords(input: {
|
|
|
1036
1165
|
if (inWindow.has(sha) || r.state !== "pending") continue;
|
|
1037
1166
|
writes.push({ path: recordPath(sha), content: `${JSON.stringify(agedOut(r, now), null, 2)}\n` });
|
|
1038
1167
|
}
|
|
1168
|
+
if (input.branchRecord) writes.push({ path: branchRecordPath(input.branchRecord.branch), content: `${JSON.stringify(input.branchRecord, null, 2)}\n` });
|
|
1039
1169
|
if (writes.length === 0) return [];
|
|
1040
1170
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
1041
1171
|
try {
|
|
@@ -1468,7 +1598,8 @@ export type CiBaseDocument =
|
|
|
1468
1598
|
* job that failed. A commit with no record (outside the tick's window)
|
|
1469
1599
|
* counts when it has a green tag and no revoked one, as `ci last-green`
|
|
1470
1600
|
* reads them. Reads local refs only: the records on `chant/lifecycle`, or
|
|
1471
|
-
* on `origin/chant/lifecycle`
|
|
1601
|
+
* on `origin/chant/lifecycle` (or the remote `CHANT_LIFECYCLE_REMOTE`
|
|
1602
|
+
* names) when there is no local branch, and the tags.
|
|
1472
1603
|
*/
|
|
1473
1604
|
export function ciBase(req: { cwd: string; from?: string; branch?: string; phase?: string; lane?: string; remote?: string }): CiBaseDocument {
|
|
1474
1605
|
const head = { $schema: CI_LAST_GREEN_SCHEMA_ID, contract: CI_LAST_GREEN_CONTRACT_VERSION, chant: readerVersion() };
|
|
@@ -1488,7 +1619,7 @@ export function ciBase(req: { cwd: string; from?: string; branch?: string; phase
|
|
|
1488
1619
|
}
|
|
1489
1620
|
const branchRef = tryGit(top, ["rev-parse", "--verify", "--quiet", `refs/remotes/${req.remote ?? "origin"}/${green.branch}^{commit}`]) ?? tryGit(top, ["rev-parse", "--verify", "--quiet", `refs/heads/${green.branch}^{commit}`]);
|
|
1490
1621
|
const tags = readCiTags(top, green, branchRef, lane?.name);
|
|
1491
|
-
const ledger = tryGit(top, ["rev-parse", "--verify", "--quiet", CI_LEDGER_REF]) !== null ? CI_LEDGER_REF : `refs/remotes/${req.remote ?? "origin"}/chant/lifecycle`;
|
|
1622
|
+
const ledger = tryGit(top, ["rev-parse", "--verify", "--quiet", CI_LEDGER_REF]) !== null ? CI_LEDGER_REF : `refs/remotes/${lifecycleRemoteOverride() ?? req.remote ?? "origin"}/chant/lifecycle`;
|
|
1492
1623
|
const records = readCiRecords(top, ledger);
|
|
1493
1624
|
const phases = req.phase !== undefined ? [req.phase] : (lane?.require ?? green.require);
|
|
1494
1625
|
const builtHere = (r: CiRecord) =>
|