@indigoai-us/hq-cli 5.345.252 → 5.345.253
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/contracts/host-canary-release.json +5 -5
- package/dist/command-catalog.generated.d.ts +148 -0
- package/dist/command-catalog.generated.js +182 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/ci-intake.d.ts +15 -0
- package/dist/commands/ci-intake.js +252 -0
- package/dist/commands/ci-metrics.d.ts +8 -0
- package/dist/commands/ci-metrics.js +55 -0
- package/dist/commands/ci.d.ts +13 -0
- package/dist/commands/ci.js +10 -0
- package/dist/commands/files.d.ts +62 -0
- package/dist/commands/files.js +249 -8
- package/dist/lib/bot/fleet-cron.d.ts +15 -0
- package/dist/lib/bot/fleet-cron.js +119 -20
- package/dist/lib/daemon/run.js +4 -3
- package/dist/lib/delivery/migrations.d.ts +32 -1
- package/dist/lib/delivery/migrations.js +69 -8
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +2 -1
- package/dist/lib/hook-engine/adapter-core-pin.js +2 -1
- package/dist/lib/hook-engine/coverage.d.ts +15 -0
- package/dist/lib/hook-engine/coverage.js +62 -1
- package/dist/lib/smart-ci/cost.d.ts +72 -0
- package/dist/lib/smart-ci/cost.js +120 -0
- package/dist/lib/smart-ci/github.d.ts +112 -0
- package/dist/lib/smart-ci/github.js +267 -0
- package/dist/lib/smart-ci/intake.d.ts +288 -0
- package/dist/lib/smart-ci/intake.js +1078 -0
- package/dist/lib/smart-ci/ledger.d.ts +218 -0
- package/dist/lib/smart-ci/ledger.js +527 -0
- package/dist/lib/smart-ci/metrics.d.ts +137 -0
- package/dist/lib/smart-ci/metrics.js +249 -0
- package/dist/lib/smart-ci/records.d.ts +265 -0
- package/dist/lib/smart-ci/records.js +281 -0
- package/dist/lib/smart-ci/reducer.d.ts +67 -0
- package/dist/lib/smart-ci/reducer.js +261 -0
- package/dist/lib/sync-core/engine-holds.d.ts +14 -0
- package/dist/lib/sync-core/engine-holds.js +78 -11
- package/dist/lib/sync-core/hand-back.d.ts +1 -0
- package/dist/lib/sync-core/hand-back.js +7 -2
- package/dist/lib/sync-core/reconcile.js +10 -2
- package/package.json +9 -7
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart CI metrics (smart-ci US-001): what the ledger says about waits, waste
|
|
3
|
+
* and cost for one repo over one window.
|
|
4
|
+
*
|
|
5
|
+
* Definitions, so the numbers can be checked by hand:
|
|
6
|
+
*
|
|
7
|
+
* - The window is [since, until). A job is in it by its queue time, a pull
|
|
8
|
+
* request by its merge time, a runner sample by its sample time.
|
|
9
|
+
* - A job "ran" when a runner picked it up (it has a runner name and a start
|
|
10
|
+
* time). Skipped jobs and jobs cancelled while still queued never ran and
|
|
11
|
+
* are left out of wait and run times.
|
|
12
|
+
* - Queue wait = start - queued. Run time = finish - start (finished jobs only).
|
|
13
|
+
* - Median and p90 use the nearest-rank method: the value at position
|
|
14
|
+
* ceil(p x n) of the sorted list. No interpolation.
|
|
15
|
+
* - A replaced-head job is one whose branch got a newer push at or after the
|
|
16
|
+
* job was queued and before it finished.
|
|
17
|
+
* - A cold start is a job that ran on the runner launched for it: the runner's
|
|
18
|
+
* name is ec2-<this job's id>-<n>, which is how hq-github-runners names a
|
|
19
|
+
* runner it launches for a queued job. Its queue wait is the cold-start
|
|
20
|
+
* time. A job that landed on a warm runner (ec2-warm-...), on a runner
|
|
21
|
+
* launched for another job, or on another pool did not wait for a launch.
|
|
22
|
+
* - Idle runner minutes come from runner pool samples: idle runners at a
|
|
23
|
+
* sample, times the gap to the next sample (capped at 5 minutes so a pause in
|
|
24
|
+
* sampling is not counted as idle time). A pool serves several repos, so the
|
|
25
|
+
* repo is given its share of each pool's idle minutes: its run minutes on
|
|
26
|
+
* the pool over the run minutes of every recorded repo on that pool in the
|
|
27
|
+
* window. The shares of the recorded repos add up to the pool's idle
|
|
28
|
+
* minutes, so summing across repos does not count a pool twice. Where
|
|
29
|
+
* samples are missing (gaps over 5 minutes) the figure covers only part of
|
|
30
|
+
* the window and is reported as an estimate with its coverage.
|
|
31
|
+
* - Merge to production = completion of the first successful deploy workflow
|
|
32
|
+
* run created at or after the merge on the base branch, minus the merge time.
|
|
33
|
+
* The run is matched by time, never by its head sha, which for hq-pro is not
|
|
34
|
+
* the commit it deploys. For hq-pro this is a lower bound: a green Deploy
|
|
35
|
+
* Prod run means the deploy was queued, and the deploy itself finishes
|
|
36
|
+
* minutes later in CodeBuild, which GitHub does not report and the ledger
|
|
37
|
+
* does not record.
|
|
38
|
+
*/
|
|
39
|
+
import { DEFAULT_RATES, classifyPool, costPerMerge } from "./cost.js";
|
|
40
|
+
import { KIND, isHosted } from "./records.js";
|
|
41
|
+
/** Repos whose merge to the base branch deploys to production, and the workflow that does it. */
|
|
42
|
+
export const DEPLOY_ON_MERGE = { "indigoai-us/hq-pro": "Deploy Prod" };
|
|
43
|
+
export const COLD_START_RUNNER = /^ec2-(\d+)-\d+$/;
|
|
44
|
+
const MAX_SAMPLE_GAP_MS = 300_000;
|
|
45
|
+
/** Idle minutes are called measured only when samples cover at least this share of the sampled span. */
|
|
46
|
+
export const IDLE_MEASURED_COVERAGE = 0.95;
|
|
47
|
+
/** Nearest-rank percentile of a list of numbers; null for an empty list. */
|
|
48
|
+
export function percentile(values, p) {
|
|
49
|
+
if (values.length === 0)
|
|
50
|
+
return null;
|
|
51
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
52
|
+
const rank = Math.min(sorted.length, Math.max(1, Math.ceil(p * sorted.length)));
|
|
53
|
+
return sorted[rank - 1];
|
|
54
|
+
}
|
|
55
|
+
function distribution(seconds) {
|
|
56
|
+
return { count: seconds.length, medianSeconds: percentile(seconds, 0.5), p90Seconds: percentile(seconds, 0.9) };
|
|
57
|
+
}
|
|
58
|
+
/** A date (2026-11-21) means the start of that UTC day. Throws on anything that is not a time. */
|
|
59
|
+
export function parseWhen(value, name) {
|
|
60
|
+
const text = /^\d{4}-\d{2}-\d{2}$/.test(value) ? `${value}T00:00:00Z` : value;
|
|
61
|
+
const ms = Date.parse(text);
|
|
62
|
+
if (Number.isNaN(ms))
|
|
63
|
+
throw new Error(`${name} is not a date or time: ${JSON.stringify(value)}. Use 2026-11-21 or 2026-11-21T00:00:00Z.`);
|
|
64
|
+
return ms;
|
|
65
|
+
}
|
|
66
|
+
const secondsBetween = (a, b) => Math.max(0, (Date.parse(b) - Date.parse(a)) / 1000);
|
|
67
|
+
const round1 = (n) => Math.round(n * 10) / 10;
|
|
68
|
+
export function computeMetrics(view, opts) {
|
|
69
|
+
const since = parseWhen(opts.since, "--since");
|
|
70
|
+
const until = opts.until === undefined ? Number.POSITIVE_INFINITY : parseWhen(opts.until, "--until");
|
|
71
|
+
const inWindow = (t) => t !== null && Date.parse(t) >= since && Date.parse(t) < until;
|
|
72
|
+
const rates = opts.rates ?? DEFAULT_RATES;
|
|
73
|
+
const allJobs = view.list(KIND.job).filter((j) => inWindow(j.queuedAt));
|
|
74
|
+
const jobs = allJobs.filter((j) => j.repo === opts.repo);
|
|
75
|
+
const ran = jobs.filter((j) => j.runnerName !== null && j.startedAt !== null);
|
|
76
|
+
const finished = ran.filter((j) => j.finishedAt !== null);
|
|
77
|
+
const queueWaits = ran.map((j) => secondsBetween(j.queuedAt, j.startedAt));
|
|
78
|
+
const runTimes = finished.map((j) => secondsBetween(j.startedAt, j.finishedAt));
|
|
79
|
+
const replaced = ran.filter((j) => j.replaced !== null);
|
|
80
|
+
const replacedFinished = replaced.filter((j) => j.finishedAt !== null);
|
|
81
|
+
const runMinutes = (list) => list.reduce((s, j) => s + secondsBetween(j.startedAt, j.finishedAt), 0) / 60;
|
|
82
|
+
const onPr = (j) => j.event !== null && j.event.startsWith("pull_request");
|
|
83
|
+
const minutesAfter = replacedFinished.reduce((s, j) => {
|
|
84
|
+
const from = Math.max(Date.parse(j.startedAt), Date.parse(j.replaced.at));
|
|
85
|
+
return s + Math.max(0, Date.parse(j.finishedAt) - from) / 1000;
|
|
86
|
+
}, 0) / 60;
|
|
87
|
+
const cold = ran.filter((j) => !isHosted(j) && COLD_START_RUNNER.exec(j.runnerName)?.[1] === String(j.jobId));
|
|
88
|
+
// Pool minutes for the cost.
|
|
89
|
+
const pools = new Map();
|
|
90
|
+
for (const j of finished) {
|
|
91
|
+
const seconds = secondsBetween(j.startedAt, j.finishedAt);
|
|
92
|
+
const p = pools.get(j.pool) ?? { pool: j.pool, poolClass: classifyPool(j.pool, isHosted(j), j.labels, rates), jobs: 0, runMinutes: 0, billedMinutes: 0 };
|
|
93
|
+
p.jobs += 1;
|
|
94
|
+
p.runMinutes += seconds / 60;
|
|
95
|
+
p.billedMinutes += Math.max(1, Math.ceil(seconds / 60));
|
|
96
|
+
pools.set(j.pool, p);
|
|
97
|
+
}
|
|
98
|
+
const poolMinutes = [...pools.values()].sort((a, b) => b.runMinutes - a.runMinutes || a.pool.localeCompare(b.pool));
|
|
99
|
+
// Idle runner minutes, for the pools this repo's jobs used.
|
|
100
|
+
const repoPools = new Set(jobs.map((j) => j.pool));
|
|
101
|
+
const samples = view
|
|
102
|
+
.list(KIND.runnerSample)
|
|
103
|
+
.filter((s) => inWindow(s.sampledAt))
|
|
104
|
+
.sort((a, b) => Date.parse(a.sampledAt) - Date.parse(b.sampledAt));
|
|
105
|
+
let idleRunners = null;
|
|
106
|
+
if (samples.length >= 2) {
|
|
107
|
+
const pool = {};
|
|
108
|
+
let coveredMs = 0;
|
|
109
|
+
for (let i = 0; i + 1 < samples.length; i++) {
|
|
110
|
+
const gapMs = Math.min(MAX_SAMPLE_GAP_MS, Date.parse(samples[i + 1].sampledAt) - Date.parse(samples[i].sampledAt));
|
|
111
|
+
coveredMs += gapMs;
|
|
112
|
+
for (const p of samples[i].pools) {
|
|
113
|
+
if (!repoPools.has(p.pool) || p.idle === 0)
|
|
114
|
+
continue;
|
|
115
|
+
pool[p.pool] = (pool[p.pool] ?? 0) + (p.idle * gapMs) / 60_000;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const spanMs = Date.parse(samples[samples.length - 1].sampledAt) - Date.parse(samples[0].sampledAt);
|
|
119
|
+
// Run minutes on each pool: this repo's and every recorded repo's.
|
|
120
|
+
const mine = {};
|
|
121
|
+
const everyone = {};
|
|
122
|
+
for (const j of allJobs) {
|
|
123
|
+
if (j.runnerName === null || j.startedAt === null || j.finishedAt === null)
|
|
124
|
+
continue;
|
|
125
|
+
const minutes = secondsBetween(j.startedAt, j.finishedAt) / 60;
|
|
126
|
+
everyone[j.pool] = (everyone[j.pool] ?? 0) + minutes;
|
|
127
|
+
if (j.repo === opts.repo)
|
|
128
|
+
mine[j.pool] = (mine[j.pool] ?? 0) + minutes;
|
|
129
|
+
}
|
|
130
|
+
const byPool = {};
|
|
131
|
+
const poolMinutes = {};
|
|
132
|
+
const share = {};
|
|
133
|
+
for (const k of Object.keys(pool)) {
|
|
134
|
+
const s = (everyone[k] ?? 0) > 0 ? (mine[k] ?? 0) / everyone[k] : 0;
|
|
135
|
+
share[k] = Math.round(s * 1000) / 1000;
|
|
136
|
+
poolMinutes[k] = round1(pool[k]);
|
|
137
|
+
byPool[k] = round1(pool[k] * s);
|
|
138
|
+
}
|
|
139
|
+
idleRunners = {
|
|
140
|
+
minutes: round1(Object.keys(pool).reduce((s, k) => s + pool[k] * ((everyone[k] ?? 0) > 0 ? (mine[k] ?? 0) / everyone[k] : 0), 0)),
|
|
141
|
+
samples: samples.length,
|
|
142
|
+
byPool,
|
|
143
|
+
poolMinutes,
|
|
144
|
+
share,
|
|
145
|
+
coverage: spanMs > 0 ? Math.round((coveredMs / spanMs) * 1000) / 1000 : 1,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const merged = view.list(KIND.pullRequest).filter((p) => p.repo === opts.repo && inWindow(p.mergedAt));
|
|
149
|
+
const openToMerge = merged.map((p) => secondsBetween(p.createdAt, p.mergedAt));
|
|
150
|
+
const workflow = opts.deployWorkflow === undefined ? (DEPLOY_ON_MERGE[opts.repo] ?? null) : opts.deployWorkflow;
|
|
151
|
+
let mergeToProduction = { applicable: false };
|
|
152
|
+
if (workflow !== null) {
|
|
153
|
+
const deploys = view
|
|
154
|
+
.list(KIND.run)
|
|
155
|
+
.filter((r) => r.repo === opts.repo && r.name === workflow && r.status === "completed" && r.conclusion === "success" && r.updatedAt !== null)
|
|
156
|
+
.sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt));
|
|
157
|
+
const times = [];
|
|
158
|
+
for (const p of merged) {
|
|
159
|
+
const first = deploys.find((r) => Date.parse(r.createdAt) >= Date.parse(p.mergedAt) && (r.headBranch === null || r.headBranch === p.baseRef));
|
|
160
|
+
if (first)
|
|
161
|
+
times.push(secondsBetween(p.mergedAt, first.updatedAt));
|
|
162
|
+
}
|
|
163
|
+
mergeToProduction = { applicable: true, workflow, deployed: times.length, notYetDeployed: merged.length - times.length, distribution: distribution(times) };
|
|
164
|
+
}
|
|
165
|
+
const cost = costPerMerge({
|
|
166
|
+
merges: merged.length,
|
|
167
|
+
pools: poolMinutes,
|
|
168
|
+
idleMinutesByPool: idleRunners === null ? null : idleRunners.byPool,
|
|
169
|
+
idleCoverage: idleRunners === null ? null : idleRunners.coverage,
|
|
170
|
+
rates,
|
|
171
|
+
githubBilledUsd: opts.githubBilledUsd,
|
|
172
|
+
awsFleetUsd: opts.awsFleetUsd,
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
repo: opts.repo,
|
|
176
|
+
since: new Date(since).toISOString(),
|
|
177
|
+
until: Number.isFinite(until) ? new Date(until).toISOString() : null,
|
|
178
|
+
jobs: { recorded: jobs.length, ran: ran.length, finished: finished.length, neverRan: jobs.length - ran.length },
|
|
179
|
+
queueWait: distribution(queueWaits),
|
|
180
|
+
runTime: distribution(runTimes),
|
|
181
|
+
replacedHead: {
|
|
182
|
+
runs: new Set(replaced.map((j) => j.runId)).size,
|
|
183
|
+
jobs: replaced.length,
|
|
184
|
+
minutes: round1(runMinutes(replacedFinished)),
|
|
185
|
+
minutesAfterReplacement: round1(minutesAfter),
|
|
186
|
+
onPullRequests: {
|
|
187
|
+
runs: new Set(replaced.filter(onPr).map((j) => j.runId)).size,
|
|
188
|
+
jobs: replaced.filter(onPr).length,
|
|
189
|
+
minutes: round1(runMinutes(replacedFinished.filter(onPr))),
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
coldStart: { jobs: cold.length, minutes: round1(cold.reduce((s, j) => s + secondsBetween(j.queuedAt, j.startedAt), 0) / 60) },
|
|
193
|
+
idleRunners,
|
|
194
|
+
pullRequests: { merged: merged.length, openToMerge: distribution(openToMerge) },
|
|
195
|
+
mergeToProduction,
|
|
196
|
+
cost,
|
|
197
|
+
poolMinutes: poolMinutes.map((p) => ({ ...p, runMinutes: round1(p.runMinutes) })),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** 95 -> "1m 35s"; 4000 -> "1h 6m 40s". */
|
|
201
|
+
export function formatDuration(seconds) {
|
|
202
|
+
if (seconds === null)
|
|
203
|
+
return "no data";
|
|
204
|
+
const s = Math.round(seconds);
|
|
205
|
+
const h = Math.floor(s / 3600);
|
|
206
|
+
const m = Math.floor((s % 3600) / 60);
|
|
207
|
+
const rest = s % 60;
|
|
208
|
+
if (h > 0)
|
|
209
|
+
return `${h}h ${m}m ${rest}s`;
|
|
210
|
+
if (m > 0)
|
|
211
|
+
return `${m}m ${rest}s`;
|
|
212
|
+
return `${rest}s`;
|
|
213
|
+
}
|
|
214
|
+
const money = (n) => `$${n.toFixed(2)}`;
|
|
215
|
+
/** The plain-text report `hq ci metrics` prints. */
|
|
216
|
+
export function renderMetrics(m) {
|
|
217
|
+
const lines = [];
|
|
218
|
+
const dist = (d) => (d.count === 0 ? "no data" : `median ${formatDuration(d.medianSeconds)}, p90 ${formatDuration(d.p90Seconds)} (${d.count})`);
|
|
219
|
+
lines.push(`Smart CI metrics for ${m.repo}`);
|
|
220
|
+
lines.push(`Window: ${m.since} to ${m.until ?? "now"}`);
|
|
221
|
+
lines.push("");
|
|
222
|
+
lines.push(`Jobs recorded: ${m.jobs.recorded} (${m.jobs.ran} ran, ${m.jobs.finished} finished, ${m.jobs.neverRan} skipped or never started)`);
|
|
223
|
+
lines.push(`Queue wait: ${dist(m.queueWait)}`);
|
|
224
|
+
lines.push(`Run time: ${dist(m.runTime)}`);
|
|
225
|
+
const r = m.replacedHead;
|
|
226
|
+
lines.push(`Replaced-head runs: ${r.runs} runs (${r.jobs} jobs), ${r.minutes} runner minutes, ${r.minutesAfterReplacement} of them after the newer push. On pull requests: ${r.onPullRequests.runs} runs (${r.onPullRequests.jobs} jobs), ${r.onPullRequests.minutes} minutes.`);
|
|
227
|
+
lines.push(`Cold-start runner minutes: ${m.coldStart.minutes} across ${m.coldStart.jobs} jobs that ran on the runner launched for them`);
|
|
228
|
+
lines.push(m.idleRunners === null
|
|
229
|
+
? "Idle runner minutes: not measured (the window has fewer than two runner pool samples)"
|
|
230
|
+
: `Idle runner minutes: ${m.idleRunners.minutes} from ${m.idleRunners.samples} samples${Object.keys(m.idleRunners.byPool).length > 0 ? ` (${Object.entries(m.idleRunners.byPool).map(([p, v]) => `${p} ${v} of the pool's ${m.idleRunners?.poolMinutes[p]}`).join(", ")})` : ""}. This is the repo's share of each pool it used, by its share of the recorded run minutes on that pool.${m.idleRunners.coverage < IDLE_MEASURED_COVERAGE ? ` Samples cover ${Math.round(m.idleRunners.coverage * 100)}% of the time between the first and the last one, so the real figure is higher.` : ""}`);
|
|
231
|
+
lines.push(`PR open to merge: ${m.pullRequests.merged === 0 ? "no pull requests merged in the window" : dist(m.pullRequests.openToMerge)}`);
|
|
232
|
+
if (!m.mergeToProduction.applicable)
|
|
233
|
+
lines.push("Merge to production: not applicable (this repo does not deploy on merge)");
|
|
234
|
+
else {
|
|
235
|
+
const p = m.mergeToProduction;
|
|
236
|
+
lines.push(`Merge to production (${p.workflow}): ${p.deployed === 0 ? "no deploy recorded for the merges in the window" : dist(p.distribution)}${p.notYetDeployed > 0 ? `; ${p.notYetDeployed} merges with no deploy recorded yet` : ""}`);
|
|
237
|
+
lines.push(` Measured to the end of the first successful ${p.workflow} run after each merge. Where that run only queues the deploy, production is live some minutes later, so read this as a lower bound.`);
|
|
238
|
+
}
|
|
239
|
+
lines.push(m.cost.usdPerMerge === null
|
|
240
|
+
? `Cost per merge: no merges in the window (total ${money(m.cost.totalUsd)}: GitHub-hosted ${money(m.cost.githubHostedUsd)}, AWS ${money(m.cost.awsUsd)})`
|
|
241
|
+
: `Cost per merge: ${money(m.cost.usdPerMerge)} (${money(m.cost.totalUsd)} over ${m.cost.merges} merges: GitHub-hosted ${money(m.cost.githubHostedUsd)}, AWS ${money(m.cost.awsUsd)})`);
|
|
242
|
+
lines.push(" This is one repo's cost over its own merges. The 2026-11-22 study's figure is for the whole org per pull request, so the two are not the same measure.");
|
|
243
|
+
lines.push("");
|
|
244
|
+
lines.push("Cost inputs (method of the 2026-11-22 CI cost study: GitHub-hosted spend plus AWS runner fleet spend, divided by merges):");
|
|
245
|
+
for (const i of m.cost.inputs)
|
|
246
|
+
lines.push(` ${i.basis.padEnd(11)} ${i.input}: ${i.value} (${i.how})`);
|
|
247
|
+
return `${lines.join("\n")}\n`;
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart CI records (smart-ci US-001).
|
|
3
|
+
*
|
|
4
|
+
* Two shapes live here. An Observation is what the intake saw: one GitHub
|
|
5
|
+
* workflow run, job, check run, pull request, push, or one sample of the
|
|
6
|
+
* runner pools, reduced to the fields Smart CI uses. A record body is what the
|
|
7
|
+
* ledger keeps: one per run, job, check run, pull request, push and sample,
|
|
8
|
+
* keyed so that the same observation written twice is still one record.
|
|
9
|
+
*
|
|
10
|
+
* Observations carry no actor, author, email or commit message. The fields are
|
|
11
|
+
* picked one by one from the API response, so nothing else can ride along.
|
|
12
|
+
* Every time in a record comes from GitHub, except a runner sample's
|
|
13
|
+
* sampledAt, which is the clock reading when the sample was taken.
|
|
14
|
+
*/
|
|
15
|
+
export declare const SMART_CI_TENANT = "smart-ci";
|
|
16
|
+
export declare const KIND: {
|
|
17
|
+
readonly run: "ci.run";
|
|
18
|
+
readonly job: "ci.job";
|
|
19
|
+
readonly checkRun: "ci.check_run";
|
|
20
|
+
readonly pullRequest: "ci.pull_request";
|
|
21
|
+
readonly push: "ci.push";
|
|
22
|
+
readonly runnerSample: "ci.runner_sample";
|
|
23
|
+
/** A stretch of a stream the intake did not read (page limit or request budget). Written so a hole is visible. */
|
|
24
|
+
readonly gap: "ci.gap";
|
|
25
|
+
};
|
|
26
|
+
/** The kinds the intake moves to archive files once they are old and closed. */
|
|
27
|
+
export declare const ROTATED_KINDS: readonly string[];
|
|
28
|
+
export interface GapBody extends Record<string, unknown> {
|
|
29
|
+
repo: string;
|
|
30
|
+
stream: "runs" | "pulls" | "activity";
|
|
31
|
+
/** Not read: from here (ISO, inclusive)... */
|
|
32
|
+
from: string;
|
|
33
|
+
/** ...to here (ISO, exclusive). */
|
|
34
|
+
to: string;
|
|
35
|
+
reason: string;
|
|
36
|
+
notedAt: string;
|
|
37
|
+
}
|
|
38
|
+
export type SmartCiKind = (typeof KIND)[keyof typeof KIND];
|
|
39
|
+
export type JobStatus = "queued" | "in_progress" | "completed";
|
|
40
|
+
export interface RunObservation {
|
|
41
|
+
id: number;
|
|
42
|
+
attempt: number;
|
|
43
|
+
name: string;
|
|
44
|
+
event: string;
|
|
45
|
+
status: JobStatus;
|
|
46
|
+
conclusion: string | null;
|
|
47
|
+
headBranch: string | null;
|
|
48
|
+
headSha: string;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
startedAt: string | null;
|
|
51
|
+
updatedAt: string | null;
|
|
52
|
+
prNumbers: number[];
|
|
53
|
+
/** True once every job of this attempt has been recorded after the run completed. */
|
|
54
|
+
jobsFinal?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface JobObservation {
|
|
57
|
+
id: number;
|
|
58
|
+
runId: number;
|
|
59
|
+
runAttempt: number;
|
|
60
|
+
workflow: string;
|
|
61
|
+
name: string;
|
|
62
|
+
headBranch: string | null;
|
|
63
|
+
headSha: string;
|
|
64
|
+
status: JobStatus;
|
|
65
|
+
conclusion: string | null;
|
|
66
|
+
/** GitHub created_at: when the job entered the queue. */
|
|
67
|
+
createdAt: string;
|
|
68
|
+
startedAt: string | null;
|
|
69
|
+
completedAt: string | null;
|
|
70
|
+
labels: string[];
|
|
71
|
+
runnerName: string | null;
|
|
72
|
+
runnerGroup: string | null;
|
|
73
|
+
}
|
|
74
|
+
export interface CheckRunObservation {
|
|
75
|
+
id: number;
|
|
76
|
+
name: string;
|
|
77
|
+
headSha: string;
|
|
78
|
+
status: JobStatus;
|
|
79
|
+
conclusion: string | null;
|
|
80
|
+
startedAt: string | null;
|
|
81
|
+
completedAt: string | null;
|
|
82
|
+
app: string | null;
|
|
83
|
+
}
|
|
84
|
+
export interface PullRequestObservation {
|
|
85
|
+
number: number;
|
|
86
|
+
title: string;
|
|
87
|
+
state: "open" | "closed";
|
|
88
|
+
draft: boolean;
|
|
89
|
+
createdAt: string;
|
|
90
|
+
updatedAt: string;
|
|
91
|
+
closedAt: string | null;
|
|
92
|
+
mergedAt: string | null;
|
|
93
|
+
mergeCommitSha: string | null;
|
|
94
|
+
headSha: string;
|
|
95
|
+
headRef: string;
|
|
96
|
+
baseRef: string;
|
|
97
|
+
labels: string[];
|
|
98
|
+
}
|
|
99
|
+
export interface PushObservation {
|
|
100
|
+
id: number;
|
|
101
|
+
ref: string;
|
|
102
|
+
before: string;
|
|
103
|
+
after: string;
|
|
104
|
+
at: string;
|
|
105
|
+
activityType: string;
|
|
106
|
+
}
|
|
107
|
+
export interface PoolCount {
|
|
108
|
+
pool: string;
|
|
109
|
+
online: number;
|
|
110
|
+
busy: number;
|
|
111
|
+
idle: number;
|
|
112
|
+
offline: number;
|
|
113
|
+
}
|
|
114
|
+
export interface RunnerSampleObservation {
|
|
115
|
+
sampledAt: string;
|
|
116
|
+
total: number;
|
|
117
|
+
pools: PoolCount[];
|
|
118
|
+
}
|
|
119
|
+
export type Observation = {
|
|
120
|
+
type: "workflow_run";
|
|
121
|
+
repo: string;
|
|
122
|
+
run: RunObservation;
|
|
123
|
+
} | {
|
|
124
|
+
type: "workflow_job";
|
|
125
|
+
repo: string;
|
|
126
|
+
job: JobObservation;
|
|
127
|
+
} | {
|
|
128
|
+
type: "check_run";
|
|
129
|
+
repo: string;
|
|
130
|
+
checkRun: CheckRunObservation;
|
|
131
|
+
} | {
|
|
132
|
+
type: "pull_request";
|
|
133
|
+
repo: string;
|
|
134
|
+
pr: PullRequestObservation;
|
|
135
|
+
} | {
|
|
136
|
+
type: "push";
|
|
137
|
+
repo: string;
|
|
138
|
+
push: PushObservation;
|
|
139
|
+
} | {
|
|
140
|
+
type: "runner_pool";
|
|
141
|
+
org: string;
|
|
142
|
+
sample: RunnerSampleObservation;
|
|
143
|
+
};
|
|
144
|
+
export declare const OBSERVATION_TYPES: readonly Observation["type"][];
|
|
145
|
+
/** A later push that moved the branch off this job's head before the job finished. */
|
|
146
|
+
export interface Replacement {
|
|
147
|
+
bySha: string;
|
|
148
|
+
at: string;
|
|
149
|
+
pushId: number;
|
|
150
|
+
}
|
|
151
|
+
export interface RunBody extends Record<string, unknown> {
|
|
152
|
+
repo: string;
|
|
153
|
+
runId: number;
|
|
154
|
+
attempt: number;
|
|
155
|
+
name: string;
|
|
156
|
+
event: string;
|
|
157
|
+
status: JobStatus;
|
|
158
|
+
conclusion: string | null;
|
|
159
|
+
headBranch: string | null;
|
|
160
|
+
headSha: string;
|
|
161
|
+
createdAt: string;
|
|
162
|
+
startedAt: string | null;
|
|
163
|
+
updatedAt: string | null;
|
|
164
|
+
prNumbers: number[];
|
|
165
|
+
jobsFinal: boolean;
|
|
166
|
+
}
|
|
167
|
+
export interface JobBody extends Record<string, unknown> {
|
|
168
|
+
repo: string;
|
|
169
|
+
jobId: number;
|
|
170
|
+
runId: number;
|
|
171
|
+
runAttempt: number;
|
|
172
|
+
workflow: string;
|
|
173
|
+
name: string;
|
|
174
|
+
/** The workflow run's trigger (pull_request, push, ...), or null until the run is recorded. */
|
|
175
|
+
event: string | null;
|
|
176
|
+
headBranch: string | null;
|
|
177
|
+
headSha: string;
|
|
178
|
+
status: JobStatus;
|
|
179
|
+
conclusion: string | null;
|
|
180
|
+
queuedAt: string;
|
|
181
|
+
startedAt: string | null;
|
|
182
|
+
finishedAt: string | null;
|
|
183
|
+
labels: string[];
|
|
184
|
+
/** The runner pool: the first runs-on label that is not a generic one, else the runner group. */
|
|
185
|
+
pool: string;
|
|
186
|
+
runnerName: string | null;
|
|
187
|
+
runnerGroup: string | null;
|
|
188
|
+
replaced: Replacement | null;
|
|
189
|
+
}
|
|
190
|
+
export interface CheckRunBody extends Record<string, unknown> {
|
|
191
|
+
repo: string;
|
|
192
|
+
checkRunId: number;
|
|
193
|
+
name: string;
|
|
194
|
+
headSha: string;
|
|
195
|
+
status: JobStatus;
|
|
196
|
+
conclusion: string | null;
|
|
197
|
+
startedAt: string | null;
|
|
198
|
+
completedAt: string | null;
|
|
199
|
+
app: string | null;
|
|
200
|
+
}
|
|
201
|
+
export interface PullRequestBody extends Record<string, unknown> {
|
|
202
|
+
repo: string;
|
|
203
|
+
number: number;
|
|
204
|
+
title: string;
|
|
205
|
+
state: "open" | "closed";
|
|
206
|
+
draft: boolean;
|
|
207
|
+
createdAt: string;
|
|
208
|
+
updatedAt: string;
|
|
209
|
+
closedAt: string | null;
|
|
210
|
+
mergedAt: string | null;
|
|
211
|
+
mergeCommitSha: string | null;
|
|
212
|
+
headSha: string;
|
|
213
|
+
headRef: string;
|
|
214
|
+
baseRef: string;
|
|
215
|
+
labels: string[];
|
|
216
|
+
}
|
|
217
|
+
export interface PushBody extends Record<string, unknown> {
|
|
218
|
+
repo: string;
|
|
219
|
+
pushId: number;
|
|
220
|
+
ref: string;
|
|
221
|
+
before: string;
|
|
222
|
+
after: string;
|
|
223
|
+
at: string;
|
|
224
|
+
activityType: string;
|
|
225
|
+
}
|
|
226
|
+
export interface RunnerSampleBody extends Record<string, unknown> {
|
|
227
|
+
org: string;
|
|
228
|
+
sampledAt: string;
|
|
229
|
+
total: number;
|
|
230
|
+
pools: PoolCount[];
|
|
231
|
+
}
|
|
232
|
+
export declare const runKey: (repo: string, runId: number, attempt: number) => string;
|
|
233
|
+
export declare const jobKey: (repo: string, jobId: number) => string;
|
|
234
|
+
export declare const checkRunKey: (repo: string, id: number) => string;
|
|
235
|
+
export declare const pullRequestKey: (repo: string, number: number) => string;
|
|
236
|
+
export declare const pushKey: (repo: string, id: number) => string;
|
|
237
|
+
export declare const runnerSampleKey: (org: string, sampledAt: string) => string;
|
|
238
|
+
export declare const statusRank: (s: JobStatus) => number;
|
|
239
|
+
/** GitHub reports several not-yet-running states; Smart CI records them all as queued. */
|
|
240
|
+
export declare function normalizeStatus(raw: unknown): JobStatus;
|
|
241
|
+
/**
|
|
242
|
+
* The pool a job ran on or asked for. A self-hosted job names its pool in
|
|
243
|
+
* runs-on (hq-cli-x64, hq-mac-light); a GitHub-hosted job's label is the image
|
|
244
|
+
* (ubuntu-latest). With no usable label the runner group is the pool.
|
|
245
|
+
*/
|
|
246
|
+
export declare function poolOf(labels: readonly string[], runnerGroup: string | null): string;
|
|
247
|
+
/** True when the job asked for a GitHub-hosted runner (no self-hosted label, not in a self-hosted group). */
|
|
248
|
+
export declare function isHosted(job: Pick<JobBody, "labels" | "runnerGroup">): boolean;
|
|
249
|
+
/** GitHub REST workflow run to observation. Array and string fields are coerced here, at the parse boundary. */
|
|
250
|
+
export declare function runFromApi(raw: unknown): RunObservation;
|
|
251
|
+
export declare function jobFromApi(raw: unknown): JobObservation;
|
|
252
|
+
export declare function checkRunFromApi(raw: unknown): CheckRunObservation;
|
|
253
|
+
export declare function pullRequestFromApi(raw: unknown): PullRequestObservation;
|
|
254
|
+
export declare function pushFromApi(raw: unknown): PushObservation;
|
|
255
|
+
/** Pool of a registered runner: its first label that is not a generic one, else its name with digits removed. */
|
|
256
|
+
export declare function runnerPool(raw: unknown): string;
|
|
257
|
+
/** Reduce a list of registered runners to counts per pool. No runner name is kept. */
|
|
258
|
+
export declare function runnerSampleFromApi(runners: readonly unknown[], sampledAt: string): RunnerSampleObservation;
|
|
259
|
+
/**
|
|
260
|
+
* Problems with one observation, or [] when it can be recorded. Used on every
|
|
261
|
+
* fixture line and on everything the poller builds, so a malformed input is
|
|
262
|
+
* refused with a reason instead of becoming a half-filled record.
|
|
263
|
+
*/
|
|
264
|
+
export declare function validateObservation(input: unknown): string[];
|
|
265
|
+
//# sourceMappingURL=records.d.ts.map
|