@intentius/chant 0.124.76 → 0.124.78
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/__fixtures__/agent-guard/plywood.d.ts +8 -0
- package/dist/__fixtures__/agent-guard/plywood.d.ts.map +1 -0
- package/dist/__fixtures__/agent-guard/plywood.js +19 -0
- package/dist/__fixtures__/agent-guard/terragucci.d.ts +8 -0
- package/dist/__fixtures__/agent-guard/terragucci.d.ts.map +1 -0
- package/dist/__fixtures__/agent-guard/terragucci.js +30 -0
- package/dist/__fixtures__/gated-ledger.d.ts +10 -0
- package/dist/__fixtures__/gated-ledger.d.ts.map +1 -0
- package/dist/__fixtures__/gated-ledger.js +51 -0
- package/dist/__fixtures__/notify-messages/events.d.ts +9 -0
- package/dist/__fixtures__/notify-messages/events.d.ts.map +1 -0
- package/dist/__fixtures__/notify-messages/events.js +21 -0
- package/dist/__fixtures__/product-words.d.ts +14 -0
- package/dist/__fixtures__/product-words.d.ts.map +1 -1
- package/dist/__fixtures__/product-words.js +11 -0
- package/dist/__fixtures__/terragucci-notify.d.ts +66 -0
- package/dist/__fixtures__/terragucci-notify.d.ts.map +1 -0
- package/dist/__fixtures__/terragucci-notify.js +133 -0
- package/dist/action-pins.d.ts +8 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +9 -0
- package/dist/agent-guard.d.ts +143 -0
- package/dist/agent-guard.d.ts.map +1 -0
- package/dist/agent-guard.js +455 -0
- package/dist/ci-commit.d.ts +120 -5
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +214 -23
- package/dist/ci-own-jobs.d.ts +81 -0
- package/dist/ci-own-jobs.d.ts.map +1 -0
- package/dist/ci-own-jobs.js +233 -0
- package/dist/ci-product-words.d.ts +18 -4
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +26 -6
- package/dist/ci-product.d.ts +40 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +40 -1
- package/dist/cli/handlers/approve.d.ts +5 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +17 -11
- package/dist/cli/handlers/build.d.ts +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +88 -2
- package/dist/cli/handlers/commit.d.ts.map +1 -1
- package/dist/cli/handlers/commit.js +3 -1
- package/dist/cli/handlers/notify-relay.d.ts +18 -1
- package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
- package/dist/cli/handlers/notify-relay.js +90 -14
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +3 -1
- package/dist/cli/handlers/release.d.ts +5 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +21 -9
- package/dist/cli/handlers/run-generate.d.ts.map +1 -1
- package/dist/cli/handlers/run-generate.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +21 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +60 -4
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/pr-env-components.d.ts +65 -0
- package/dist/components/pr-env-components.d.ts.map +1 -0
- package/dist/components/pr-env-components.js +162 -0
- package/dist/components/pr-policy.d.ts +15 -0
- package/dist/components/pr-policy.d.ts.map +1 -1
- package/dist/components/pr-policy.js +24 -1
- package/dist/components/release-compile.d.ts +15 -3
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +66 -15
- package/dist/config.d.ts +14 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -1
- package/dist/gate-policy.d.ts +14 -1
- package/dist/gate-policy.d.ts.map +1 -1
- package/dist/gate-policy.js +16 -6
- package/dist/lexicon.d.ts +25 -1
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +10 -0
- package/dist/lifecycle/gated-op.d.ts +95 -0
- package/dist/lifecycle/gated-op.d.ts.map +1 -0
- package/dist/lifecycle/gated-op.js +96 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +83 -2
- package/dist/lifecycle/release-images.d.ts +77 -3
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +132 -6
- package/dist/notify-product.d.ts +11 -2
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +16 -4
- package/dist/notify-relay-repo.d.ts +131 -0
- package/dist/notify-relay-repo.d.ts.map +1 -0
- package/dist/notify-relay-repo.js +202 -0
- package/dist/notify-relay.d.ts +25 -1
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +27 -2
- package/dist/notify.d.ts +36 -4
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +31 -21
- package/dist/notify.schema.json +1 -0
- package/dist/op/activities/review-product.d.ts +111 -0
- package/dist/op/activities/review-product.d.ts.map +1 -0
- package/dist/op/activities/review-product.js +116 -0
- package/dist/op/op-waves-capability.js +2 -2
- package/dist/policy-engine.d.ts +95 -0
- package/dist/policy-engine.d.ts.map +1 -0
- package/dist/policy-engine.js +157 -0
- package/dist/pr-forge-reads.d.ts +124 -0
- package/dist/pr-forge-reads.d.ts.map +1 -0
- package/dist/pr-forge-reads.js +322 -0
- package/dist/pr-forge.d.ts +14 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +21 -13
- package/dist/pr-plan-note.d.ts +293 -0
- package/dist/pr-plan-note.d.ts.map +1 -0
- package/dist/pr-plan-note.js +362 -0
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +9 -1
- package/dist/state-export.d.ts +126 -0
- package/dist/state-export.d.ts.map +1 -0
- package/dist/state-export.js +156 -0
- package/dist/state-migration.d.ts +148 -0
- package/dist/state-migration.d.ts.map +1 -0
- package/dist/state-migration.js +146 -0
- package/dist/state-unlock.d.ts +167 -0
- package/dist/state-unlock.d.ts.map +1 -0
- package/dist/state-unlock.js +196 -0
- package/dist/wave-runtime.mjs +332 -332
- package/dist/workspace/declaration.schema.json +1 -1
- package/dist/workspace/release-workflow.d.ts +10 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +10 -4
- package/package.json +1 -1
- package/src/__fixtures__/agent-guard/plywood.ts +27 -0
- package/src/__fixtures__/agent-guard/terragucci.ts +39 -0
- package/src/__fixtures__/gated-ledger.ts +58 -0
- package/src/__fixtures__/notify-messages/events.ts +23 -0
- package/src/__fixtures__/notify-messages/messages.json +50 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.golden.md +53 -0
- package/src/__fixtures__/pr-loop/terragucci-plan.note.json +83 -0
- package/src/__fixtures__/product-words.ts +12 -0
- package/src/__fixtures__/review-agent/terragucci-review.json +94 -0
- package/src/__fixtures__/terragucci-notify.ts +170 -0
- package/src/action-pins.test.ts +12 -1
- package/src/action-pins.ts +11 -0
- package/src/agent-guard.test.ts +319 -0
- package/src/agent-guard.ts +547 -0
- package/src/ci-commit.test.ts +213 -2
- package/src/ci-commit.ts +258 -27
- package/src/ci-own-jobs.test.ts +108 -0
- package/src/ci-own-jobs.ts +252 -0
- package/src/ci-product-words.ts +35 -7
- package/src/ci-product.ts +81 -1
- package/src/cli/handlers/approve-cwd.test.ts +112 -0
- package/src/cli/handlers/approve.ts +22 -11
- package/src/cli/handlers/build-own-jobs.test.ts +80 -0
- package/src/cli/handlers/build-pr-loop-control.test.ts +87 -0
- package/src/cli/handlers/build-run-group.test.ts +59 -0
- package/src/cli/handlers/build.ts +83 -3
- package/src/cli/handlers/commit.ts +3 -0
- package/src/cli/handlers/notify-relay.ts +99 -17
- package/src/cli/handlers/pr.ts +3 -1
- package/src/cli/handlers/release.ts +20 -10
- package/src/cli/handlers/run-generate.ts +2 -1
- package/src/cli/main.ts +21 -1
- package/src/cli/parse-args.ts +45 -3
- package/src/cli/registry.ts +16 -0
- package/src/components/pr-env-components.test.ts +137 -0
- package/src/components/pr-env-components.ts +213 -0
- package/src/components/pr-policy.test.ts +41 -1
- package/src/components/pr-policy.ts +25 -1
- package/src/components/release-compile.test.ts +47 -0
- package/src/components/release-compile.ts +70 -13
- package/src/config.ts +23 -3
- package/src/gate-policy-bundle.test.ts +14 -0
- package/src/gate-policy.test.ts +7 -0
- package/src/gate-policy.ts +22 -7
- package/src/lexicon.ts +28 -1
- package/src/lifecycle/gated-op.ts +158 -0
- package/src/lifecycle/git.test.ts +92 -0
- package/src/lifecycle/git.ts +71 -2
- package/src/lifecycle/release-images-dockerfile.test.ts +221 -0
- package/src/lifecycle/release-images.ts +167 -8
- package/src/notify-message-words.test.ts +186 -0
- package/src/notify-product.ts +17 -4
- package/src/notify-relay-repo.test.ts +284 -0
- package/src/notify-relay-repo.ts +234 -0
- package/src/notify-relay.test.ts +12 -0
- package/src/notify-relay.ts +29 -3
- package/src/notify.schema.json +1 -0
- package/src/notify.ts +59 -19
- package/src/op/activities/review-product.test.ts +116 -0
- package/src/op/activities/review-product.ts +200 -0
- package/src/op/op-waves-capability.ts +2 -2
- package/src/op/schedule-overdue.test.ts +26 -0
- package/src/policy-engine.test.ts +162 -0
- package/src/policy-engine.ts +200 -0
- package/src/pr-forge-reads.test.ts +285 -0
- package/src/pr-forge-reads.ts +424 -0
- package/src/pr-forge.ts +30 -16
- package/src/pr-plan-note.test.ts +105 -0
- package/src/pr-plan-note.ts +521 -0
- package/src/release-floors.ts +13 -1
- package/src/state-export.test.ts +124 -0
- package/src/state-export.ts +227 -0
- package/src/state-migration.test.ts +133 -0
- package/src/state-migration.ts +236 -0
- package/src/state-unlock.test.ts +165 -0
- package/src/state-unlock.ts +293 -0
- package/src/workspace/declaration.schema.json +1 -1
- package/src/workspace/release-workflow.test.ts +34 -0
- package/src/workspace/release-workflow.ts +19 -4
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { type GatedRequestLedger } from "./lifecycle/gated-op.js";
|
|
2
|
+
import type { GatedRequestRules } from "./lifecycle/gated-request.js";
|
|
3
|
+
import type { ForgeFetch, ForgeKind } from "./pr-forge.js";
|
|
4
|
+
/** The first chant with the engine-neutral lock release and {@link forgeLiveRuns} (#4762). */
|
|
5
|
+
export declare const STATE_UNLOCK_FLOOR = "0.124.77";
|
|
6
|
+
/** A run of the repository that has not finished, as {@link forgeLiveRuns} reads it. */
|
|
7
|
+
export interface LiveRun {
|
|
8
|
+
id: string;
|
|
9
|
+
status: string;
|
|
10
|
+
/** When it began, or was created when the forge gives no start. ISO 8601. */
|
|
11
|
+
started?: string;
|
|
12
|
+
url?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Where {@link forgeLiveRuns} reads a repository's runs. */
|
|
15
|
+
export interface LiveRunsTarget {
|
|
16
|
+
kind: ForgeKind;
|
|
17
|
+
/** The forge's API base: `https://api.github.com`, `https://<host>/api/v1`, `https://<host>/api/v4`. */
|
|
18
|
+
apiBase: string;
|
|
19
|
+
/** `owner/repo` on GitHub and Forgejo; the project's id or path on GitLab. */
|
|
20
|
+
repo: string;
|
|
21
|
+
token?: string;
|
|
22
|
+
/** GitLab: the header the token goes in. Default `PRIVATE-TOKEN`. */
|
|
23
|
+
tokenHeader?: "PRIVATE-TOKEN" | "JOB-TOKEN";
|
|
24
|
+
fetch?: ForgeFetch;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The repository's runs that have not finished: GitHub's and Forgejo's
|
|
28
|
+
* Actions runs queued, waiting or in progress, GitLab's pipelines running,
|
|
29
|
+
* pending, preparing or waiting for a resource. Kept here rather than on the
|
|
30
|
+
* forge clients, so the bundles that carry those clients do not grow with
|
|
31
|
+
* a read only a lock release makes. Throws on a forge that answers an error.
|
|
32
|
+
*/
|
|
33
|
+
export declare function forgeLiveRuns(t: LiveRunsTarget): Promise<LiveRun[]>;
|
|
34
|
+
/** How far a run's start may be after the lock's and still count as a run that could hold it: the clocks of the job and the forge differ. */
|
|
35
|
+
export declare const CLOCK_SKEW_MS: number;
|
|
36
|
+
/** A lock's info, as Terraform's binary writes it and other engines can name it. */
|
|
37
|
+
export interface LockInfo {
|
|
38
|
+
ID: string;
|
|
39
|
+
Operation?: string;
|
|
40
|
+
Info?: string;
|
|
41
|
+
Who?: string;
|
|
42
|
+
Version?: string;
|
|
43
|
+
Created?: string;
|
|
44
|
+
Path?: string;
|
|
45
|
+
}
|
|
46
|
+
/** A lock info's JSON, or undefined when it holds no lock ID. */
|
|
47
|
+
export declare function parseLockInfo(text: string): LockInfo | undefined;
|
|
48
|
+
/** An engine's state lock: the adapter a product's engine supplies. */
|
|
49
|
+
export interface StateLockSource {
|
|
50
|
+
/** Where the lock is, as messages and the record name it. Never a credential. */
|
|
51
|
+
readonly location: string;
|
|
52
|
+
/** The lock held now, or undefined when none is. */
|
|
53
|
+
read(): Promise<LockInfo | undefined>;
|
|
54
|
+
/** Release the lock with this ID, and no other. */
|
|
55
|
+
release(id: string): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The live runs that may hold a lock taken at `created`: those that began
|
|
59
|
+
* before it, give or take the clocks' skew. A lock with no time it was taken,
|
|
60
|
+
* or a run with no start, keeps every run in.
|
|
61
|
+
*/
|
|
62
|
+
export declare function possibleHolders(runs: readonly LiveRun[], created: string | undefined, skewMs?: number): LiveRun[];
|
|
63
|
+
/** A lock as one line: its ID, operation, holder and time. */
|
|
64
|
+
export declare const describeLock: (l: LockInfo) => string;
|
|
65
|
+
/** A run as one line. */
|
|
66
|
+
export declare const describeRun: (r: LiveRun) => string;
|
|
67
|
+
/** The product's words for a release. */
|
|
68
|
+
export interface StateUnlockWords {
|
|
69
|
+
/** The op the requests wait at, such as `tf-unlock`. */
|
|
70
|
+
op: string;
|
|
71
|
+
/** The request's kind. Default `unlock`. */
|
|
72
|
+
kind?: string;
|
|
73
|
+
/** The command that approves a request, as the product prints it. Default chant's. */
|
|
74
|
+
approveCommand?: (subject: string, digest: string) => string;
|
|
75
|
+
}
|
|
76
|
+
export interface StateUnlockInput {
|
|
77
|
+
/** Whose lock: a root, a stack. The gate the request waits at. */
|
|
78
|
+
subject: string;
|
|
79
|
+
/** The requester. Their own approval never counts. */
|
|
80
|
+
by: string;
|
|
81
|
+
lock: StateLockSource;
|
|
82
|
+
/**
|
|
83
|
+
* The repository's runs that have not finished, such as
|
|
84
|
+
* {@link forgeLiveRuns}. Read before the request and again just before
|
|
85
|
+
* the spend. A throw refuses the release.
|
|
86
|
+
*/
|
|
87
|
+
liveRuns: () => Promise<LiveRun[]>;
|
|
88
|
+
words: StateUnlockWords;
|
|
89
|
+
rules: GatedRequestRules;
|
|
90
|
+
cwd?: string;
|
|
91
|
+
base?: string;
|
|
92
|
+
/** How long a request waits for its approval. Default 48h. */
|
|
93
|
+
expiry?: string;
|
|
94
|
+
now?: string;
|
|
95
|
+
commit?: string;
|
|
96
|
+
skewMs?: number;
|
|
97
|
+
ledger?: GatedRequestLedger;
|
|
98
|
+
}
|
|
99
|
+
/** How a release ended. `exit` is the code its command exits with. */
|
|
100
|
+
export type StateUnlockOutcome = {
|
|
101
|
+
status: "free";
|
|
102
|
+
exit: 0;
|
|
103
|
+
location: string;
|
|
104
|
+
} | {
|
|
105
|
+
status: "released";
|
|
106
|
+
exit: 0;
|
|
107
|
+
location: string;
|
|
108
|
+
lock: LockInfo;
|
|
109
|
+
digest: string;
|
|
110
|
+
approvedBy: string;
|
|
111
|
+
liveRuns: number;
|
|
112
|
+
recorded: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** A run that may hold the lock is alive: nothing was asked or released. */
|
|
115
|
+
| {
|
|
116
|
+
status: "alive";
|
|
117
|
+
exit: 5;
|
|
118
|
+
location: string;
|
|
119
|
+
lock: LockInfo;
|
|
120
|
+
alive: LiveRun[];
|
|
121
|
+
} | {
|
|
122
|
+
status: "waiting";
|
|
123
|
+
exit: 3;
|
|
124
|
+
location: string;
|
|
125
|
+
lock: LockInfo;
|
|
126
|
+
digest: string;
|
|
127
|
+
command: string;
|
|
128
|
+
} | {
|
|
129
|
+
status: "refused";
|
|
130
|
+
exit: 3;
|
|
131
|
+
location: string;
|
|
132
|
+
lock: LockInfo;
|
|
133
|
+
digest: string;
|
|
134
|
+
command: string;
|
|
135
|
+
by: string;
|
|
136
|
+
reason: string;
|
|
137
|
+
}
|
|
138
|
+
/** Approved, and a run that may hold the lock came back before the spend: the approval stands unspent. */
|
|
139
|
+
| {
|
|
140
|
+
status: "held";
|
|
141
|
+
exit: 5;
|
|
142
|
+
location: string;
|
|
143
|
+
lock: LockInfo;
|
|
144
|
+
digest: string;
|
|
145
|
+
reason: string;
|
|
146
|
+
} | {
|
|
147
|
+
status: "spent";
|
|
148
|
+
exit: 1;
|
|
149
|
+
location: string;
|
|
150
|
+
lock: LockInfo;
|
|
151
|
+
digest: string;
|
|
152
|
+
} | {
|
|
153
|
+
status: "failed";
|
|
154
|
+
exit: 1;
|
|
155
|
+
location: string;
|
|
156
|
+
lock: LockInfo;
|
|
157
|
+
digest: string;
|
|
158
|
+
error: Error;
|
|
159
|
+
recorded: boolean;
|
|
160
|
+
};
|
|
161
|
+
/** A refusal before anything is asked: the runs could not be read. */
|
|
162
|
+
export declare class StateUnlockError extends Error {
|
|
163
|
+
constructor(message: string);
|
|
164
|
+
}
|
|
165
|
+
/** Release a state's lock that no live run can hold, once an approval of that lock stands. */
|
|
166
|
+
export declare function releaseStateLock(input: StateUnlockInput): Promise<StateUnlockOutcome>;
|
|
167
|
+
//# sourceMappingURL=state-unlock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-unlock.d.ts","sourceRoot":"","sources":["../src/state-unlock.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAW,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAA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CAAA;CAAE,GAC7F;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC9E;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAErH,sEAAsE;AACtE,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,8FAA8F;AAC9F,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAuE3F"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stale state lock released behind a gated request (#4762): the lock a
|
|
3
|
+
* job killed mid-apply left behind, released once someone else approved
|
|
4
|
+
* that lock by its ID, and only while no run that may hold it is alive.
|
|
5
|
+
*
|
|
6
|
+
* Engine-neutral. The engine's adapter is a {@link StateLockSource}: where
|
|
7
|
+
* the lock is, the lock it holds now, and a release by ID. The terraform
|
|
8
|
+
* lexicon builds one from a root's backend and the binary's `force-unlock`
|
|
9
|
+
* (`@intentius/chant-lexicon-terraform/state-unlock`); a Pulumi stack's lock
|
|
10
|
+
* (`.pulumi/locks/...` and `pulumi cancel`) fits the same calls. The runs
|
|
11
|
+
* come from the forge ({@link forgeLiveRuns}), or the caller's own list.
|
|
12
|
+
*
|
|
13
|
+
* 1. The lock is read, with its ID, who took it and when.
|
|
14
|
+
* 2. A run of the repository that has not finished and began before the
|
|
15
|
+
* lock was taken (give or take {@link CLOCK_SKEW_MS}) may be the one
|
|
16
|
+
* holding it, so while one is alive nothing is asked and nothing is
|
|
17
|
+
* released. A forge that cannot be read refuses too: nothing then says
|
|
18
|
+
* the holder is gone.
|
|
19
|
+
* 3. The request (kind `unlock`, subject the root or stack, fields the
|
|
20
|
+
* lock's location and ID) waits for an approval by someone other than
|
|
21
|
+
* the requester. An approval binds that lock and no other.
|
|
22
|
+
* 4. Approved, the runs are read again just before the spend, the lock is
|
|
23
|
+
* released by its ID, read again to check it is gone, and the finished
|
|
24
|
+
* line records who released which lock under whose approval.
|
|
25
|
+
*/
|
|
26
|
+
import { CHANT_EXIT } from "./exit-codes.js";
|
|
27
|
+
import { gatedOp } from "./lifecycle/gated-op.js";
|
|
28
|
+
/** The first chant with the engine-neutral lock release and {@link forgeLiveRuns} (#4762). */
|
|
29
|
+
export const STATE_UNLOCK_FLOOR = "0.124.77";
|
|
30
|
+
const text = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
31
|
+
/**
|
|
32
|
+
* The repository's runs that have not finished: GitHub's and Forgejo's
|
|
33
|
+
* Actions runs queued, waiting or in progress, GitLab's pipelines running,
|
|
34
|
+
* pending, preparing or waiting for a resource. Kept here rather than on the
|
|
35
|
+
* forge clients, so the bundles that carry those clients do not grow with
|
|
36
|
+
* a read only a lock release makes. Throws on a forge that answers an error.
|
|
37
|
+
*/
|
|
38
|
+
export async function forgeLiveRuns(t) {
|
|
39
|
+
const fetchFn = t.fetch ?? globalThis.fetch;
|
|
40
|
+
const base = t.apiBase.replace(/\/+$/, "");
|
|
41
|
+
const headers = t.kind === "github"
|
|
42
|
+
? { ...(t.token ? { Authorization: `Bearer ${t.token}` } : {}), Accept: "application/vnd.github+json" }
|
|
43
|
+
: t.kind === "forgejo"
|
|
44
|
+
? { ...(t.token ? { Authorization: `token ${t.token}` } : {}), Accept: "application/json" }
|
|
45
|
+
: { ...(t.token ? { [t.tokenHeader ?? "PRIVATE-TOKEN"]: t.token } : {}), Accept: "application/json" };
|
|
46
|
+
const get = async (path) => {
|
|
47
|
+
const res = await fetchFn(`${base}${path}`, { method: "GET", headers });
|
|
48
|
+
const body = await res.text();
|
|
49
|
+
if (!res.ok)
|
|
50
|
+
throw new Error(`GET ${base}${path}: ${res.status} ${body.slice(0, 200)}`);
|
|
51
|
+
return body ? JSON.parse(body) : undefined;
|
|
52
|
+
};
|
|
53
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
54
|
+
const out = new Map();
|
|
55
|
+
if (t.kind === "gitlab") {
|
|
56
|
+
const project = encodeURIComponent(decodeURIComponent(t.repo));
|
|
57
|
+
for (const status of ["running", "pending", "preparing", "waiting_for_resource"]) {
|
|
58
|
+
const rows = await get(`/projects/${project}/pipelines?status=${status}&per_page=100`);
|
|
59
|
+
for (const p of Array.isArray(rows) ? rows : []) {
|
|
60
|
+
if (!isObject(p) || p.id === undefined)
|
|
61
|
+
continue;
|
|
62
|
+
const started = text(p.started_at) ?? text(p.created_at);
|
|
63
|
+
const url = text(p.web_url);
|
|
64
|
+
out.set(String(p.id), { id: String(p.id), status: text(p.status) ?? status, ...(started ? { started } : {}), ...(url ? { url } : {}) });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return [...out.values()];
|
|
68
|
+
}
|
|
69
|
+
const statuses = t.kind === "github" ? ["in_progress", "queued", "waiting", "pending", "requested"] : ["running", "waiting", "blocked"];
|
|
70
|
+
for (const status of statuses) {
|
|
71
|
+
const body = await get(`/repos/${t.repo}/actions/runs?status=${status}&${t.kind === "github" ? "per_page=100" : "limit=50"}`);
|
|
72
|
+
const runs = Array.isArray(body) ? body : isObject(body) && Array.isArray(body.workflow_runs) ? body.workflow_runs : [];
|
|
73
|
+
for (const r of runs) {
|
|
74
|
+
if (!isObject(r) || r.id === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
const started = t.kind === "github" ? (text(r.run_started_at) ?? text(r.created_at)) : (text(r.started) ?? text(r.created));
|
|
77
|
+
// Forgejo leaves `started` at the epoch until a job starts.
|
|
78
|
+
const begun = started && Date.parse(started) > 0 ? started : (text(r.created) ?? text(r.created_at));
|
|
79
|
+
const url = text(r.html_url);
|
|
80
|
+
out.set(String(r.id), { id: String(r.id), status: text(r.status) ?? status, ...(begun ? { started: begun } : {}), ...(url ? { url } : {}) });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [...out.values()];
|
|
84
|
+
}
|
|
85
|
+
/** How far a run's start may be after the lock's and still count as a run that could hold it: the clocks of the job and the forge differ. */
|
|
86
|
+
export const CLOCK_SKEW_MS = 2 * 60 * 1000;
|
|
87
|
+
/** A lock info's JSON, or undefined when it holds no lock ID. */
|
|
88
|
+
export function parseLockInfo(text) {
|
|
89
|
+
try {
|
|
90
|
+
const v = JSON.parse(text);
|
|
91
|
+
if (!v || typeof v !== "object" || typeof v.ID !== "string" || v.ID === "")
|
|
92
|
+
return undefined;
|
|
93
|
+
const out = { ID: v.ID };
|
|
94
|
+
for (const k of ["Operation", "Info", "Who", "Version", "Created", "Path"])
|
|
95
|
+
if (typeof v[k] === "string")
|
|
96
|
+
out[k] = v[k];
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const time = (iso) => (iso ? Date.parse(iso) : Number.NaN);
|
|
104
|
+
/**
|
|
105
|
+
* The live runs that may hold a lock taken at `created`: those that began
|
|
106
|
+
* before it, give or take the clocks' skew. A lock with no time it was taken,
|
|
107
|
+
* or a run with no start, keeps every run in.
|
|
108
|
+
*/
|
|
109
|
+
export function possibleHolders(runs, created, skewMs = CLOCK_SKEW_MS) {
|
|
110
|
+
const taken = time(created);
|
|
111
|
+
return runs.filter((r) => Number.isNaN(taken) || Number.isNaN(time(r.started)) || time(r.started) <= taken + skewMs);
|
|
112
|
+
}
|
|
113
|
+
/** A lock as one line: its ID, operation, holder and time. */
|
|
114
|
+
export const describeLock = (l) => `lock ${l.ID}${l.Operation ? `, ${l.Operation}` : ""}${l.Who ? ` by ${l.Who}` : ""}${l.Created ? ` at ${l.Created}` : ""}`;
|
|
115
|
+
/** A run as one line. */
|
|
116
|
+
export const describeRun = (r) => `run ${r.id} (${r.status}${r.started ? `, began ${r.started}` : ""})${r.url ? ` ${r.url}` : ""}`;
|
|
117
|
+
/** A refusal before anything is asked: the runs could not be read. */
|
|
118
|
+
export class StateUnlockError extends Error {
|
|
119
|
+
constructor(message) {
|
|
120
|
+
super(message);
|
|
121
|
+
this.name = "StateUnlockError";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Release a state's lock that no live run can hold, once an approval of that lock stands. */
|
|
125
|
+
export async function releaseStateLock(input) {
|
|
126
|
+
const location = input.lock.location;
|
|
127
|
+
const lock = await input.lock.read();
|
|
128
|
+
if (!lock)
|
|
129
|
+
return { status: "free", exit: CHANT_EXIT.done, location };
|
|
130
|
+
let live = 0;
|
|
131
|
+
const holders = async () => {
|
|
132
|
+
let runs;
|
|
133
|
+
try {
|
|
134
|
+
runs = await input.liveRuns();
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
throw new StateUnlockError(`the repository's runs could not be read (${e.message}), so nothing says the run holding ${describeLock(lock)} is gone`);
|
|
138
|
+
}
|
|
139
|
+
live = runs.length;
|
|
140
|
+
return possibleHolders(runs, lock.Created, input.skewMs);
|
|
141
|
+
};
|
|
142
|
+
const alive = await holders();
|
|
143
|
+
if (alive.length > 0)
|
|
144
|
+
return { status: "alive", exit: CHANT_EXIT.held, location, lock, alive };
|
|
145
|
+
const result = await gatedOp({
|
|
146
|
+
op: input.words.op,
|
|
147
|
+
request: { kind: input.words.kind ?? "unlock", subject: input.subject, by: input.by, fields: { location, id: lock.ID } },
|
|
148
|
+
rules: input.rules,
|
|
149
|
+
description: `release ${describeLock(lock)} on ${location}`,
|
|
150
|
+
expiry: input.expiry ?? "48h",
|
|
151
|
+
...(input.base ? { base: input.base } : {}),
|
|
152
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
153
|
+
...(input.now ? { now: input.now } : {}),
|
|
154
|
+
...(input.commit ? { commit: input.commit } : {}),
|
|
155
|
+
...(input.ledger ? { ledger: input.ledger } : {}),
|
|
156
|
+
// The approval may be hours old: the runs are read again just before the spend.
|
|
157
|
+
beforeSpend: async () => {
|
|
158
|
+
const still = await holders();
|
|
159
|
+
return still.length > 0 ? `a run that began before the lock is alive again (${still.map(describeRun).join("; ")}), so the lock is not released` : undefined;
|
|
160
|
+
},
|
|
161
|
+
}, async ({ approvedBy }) => {
|
|
162
|
+
await input.lock.release(lock.ID);
|
|
163
|
+
const after = await input.lock.read();
|
|
164
|
+
if (after?.ID === lock.ID)
|
|
165
|
+
throw new StateUnlockError(`the release of lock ${lock.ID} ran, and ${location} still holds it`);
|
|
166
|
+
return {
|
|
167
|
+
output: approvedBy,
|
|
168
|
+
detail: {
|
|
169
|
+
by: input.by,
|
|
170
|
+
location,
|
|
171
|
+
lock_id: lock.ID,
|
|
172
|
+
...(lock.Operation ? { operation: lock.Operation } : {}),
|
|
173
|
+
...(lock.Who ? { locked_by: lock.Who } : {}),
|
|
174
|
+
...(lock.Created ? { locked_at: lock.Created } : {}),
|
|
175
|
+
approved_by: approvedBy,
|
|
176
|
+
live_runs: live,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
const command = (fallback) => (input.words.approveCommand ? input.words.approveCommand(input.subject, result.digest) : fallback);
|
|
181
|
+
const at = { location, lock, digest: result.digest };
|
|
182
|
+
switch (result.status) {
|
|
183
|
+
case "done":
|
|
184
|
+
return { status: "released", exit: CHANT_EXIT.done, ...at, approvedBy: result.approvedBy, liveRuns: live, recorded: result.recorded };
|
|
185
|
+
case "waiting":
|
|
186
|
+
return { status: "waiting", exit: CHANT_EXIT.waiting, ...at, command: command(result.command) };
|
|
187
|
+
case "refused":
|
|
188
|
+
return { status: "refused", exit: CHANT_EXIT.waiting, ...at, command: command(result.command), by: result.by, reason: result.reason };
|
|
189
|
+
case "held":
|
|
190
|
+
return { status: "held", exit: CHANT_EXIT.held, ...at, reason: result.reason };
|
|
191
|
+
case "spent":
|
|
192
|
+
return { status: "spent", exit: CHANT_EXIT.failed, ...at };
|
|
193
|
+
case "failed":
|
|
194
|
+
return { status: "failed", exit: CHANT_EXIT.failed, ...at, error: result.error, recorded: result.recorded };
|
|
195
|
+
}
|
|
196
|
+
}
|