@futurelastic/colab-handbook 1.12.0-rc.36 → 1.12.0-rc.38
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/package.json +1 -1
- package/templates/release-auto.yml +69 -14
- package/tools/colab +102 -7
- package/tools/lib/ci-cure.js +256 -16
- package/tools/lib/cure-diff.js +198 -9
- package/tools/lib/git.js +20 -1
- package/tools/lib/workflow-triggers.js +48 -0
package/package.json
CHANGED
|
@@ -91,6 +91,23 @@
|
|
|
91
91
|
# run still concludes on the `release` job. EDIT: on this route, a cron more frequent than daily
|
|
92
92
|
# tags a head that release.final-spacing held back sooner.
|
|
93
93
|
#
|
|
94
|
+
# DRY RUN ON A FIX BRANCH (#474). This workflow never runs on a branch by itself, so a fix to it
|
|
95
|
+
# (a moved runner label, a HANDBOOK_REF naming a missing branch) had no run to prove it, and the
|
|
96
|
+
# cure rule (CONVENTIONS.md §4) could only refuse it — a human ci-grant was the one door. Dispatch
|
|
97
|
+
# it on the fix branch instead:
|
|
98
|
+
#
|
|
99
|
+
# gh workflow run release-auto.yml --ref <fix-branch> -f dry_run=true
|
|
100
|
+
#
|
|
101
|
+
# (`colab ship` dispatches it for you when a red in this workflow is what stands between the branch
|
|
102
|
+
# and trunk). A dispatch on any ref other than main is ALWAYS dry, input or not. A dry run checks out
|
|
103
|
+
# the branch, runs every step with `--dry` — the same decisions, nothing promoted, tagged, released,
|
|
104
|
+
# pushed or dispatched — and skips only the steps whose names end in `[publish]`. The step
|
|
105
|
+
# "Dry run — nothing is tagged, released or published" runs only then; it is how the cure rule
|
|
106
|
+
# recognises the run. Keep both names as they are: the cure rule matches steps BY NAME, and accepts
|
|
107
|
+
# a dry run only if every step that ran in trunk's red run passed in it and every step it skipped
|
|
108
|
+
# ends in `[publish]`. So a red INSIDE a `[publish]` step, or in the npm or deploy jobs (which never
|
|
109
|
+
# run without a tag), cannot be cured by a dry run — that stays a human ci-grant.
|
|
110
|
+
#
|
|
94
111
|
# IT READS TAGS AND CREATES TAGS. IT NEVER WRITES A COMMIT. No step here commits; the refs
|
|
95
112
|
# pushed are the tags `colab release cut` / `colab release finalize` create (annotated, their
|
|
96
113
|
# checks recorded in the tag message) and — only on a repo granting unattended promotion — the
|
|
@@ -154,12 +171,21 @@ on:
|
|
|
154
171
|
# hour is when scheduled runs queue longest.
|
|
155
172
|
- cron: "17 3 * * *"
|
|
156
173
|
workflow_dispatch:
|
|
174
|
+
# #474: a DRY RUN for a fix branch — see "DRY RUN ON A FIX BRANCH" in the header. A dispatch on
|
|
175
|
+
# any ref other than main is dry whether or not this is set; on main it is opt-in.
|
|
176
|
+
inputs:
|
|
177
|
+
dry_run:
|
|
178
|
+
description: "Dry run: decide everything, write nothing (no promotion, tag, Release or publish)"
|
|
179
|
+
type: boolean
|
|
180
|
+
default: false
|
|
157
181
|
|
|
158
182
|
# One release run at a time; a second one waits rather than racing the first for the same
|
|
159
183
|
# candidate number. Never cancelled mid-run: a half-finished run may have pushed a tag
|
|
160
184
|
# without publishing it.
|
|
161
185
|
concurrency:
|
|
162
|
-
group:
|
|
186
|
+
# A dry run (#474) gets a group of its own: GitHub cancels an older PENDING run in the same group,
|
|
187
|
+
# so a shared one could let a branch's dry run displace a real release run waiting on main.
|
|
188
|
+
group: release-auto${{ github.event_name == 'workflow_dispatch' && (inputs.dry_run || github.ref_name != 'main') && format('-dry-{0}', github.ref_name) || '' }}
|
|
163
189
|
cancel-in-progress: false
|
|
164
190
|
|
|
165
191
|
permissions: {}
|
|
@@ -230,16 +256,34 @@ jobs:
|
|
|
230
256
|
health-url: ${{ steps.cut.outputs.health-url }}
|
|
231
257
|
env:
|
|
232
258
|
GH_TOKEN: ${{ github.token }}
|
|
259
|
+
# #474: 'true' on a dry run — a dispatch on any ref other than main, or one with dry_run set.
|
|
260
|
+
# Never on workflow_run or schedule. Every write below is off when it is.
|
|
261
|
+
# EDIT: if your trunk is not `main`, name it here too (the same branch as `ref:` below).
|
|
262
|
+
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && (inputs.dry_run || github.ref_name != 'main') }}
|
|
233
263
|
steps:
|
|
234
264
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
235
265
|
with:
|
|
236
|
-
ref
|
|
266
|
+
# A dry run checks out the ref it was dispatched on — the fix being proven; every other run, main.
|
|
267
|
+
ref: ${{ env.DRY_RUN == 'true' && github.sha || 'main' }}
|
|
237
268
|
# Full history plus tags: versions, bumps and "previous final" are all read from
|
|
238
269
|
# git, and the on-trunk check refuses a shallow checkout outright.
|
|
239
270
|
fetch-depth: 0
|
|
240
271
|
# Left on deliberately: `colab release cut` / `finalize` push their tag over the
|
|
241
|
-
# checkout's origin. The token is this job's, scoped by `permissions:` above.
|
|
242
|
-
|
|
272
|
+
# checkout's origin. The token is this job's, scoped by `permissions:` above. Off on a dry
|
|
273
|
+
# run (#474): nothing is pushed, so nothing should be able to push.
|
|
274
|
+
persist-credentials: ${{ env.DRY_RUN != 'true' }}
|
|
275
|
+
|
|
276
|
+
# #474: the marker ci-cure reads to recognise a dry run — its name must stay byte-identical to
|
|
277
|
+
# DRY_RUN_STEP in the handbook's tools/lib/ci-cure.js. Skipped on every ordinary run.
|
|
278
|
+
- name: Dry run — nothing is tagged, released or published
|
|
279
|
+
if: env.DRY_RUN == 'true'
|
|
280
|
+
run: |
|
|
281
|
+
{
|
|
282
|
+
echo "#### Dry run (#474)"
|
|
283
|
+
echo
|
|
284
|
+
echo "Dispatched on \`$GITHUB_REF_NAME\` @ \`$GITHUB_SHA\`. Every decision below runs with \`--dry\`; steps marked \`[publish]\` are skipped. Nothing is promoted, tagged, released or published."
|
|
285
|
+
echo
|
|
286
|
+
} >> "$GITHUB_STEP_SUMMARY"
|
|
243
287
|
|
|
244
288
|
# A red CI run on main is not a candidate. Gated here rather than by a job-level `if:` so
|
|
245
289
|
# this run concludes success, never `skipped` (#435; the comment on the job above).
|
|
@@ -285,7 +329,8 @@ jobs:
|
|
|
285
329
|
eval "$RETRY_TRANSIENT"
|
|
286
330
|
OUT="$RUNNER_TEMP/promote.json"
|
|
287
331
|
rc=0
|
|
288
|
-
|
|
332
|
+
DRY=(); [ "${DRY_RUN:-false}" = "true" ] && DRY=(--dry)
|
|
333
|
+
retry_transient node "$COLAB" promote --auto ${DRY[@]+"${DRY[@]}"} --json > "$OUT" || rc=$?
|
|
289
334
|
if ! jq -e 'has("promoted")' "$OUT" > /dev/null 2>&1; then
|
|
290
335
|
echo "::warning::colab promote --auto gave no verdict (exit $rc; a HANDBOOK_REF older than #440?) — nothing was promoted"
|
|
291
336
|
exit 0
|
|
@@ -296,7 +341,10 @@ jobs:
|
|
|
296
341
|
jq -r '.checks[]? | "- \(if .ok then "✓" else "✗" end) **\(.condition)** — \(.detail)"' "$OUT"
|
|
297
342
|
echo
|
|
298
343
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
299
|
-
if [ "$
|
|
344
|
+
if [ "${DRY_RUN:-false}" = "true" ]; then
|
|
345
|
+
# #474: a dry run promotes nothing and dispatches nothing, whatever the verdict says.
|
|
346
|
+
echo "Dry run — promote: $(jq -r 'if .promoted then "would promote" elif .noop then "no-op: \(.reason)" else "would refuse: \(.reason)" end' "$OUT")" | tee -a "$GITHUB_STEP_SUMMARY"
|
|
347
|
+
elif [ "$(jq -r '.promoted' "$OUT")" = "true" ]; then
|
|
300
348
|
echo "promoted=true" >> "$GITHUB_OUTPUT"
|
|
301
349
|
echo "Promoted to main @ $(jq -r '.sha' "$OUT")" | tee -a "$GITHUB_STEP_SUMMARY"
|
|
302
350
|
if retry_transient gh workflow run "$CI_WORKFLOW" --ref main; then
|
|
@@ -322,7 +370,8 @@ jobs:
|
|
|
322
370
|
eval "$RETRY_TRANSIENT"
|
|
323
371
|
OUT="$RUNNER_TEMP/cut.json"
|
|
324
372
|
rc=0
|
|
325
|
-
|
|
373
|
+
DRY=(); [ "${DRY_RUN:-false}" = "true" ] && DRY=(--dry)
|
|
374
|
+
retry_transient node "$COLAB" release cut --auto ${DRY[@]+"${DRY[@]}"} --json > "$OUT" || rc=$?
|
|
326
375
|
# A verdict is JSON carrying `ok`; anything else is a run that never decided.
|
|
327
376
|
if ! jq -e 'has("ok")' "$OUT" > /dev/null 2>&1; then
|
|
328
377
|
echo "::error::colab release cut produced no verdict (exit $rc)"
|
|
@@ -336,7 +385,10 @@ jobs:
|
|
|
336
385
|
jq -r '.checks[]? | "- \(if .ok then "✓" else "✗" end) **\(.condition)** — \(.detail)"' "$OUT"
|
|
337
386
|
echo
|
|
338
387
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
339
|
-
if [ "$
|
|
388
|
+
if [ "${DRY_RUN:-false}" = "true" ]; then
|
|
389
|
+
# #474: a dry run never hands a tag to the publishing steps, whatever the verdict says.
|
|
390
|
+
echo "Dry run — would cut: $(jq -r '.tag // "nothing"' "$OUT") (created: $(jq -r '.created' "$OUT"))" | tee -a "$GITHUB_STEP_SUMMARY"
|
|
391
|
+
elif [ "$(jq -r '.created' "$OUT")" = "true" ]; then
|
|
340
392
|
TAG="$(jq -r '.tag' "$OUT")"
|
|
341
393
|
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
|
342
394
|
echo "Cut $TAG" | tee -a "$GITHUB_STEP_SUMMARY"
|
|
@@ -376,7 +428,8 @@ jobs:
|
|
|
376
428
|
eval "$RETRY_TRANSIENT"
|
|
377
429
|
OUT="$RUNNER_TEMP/finalize.json"
|
|
378
430
|
rc=0
|
|
379
|
-
|
|
431
|
+
DRY=(); [ "${DRY_RUN:-false}" = "true" ] && DRY=(--dry)
|
|
432
|
+
retry_transient node "$COLAB" release finalize --auto ${DRY[@]+"${DRY[@]}"} --json > "$OUT" || rc=$?
|
|
380
433
|
if ! jq -e 'has("state")' "$OUT" > /dev/null 2>&1; then
|
|
381
434
|
echo "::error::colab release finalize produced no verdict (exit $rc)"
|
|
382
435
|
echo "colab release finalize produced no verdict (exit $rc) — the reason is in this step's log." >> "$GITHUB_STEP_SUMMARY"
|
|
@@ -400,7 +453,9 @@ jobs:
|
|
|
400
453
|
echo
|
|
401
454
|
fi
|
|
402
455
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
403
|
-
if [ "$
|
|
456
|
+
if [ "${DRY_RUN:-false}" = "true" ]; then
|
|
457
|
+
echo "Dry run — finalize: $STATE (would tag: $(jq -r '.finalTag // "nothing"' "$OUT"))" | tee -a "$GITHUB_STEP_SUMMARY"
|
|
458
|
+
elif [ "$(jq -r '.tagged' "$OUT")" = "true" ]; then
|
|
404
459
|
TAG="$(jq -r '.finalTag' "$OUT")"
|
|
405
460
|
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
|
406
461
|
echo "Finalized $TAG" | tee -a "$GITHUB_STEP_SUMMARY"
|
|
@@ -414,9 +469,9 @@ jobs:
|
|
|
414
469
|
# Whether the npm job publishes what this run tagged — `colab release npm` reads the
|
|
415
470
|
# release: block (one reading, the same as cut/finalize). A CLI older than #433 gives no
|
|
416
471
|
# verdict; that is a warning and no npm publish, never a failed release.
|
|
417
|
-
- name: Read the npm target (colab release npm)
|
|
472
|
+
- name: Read the npm target (colab release npm) [publish]
|
|
418
473
|
id: npm-target
|
|
419
|
-
if: steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != ''
|
|
474
|
+
if: env.DRY_RUN != 'true' && (steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != '')
|
|
420
475
|
env:
|
|
421
476
|
TAGS: ${{ steps.cut.outputs.tag }} ${{ steps.finalize.outputs.tag }}
|
|
422
477
|
run: |
|
|
@@ -445,8 +500,8 @@ jobs:
|
|
|
445
500
|
|
|
446
501
|
# Publishes every tag THIS run created. In this run, never via a tag-push workflow:
|
|
447
502
|
# see "PUBLISHING HAPPENS IN THIS RUN" in the header.
|
|
448
|
-
- name: Publish GitHub Release (same run)
|
|
449
|
-
if: steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != ''
|
|
503
|
+
- name: Publish GitHub Release (same run) [publish]
|
|
504
|
+
if: env.DRY_RUN != 'true' && (steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != '')
|
|
450
505
|
env:
|
|
451
506
|
TAGS: ${{ steps.cut.outputs.tag }} ${{ steps.finalize.outputs.tag }}
|
|
452
507
|
run: |
|
package/tools/colab
CHANGED
|
@@ -9450,10 +9450,14 @@ function ciGrantTrailerLine(grantVerdict, branch, trunk) {
|
|
|
9450
9450
|
*/
|
|
9451
9451
|
function ciCureTrailerLine(cureVerdict, branch, trunk) {
|
|
9452
9452
|
if (!cureVerdict || !cureVerdict.ok) return null;
|
|
9453
|
-
const via = cureVerdict.carveOut
|
|
9453
|
+
const via = (cureVerdict.carveOut
|
|
9454
9454
|
? ` via workflow-carve-out jobs ${cureVerdict.carveOut.jobs.map((j) => j.name).join(',')}`
|
|
9455
|
-
: '';
|
|
9456
|
-
|
|
9455
|
+
: '') + (cureVerdict.dryRun ? ` via dry-run jobs ${cureVerdict.dryRun.jobs.join(',')}` : '');
|
|
9456
|
+
// #475/#476: a cure that changed a manifest under an admission says which, for the same reason.
|
|
9457
|
+
const adm = cureVerdict.admitted || {};
|
|
9458
|
+
const manifest = [adm.scripts ? 'add-only-scripts' : null, adm.pins ? 'pin-only-requirements' : null].filter(Boolean);
|
|
9459
|
+
const admittedSuffix = manifest.length ? ` admitted ${manifest.join(',')}` : '';
|
|
9460
|
+
return `CI-Cure: branch ${branch} over-red ${trunk}@${shortSha(cureVerdict.redSha)} evidence ${shortSha(cureVerdict.evidenceSha)}${via}${admittedSuffix}`;
|
|
9457
9461
|
}
|
|
9458
9462
|
|
|
9459
9463
|
const HELP_SHIP = `colab ship [--repo <path>] [--worktree <name> | --branch <br> | --direct] [--message "<msg>"] [--refs <N[,M]>] [--keep-worktree] [--delete-branch | --keep-branch] [--adopt] [--session <id>] [--session-name <s>] [--dry] [--json]
|
|
@@ -10426,9 +10430,10 @@ function applyRedTrunkExemptions(raw, target, trunk, redSha, grantThunk, cureThu
|
|
|
10426
10430
|
const via = cureVerdict.carveOut
|
|
10427
10431
|
? ` THROUGH THE #321 WORKFLOW CARVE-OUT — every job red on trunk ran to success here: ${cureVerdict.carveOut.jobs.map((j) => `${j.name} (${j.redMs}ms red, ${j.branchMs}ms passing)`).join(', ')}`
|
|
10428
10432
|
: '';
|
|
10433
|
+
const viaDry = cureVerdict.dryRun ? ` — main-only job(s) ${cureVerdict.dryRun.jobs.join(', ')} proven by a DRY RUN on the branch (#474)` : '';
|
|
10429
10434
|
return {
|
|
10430
10435
|
name: raw.name, ok: true, class: null,
|
|
10431
|
-
detail: `PRECONDITION OVERRIDDEN by the cure rule (#281) — branch contains red ${shortSha(redSha)} and is green at its own head${via} (raw: ${raw.detail})`,
|
|
10436
|
+
detail: `PRECONDITION OVERRIDDEN by the cure rule (#281) — branch contains red ${shortSha(redSha)} and is green at its own head${via}${viaDry} (raw: ${raw.detail})`,
|
|
10432
10437
|
grantVerdict: null, cureVerdict,
|
|
10433
10438
|
};
|
|
10434
10439
|
}
|
|
@@ -10548,11 +10553,25 @@ function shipCiCure(repoAbs, gh, target, trunk, redSha, branch) {
|
|
|
10548
10553
|
// so a branch that cannot cure pays no job-level `gh` calls for it.
|
|
10549
10554
|
const jobEvidence = (containsRedSha && evidence && evidence.ok)
|
|
10550
10555
|
? shipCureJobEvidence(repoAbs, trunk, redSha, branch, evRun) : null;
|
|
10556
|
+
// #474: which workflows at the branch head offer a dry run — a static read (git show), read only
|
|
10557
|
+
// when job evidence exists, so a branch that already refuses on containment or 2a pays nothing.
|
|
10558
|
+
const capable = jobEvidence && evidence ? dryRunCapableWorkflows(repoAbs, evidence.sha) : [];
|
|
10551
10559
|
const verdict = ciCure.cureVerdict({ containsRedSha, evidence, redSha, stacking, jobEvidence,
|
|
10552
10560
|
workflowsTouched: diff.workflowsTouched,
|
|
10553
10561
|
manifestScriptsTouched: diff.manifestScriptsTouched, manifestPaths: diff.manifestPaths,
|
|
10554
|
-
|
|
10555
|
-
|
|
10562
|
+
manifestScriptsAddOnly: diff.manifestScriptsAddOnly,
|
|
10563
|
+
pythonManifestTouched: diff.pythonManifestTouched, pythonManifestPaths: diff.pythonManifestPaths,
|
|
10564
|
+
pythonPinOnly: diff.pythonPinOnly,
|
|
10565
|
+
dryRunCapable: capable.map((w) => w.name) });
|
|
10566
|
+
// The dispatch plan carries the FILE and the exact command, so the refusal can name it and the
|
|
10567
|
+
// real ship path can run it — measurement only here; nothing is dispatched by this function.
|
|
10568
|
+
const dryRunDispatch = verdict.dryRunWanted
|
|
10569
|
+
? verdict.dryRunWanted.map((name) => {
|
|
10570
|
+
const w = capable.find((c) => c.name === name);
|
|
10571
|
+
return { workflow: name, file: w.file, command: `gh workflow run ${w.file} --ref ${branch} -f ${DRY_RUN_INPUT}=true` };
|
|
10572
|
+
})
|
|
10573
|
+
: null;
|
|
10574
|
+
return { ...verdict, ...(dryRunDispatch ? { dryRunDispatch } : {}), redSha, evidenceSha: evidence ? evidence.sha : null };
|
|
10556
10575
|
}
|
|
10557
10576
|
|
|
10558
10577
|
/**
|
|
@@ -10630,9 +10649,73 @@ function ciCurePayload(ciResult) {
|
|
|
10630
10649
|
carveOut: c.carveOut
|
|
10631
10650
|
? { jobs: c.carveOut.jobs.map((j) => ({ name: j.name, redDurationMs: j.redMs, branchDurationMs: j.branchMs })) }
|
|
10632
10651
|
: null,
|
|
10652
|
+
// #474: the red job(s) proven only by a dry run of a main-only workflow — null otherwise.
|
|
10653
|
+
dryRun: c.dryRun ? { jobs: c.dryRun.jobs.slice() } : null,
|
|
10654
|
+
// #474: on a refusal, the dry run(s) that would supply the missing 2b evidence — what the real
|
|
10655
|
+
// ship dispatches; `--dry --json` only reports it. null when none would help.
|
|
10656
|
+
dryRunWanted: c.dryRunDispatch ? c.dryRunDispatch.map((d) => ({ ...d })) : null,
|
|
10657
|
+
// #475/#476: the manifest change a cure was admitted with — `{scripts?, pins?}` — or null.
|
|
10658
|
+
admitted: c.admitted || null,
|
|
10633
10659
|
};
|
|
10634
10660
|
}
|
|
10635
10661
|
|
|
10662
|
+
/** The dispatch input a dry-run-capable workflow declares (#474, templates/release-auto.yml). */
|
|
10663
|
+
const DRY_RUN_INPUT = 'dry_run';
|
|
10664
|
+
|
|
10665
|
+
/**
|
|
10666
|
+
* The workflows at `treeish` that offer a dry run (#474): a top-level `name:`, a `workflow_dispatch`
|
|
10667
|
+
* input named `dry_run`, and ci-cure's sentinel step text. All three, read statically at the BRANCH's
|
|
10668
|
+
* head — the copy a dispatch on that ref would run. A pre-#474 copy has no forced-dry mode and would
|
|
10669
|
+
* really publish if dispatched, which is exactly why this read gates every dispatch. `[]` on any
|
|
10670
|
+
* failed read: no capability is ever assumed.
|
|
10671
|
+
*/
|
|
10672
|
+
function dryRunCapableWorkflows(repoAbs, treeish) {
|
|
10673
|
+
const ls = git.git(['ls-tree', '--name-only', `${treeish}:.github/workflows`], repoAbs);
|
|
10674
|
+
if (!ls.ok) return [];
|
|
10675
|
+
const out = [];
|
|
10676
|
+
for (const f of ls.stdout.split('\n').map((x) => x.trim()).filter((x) => /\.ya?ml$/.test(x))) {
|
|
10677
|
+
const r = git.git(['show', `${treeish}:.github/workflows/${f}`], repoAbs);
|
|
10678
|
+
if (!r.ok) continue;
|
|
10679
|
+
const name = workflowTriggers.workflowNameOf(r.stdout);
|
|
10680
|
+
if (!name || !r.stdout.includes(ciCure.DRY_RUN_STEP)) continue;
|
|
10681
|
+
if (!workflowTriggers.workflowDispatchInputs(r.stdout).includes(DRY_RUN_INPUT)) continue;
|
|
10682
|
+
out.push({ name, file: f });
|
|
10683
|
+
}
|
|
10684
|
+
return out;
|
|
10685
|
+
}
|
|
10686
|
+
|
|
10687
|
+
/**
|
|
10688
|
+
* Dispatch the dry run(s) a refused cure asked for (#474) — the REAL ship path only, never `--dry`,
|
|
10689
|
+
* never `--dry --json`, never from the measurement above (which runs up to three times per ship).
|
|
10690
|
+
* Skips a workflow that already has ANY run at the branch head, whatever its status: a queued run has
|
|
10691
|
+
* no jobs yet, so "job absent" alone would dispatch it twice. Never waits — the caller re-runs ship
|
|
10692
|
+
* once the run completes (code-ship B1a's bounded wait), the same no-polling stance as every other
|
|
10693
|
+
* read here.
|
|
10694
|
+
*/
|
|
10695
|
+
function shipDispatchDryRuns(repoAbs, branch, plan) {
|
|
10696
|
+
const head = git.git(['rev-parse', branch], repoAbs);
|
|
10697
|
+
const runs = head.ok ? git.ghRunsForCommit(repoAbs, branch, head.stdout.trim(), 30) : null;
|
|
10698
|
+
for (const p of plan) {
|
|
10699
|
+
const existing = runs ? runs.filter((r) => r.workflowName === p.workflow) : null;
|
|
10700
|
+
if (existing === null) {
|
|
10701
|
+
warn(` dry run for ${p.workflow} NOT dispatched: the runs at ${branch}'s head could not be read — run it yourself: ${p.command}`);
|
|
10702
|
+
continue;
|
|
10703
|
+
}
|
|
10704
|
+
if (existing.length) {
|
|
10705
|
+
const r = existing[0];
|
|
10706
|
+
warn(` dry run for ${p.workflow} already exists at ${branch}'s head (run ${r.databaseId}, ${r.status}${r.conclusion ? '/' + r.conclusion : ''}) — not dispatched again; re-run \`colab ship\` once it completes.`);
|
|
10707
|
+
continue;
|
|
10708
|
+
}
|
|
10709
|
+
const d = git.ghWorkflowDispatch(repoAbs, p.file, branch, { [DRY_RUN_INPUT]: 'true' });
|
|
10710
|
+
if (d.ok) {
|
|
10711
|
+
warn(` ↻ dispatched a dry run of ${p.workflow} on ${branch} (#474)${d.withInputs ? '' : ' — without the input, which GitHub refused; the ref forces dry mode'}. ` +
|
|
10712
|
+
'Re-run `colab ship` once it completes (code-ship B1a\'s bounded wait) — it is the evidence this cure is missing.');
|
|
10713
|
+
} else {
|
|
10714
|
+
warn(` dry run for ${p.workflow} could NOT be dispatched (${d.detail}) — run it yourself: ${p.command}`);
|
|
10715
|
+
}
|
|
10716
|
+
}
|
|
10717
|
+
}
|
|
10718
|
+
|
|
10636
10719
|
/**
|
|
10637
10720
|
* Previews whether B0's merge (target INTO the branch) would conflict — WITHOUT touching the real
|
|
10638
10721
|
* worktree, the branch, or the network beyond a fetch — so `ship --dry --json`'s "no hand-merge
|
|
@@ -12065,6 +12148,11 @@ function cmdShip(argv) {
|
|
|
12065
12148
|
}
|
|
12066
12149
|
const dryOk = preOk && dryClosingConflicts.length === 0;
|
|
12067
12150
|
print(dryOk ? '→ READY: preconditions pass. Re-run without --dry to ship.' : '→ NOT READY: fix the ✗ rows above.');
|
|
12151
|
+
if (!ciOk && ciResult.cureVerdict && ciResult.cureVerdict.dryRunDispatch) {
|
|
12152
|
+
for (const d of ciResult.cureVerdict.dryRunDispatch) {
|
|
12153
|
+
print(` Dry run wanted (#474): ${d.workflow} has no run on this branch — a real \`colab ship\` dispatches \`${d.command}\` and refuses until it completes.`);
|
|
12154
|
+
}
|
|
12155
|
+
}
|
|
12068
12156
|
if (mode.evidenceClose) {
|
|
12069
12157
|
print(' Plan: no merge, no commit, no push · post evidence comment + CLOSE each issue · ' +
|
|
12070
12158
|
(opts.keepWorktree ? 'keep worktree' : 'worktree rm') + ' (releases claims)');
|
|
@@ -12095,7 +12183,14 @@ function cmdShip(argv) {
|
|
|
12095
12183
|
if (refsIssues.length) print(` Refs (kept open, NOT closed): ${refsIssues.map((n) => '#' + n).join(' ')}`);
|
|
12096
12184
|
return dryOk ? 0 : 1;
|
|
12097
12185
|
}
|
|
12098
|
-
if (!preOk) {
|
|
12186
|
+
if (!preOk) {
|
|
12187
|
+
// #474: the cure is missing only a main-only workflow's run, and that workflow offers a dry run —
|
|
12188
|
+
// dispatch it now (once), so the re-run has the evidence. Never on --dry: that returned above.
|
|
12189
|
+
if (!ciOk && ciResult.cureVerdict && ciResult.cureVerdict.dryRunDispatch && gh) {
|
|
12190
|
+
shipDispatchDryRuns(repoAbs, sess.branch, ciResult.cureVerdict.dryRunDispatch);
|
|
12191
|
+
}
|
|
12192
|
+
process.stderr.write('✗ Aborting: one or more preconditions failed (see ✗ above). Nothing was pushed.\n'); return 1;
|
|
12193
|
+
}
|
|
12099
12194
|
|
|
12100
12195
|
// ---- (b3) evidence-close: the whole B0–B2 sequence is skipped, because there is nothing to merge ----
|
|
12101
12196
|
if (mode.evidenceClose) return shipEvidenceClose({
|
package/tools/lib/ci-cure.js
CHANGED
|
@@ -44,12 +44,29 @@
|
|
|
44
44
|
* and test run at all, and a skipped step leaves the job `success` — so deleting
|
|
45
45
|
* `scripts.test` weakens the instrument without touching a workflow file. No carve-out: see
|
|
46
46
|
* below for why the #321 door cannot adjudicate it.
|
|
47
|
+
* ONE NARROW ADMISSION (#475): an ADD-ONLY scripts change — keys added, none removed or changed,
|
|
48
|
+
* no lifecycle hook — makes the template run MORE, so it passes condition 5 on step evidence
|
|
49
|
+
* (`manifestStepProof`, below) instead of refusing.
|
|
47
50
|
* 6. NO PYTHON DEPENDENCY-MANIFEST CHANGES (#377) — the branch diff must not change a file the
|
|
48
51
|
* Python CI template installs from (`pyproject.toml`/`setup.py`/`setup.cfg`, `requirements*`
|
|
49
52
|
* files and what they include — tools/lib/cure-diff.js names the set). That template runs
|
|
50
53
|
* ruff/mypy/pytest only when the tool is importable after install, so removing `pytest` from
|
|
51
54
|
* `requirements-dev.txt` skips the Test step and leaves the job `success`. Same shape as 5, a
|
|
52
|
-
* sibling door with no carve-out, for the same reason.
|
|
55
|
+
* sibling door with no carve-out, for the same reason. ONE NARROW ADMISSION (#476): a PIN-ONLY
|
|
56
|
+
* change — only the version specifier of requirements present on both sides — passes on step
|
|
57
|
+
* evidence plus the no-late-skip test (`manifestStepProof`, below).
|
|
58
|
+
*
|
|
59
|
+
* THE STEP PROOF BEHIND BOTH ADMISSIONS (#475, #476). Every step that RAN in each red job on trunk —
|
|
60
|
+
* the failing one included — ran on the branch and concluded `success`: the 4b read, applied here
|
|
61
|
+
* without the carve-out's duration floor (no workflow changed, so no `run:` body can have been
|
|
62
|
+
* gutted). Check-runs name steps, not commands, so "the step that runs the added script" is not
|
|
63
|
+
* measurable as such; "the step trunk failed in now passes" is, and it is the claim a cure makes.
|
|
64
|
+
* The pin admission adds one test (#476's open question, answered): a pin can drop a TRANSITIVELY
|
|
65
|
+
* installed tool, and the Python template then skips that tool's step with the job still `success`.
|
|
66
|
+
* Steps before trunk's failure point are covered by the superset; steps AFTER it were skipped on
|
|
67
|
+
* trunk and so say nothing. So no step after the last one that ran on trunk may be `skipped` on the
|
|
68
|
+
* branch. That refuses a repo that never had, say, mypy when its red came before the Typecheck step
|
|
69
|
+
* — a false refusal, falling through to the ci-grant, the safe direction.
|
|
53
70
|
*
|
|
54
71
|
* THE WORKFLOW CARVE-OUT (#321) — why condition 4 could not simply stay absolute. The repair for
|
|
55
72
|
* a CI-INFRASTRUCTURE outage is, by construction, a workflow change: when trunk goes red because
|
|
@@ -126,6 +143,33 @@
|
|
|
126
143
|
* is the obvious first follow-up the moment that refusal is observed in the field, but adding it
|
|
127
144
|
* unmeasured is precisely the speculative loosening condition 4 exists to resist.
|
|
128
145
|
*
|
|
146
|
+
* DRY-RUN EVIDENCE FOR A MAIN-ONLY WORKFLOW (#474). Some checks never run on a branch at all:
|
|
147
|
+
* `release-auto.yml` fires on `workflow_run` after trunk CI, or on a schedule. 2b then refuses every
|
|
148
|
+
* fix for a red in it (the job is absent on the branch), and a human ci-grant was the only door,
|
|
149
|
+
* even for a mechanical defect. The workflow template therefore offers a DRY RUN: dispatched on the
|
|
150
|
+
* fix branch, it runs the same job and the same steps, but with every external write turned off. Steps
|
|
151
|
+
* that would publish are skipped, and their names end in `PUBLISH_STEP_MARKER`. A sentinel step named
|
|
152
|
+
* `DRY_RUN_STEP` runs only in that mode, and is how a job instance is recognised as a dry run here.
|
|
153
|
+
* Such an instance counts as the job's evidence for 2b (and hence 4a) only when, on top of 2b:
|
|
154
|
+
*
|
|
155
|
+
* D1. both step lists are measurable — trunk's ran-steps and the dry run's steps;
|
|
156
|
+
* D2. every step that RAN on trunk, the failing one included, concluded `success` in the dry run.
|
|
157
|
+
* This is the not-a-back-door proof: a red INSIDE a publishing step can never be cured this way,
|
|
158
|
+
* because the dry run skips exactly that step. It is 4b, applied to dry-run instances on every
|
|
159
|
+
* path, not only the carve-out's;
|
|
160
|
+
* D3. every step the dry run did NOT run to success is a skipped publishing step. A dry run that
|
|
161
|
+
* also skipped some ordinary step past trunk's failure point has not run the job, it has run
|
|
162
|
+
* part of it.
|
|
163
|
+
*
|
|
164
|
+
* Why a NAME marker and not a list declared in the workflow: steps are matched by exact name (D2/4b),
|
|
165
|
+
* so marking the very step that failed on trunk renames it, and D2 then reads it as absent and
|
|
166
|
+
* refuses. A list inside the workflow would be read from the branch, which is the party being graded.
|
|
167
|
+
*
|
|
168
|
+
* Limit, stated: a red in a publishing step, or in a later job that only runs after a tag (npm,
|
|
169
|
+
* deploy), cannot be cured by a dry run. That stays a ci-grant. So does a red job that ran ZERO steps
|
|
170
|
+
* (a runner that never picked it up) on the carve-out path: 4c has no usable duration for it and
|
|
171
|
+
* refuses, which is the safe direction and a deliberately unmade loosening, like the timeout case.
|
|
172
|
+
*
|
|
129
173
|
* PURE BY CONSTRUCTION, identical posture to ci-grant.js / migration-grant.js / readiness.js /
|
|
130
174
|
* shipguard.js: signals in, verdict out. No git, no network, no `gh`. The caller (tools/colab)
|
|
131
175
|
* measures containment, evidence, anti-stacking and the workflow-file diff, and hands them in.
|
|
@@ -177,6 +221,25 @@ const PYTHON_MANIFEST_REFUSAL =
|
|
|
177
221
|
* never ran is not a job that failed. */
|
|
178
222
|
const NOT_RED_CONCLUSIONS = new Set(['success', 'cancelled', 'skipped']);
|
|
179
223
|
|
|
224
|
+
/** The suffix a step name carries when the dry run skips it because it writes outside the run (#474).
|
|
225
|
+
* The template names its publishing steps with it; D3 admits no other skipped step. */
|
|
226
|
+
const PUBLISH_STEP_MARKER = '[publish]';
|
|
227
|
+
|
|
228
|
+
/** The sentinel step a dry-run job instance runs and an ordinary one skips (#474). Its successful
|
|
229
|
+
* presence is the only thing that marks an instance as a dry run here. Must match the template's
|
|
230
|
+
* step name byte for byte. */
|
|
231
|
+
const DRY_RUN_STEP = 'Dry run — nothing is tagged, released or published';
|
|
232
|
+
|
|
233
|
+
function isPublishStepName(name) {
|
|
234
|
+
return typeof name === 'string' && name.trimEnd().endsWith(PUBLISH_STEP_MARKER);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** A job instance is a dry run iff its sentinel step concluded `success`. A skipped sentinel is an
|
|
238
|
+
* ordinary run (the template's `if:` was false), never a dry one. */
|
|
239
|
+
function isDryRunSteps(steps) {
|
|
240
|
+
return Array.isArray(steps) && steps.some((s) => s && s.name === DRY_RUN_STEP && s.conclusion === 'success');
|
|
241
|
+
}
|
|
242
|
+
|
|
180
243
|
/** A step "ran" on trunk iff it reached a terminal conclusion that is not `skipped`/`cancelled`.
|
|
181
244
|
* Steps after the failing one are skipped by GitHub, and a skipped step constrains nothing. */
|
|
182
245
|
function stepRan(s) {
|
|
@@ -245,6 +308,7 @@ function shapeJobEvidence({ redRunJobs, branchRunJobs } = {}) {
|
|
|
245
308
|
conclusion: j && j.conclusion,
|
|
246
309
|
durationMs: j ? durationMs(j.startedAt, j.completedAt) : null,
|
|
247
310
|
steps: j && Array.isArray(j.steps) ? j.steps.map((s) => ({ name: s && s.name, conclusion: s && s.conclusion })) : null,
|
|
311
|
+
dryRun: !!j && isDryRunSteps(j.steps),
|
|
248
312
|
}));
|
|
249
313
|
|
|
250
314
|
return { redJobs, branchJobs };
|
|
@@ -279,13 +343,46 @@ function indexBranchJobs(branchJobs) {
|
|
|
279
343
|
const isRed = j.status === 'completed' && !NOT_RED_CONCLUSIONS.has(j.conclusion);
|
|
280
344
|
const isPending = j.status !== 'completed';
|
|
281
345
|
if (!prev) { idx.set(k, { job: j, hasRed: isRed, hasPending: isPending }); continue; }
|
|
282
|
-
const
|
|
283
|
-
|
|
346
|
+
const ok = (x) => x.status === 'completed' && x.conclusion === 'success';
|
|
347
|
+
// A green ORDINARY instance outranks a green dry run (#474): the dry-run rules only apply when
|
|
348
|
+
// a dry run is the sole evidence the branch has for that job.
|
|
349
|
+
const better = ok(j) && (!ok(prev.job) || (prev.job.dryRun && !j.dryRun));
|
|
284
350
|
idx.set(k, { job: better ? j : prev.job, hasRed: prev.hasRed || isRed, hasPending: prev.hasPending || isPending });
|
|
285
351
|
}
|
|
286
352
|
return idx;
|
|
287
353
|
}
|
|
288
354
|
|
|
355
|
+
/**
|
|
356
|
+
* The dry-run rules (#474), D1–D3 — see the module header. `red` is a trunk red job (with
|
|
357
|
+
* `ranSteps`), `mine` the branch's dry-run instance of the same job (with `steps`). Returns a refusal
|
|
358
|
+
* reason, or '' when the dry run is admissible evidence for this job.
|
|
359
|
+
*/
|
|
360
|
+
function dryRunEvidence(red, mine) {
|
|
361
|
+
const label = jobLabel(red);
|
|
362
|
+
if (!Array.isArray(red.ranSteps) || !Array.isArray(mine.steps)) {
|
|
363
|
+
return `job \`${label}\` is proven only by a dry run, and its step lists could not be read — a dry run is admissible only step by step`;
|
|
364
|
+
}
|
|
365
|
+
const mySteps = new Map();
|
|
366
|
+
for (const s of mine.steps) if (s && s.name) mySteps.set(s.name, s);
|
|
367
|
+
for (const stepName of red.ranSteps) {
|
|
368
|
+
const s = mySteps.get(stepName);
|
|
369
|
+
if (!s) {
|
|
370
|
+
return `step \`${stepName}\` RAN in job \`${label}\` on trunk and is absent from the branch's dry run — a dry run proves only the steps it executes`;
|
|
371
|
+
}
|
|
372
|
+
if (s.conclusion !== 'success') {
|
|
373
|
+
return `step \`${stepName}\` RAN in job \`${label}\` on trunk and concluded \`${s.conclusion}\` in the branch's dry run — ` +
|
|
374
|
+
'a dry run cannot cure a red in a step it does not execute (a red in a publishing step stays a ci-grant)';
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
for (const s of mine.steps) {
|
|
378
|
+
if (!s || s.conclusion === 'success') continue;
|
|
379
|
+
if (s.conclusion === 'skipped' && isPublishStepName(s.name)) continue;
|
|
380
|
+
return `step \`${s && s.name}\` concluded \`${s && s.conclusion}\` in the branch's dry run of job \`${label}\` and is not a publishing step ` +
|
|
381
|
+
`(name ending \`${PUBLISH_STEP_MARKER}\`) — a dry run may skip only the steps that write outside the run`;
|
|
382
|
+
}
|
|
383
|
+
return '';
|
|
384
|
+
}
|
|
385
|
+
|
|
289
386
|
/**
|
|
290
387
|
* Sub-test 4a (#321), and — since #297 — condition 2b of EVERY cure: every job RED on trunk exists
|
|
291
388
|
* on the branch's runs at its own head, completed and successful.
|
|
@@ -299,7 +396,8 @@ function indexBranchJobs(branchJobs) {
|
|
|
299
396
|
* that exists only on the branch: this certifies that the branch cures trunk's red, not that the
|
|
300
397
|
* branch is spotless.
|
|
301
398
|
*
|
|
302
|
-
* Returns `{ok, reason, jobs}` — `jobs` is the list of red job names proven on the branch
|
|
399
|
+
* Returns `{ok, reason, jobs, dryRunJobs}` — `jobs` is the list of red job names proven on the branch,
|
|
400
|
+
* `dryRunJobs` the subset proven only by a dry run (#474), each having passed D1–D3.
|
|
303
401
|
* Every unmeasurable input is a refusal, never a pass.
|
|
304
402
|
*/
|
|
305
403
|
function redJobsProvenOnBranch(jobEvidence) {
|
|
@@ -317,6 +415,7 @@ function redJobsProvenOnBranch(jobEvidence) {
|
|
|
317
415
|
return { ok: false, jobs: [], reason: "the branch's own run reported no jobs to compare against" };
|
|
318
416
|
}
|
|
319
417
|
const idx = indexBranchJobs(branchJobs);
|
|
418
|
+
const dryRunJobs = [];
|
|
320
419
|
|
|
321
420
|
for (const red of redJobs) {
|
|
322
421
|
if (!red || !red.name) {
|
|
@@ -341,8 +440,13 @@ function redJobsProvenOnBranch(jobEvidence) {
|
|
|
341
440
|
return { ok: false, jobs: [],
|
|
342
441
|
reason: `job \`${label}\` is red on trunk and failed in another run at the branch's own head — a job that both passed and failed at one sha has proven nothing` };
|
|
343
442
|
}
|
|
443
|
+
if (mine.dryRun) {
|
|
444
|
+
const why = dryRunEvidence(red, mine);
|
|
445
|
+
if (why) return { ok: false, jobs: [], reason: why };
|
|
446
|
+
dryRunJobs.push(red.name);
|
|
447
|
+
}
|
|
344
448
|
}
|
|
345
|
-
return { ok: true, jobs: redJobs.map((r) => r.name), reason: '' };
|
|
449
|
+
return { ok: true, jobs: redJobs.map((r) => r.name), ...(dryRunJobs.length ? { dryRunJobs } : {}), reason: '' };
|
|
346
450
|
}
|
|
347
451
|
|
|
348
452
|
/**
|
|
@@ -402,6 +506,83 @@ function workflowCarveOut(jobEvidence) {
|
|
|
402
506
|
return { ok: true, jobs, reason: '' };
|
|
403
507
|
}
|
|
404
508
|
|
|
509
|
+
/**
|
|
510
|
+
* The step proof behind the #475/#476 manifest admissions — 4b without 4c, plus (for a pin) the
|
|
511
|
+
* no-late-skip test. See the module header. Returns `{ok, reason}`; every unmeasurable input refuses.
|
|
512
|
+
* Called only after `redJobsProvenOnBranch` passed, so every red job has a successful branch instance.
|
|
513
|
+
*/
|
|
514
|
+
function manifestStepProof(jobEvidence, { noLateSkip = false } = {}) {
|
|
515
|
+
if (!jobEvidence || !Array.isArray(jobEvidence.redJobs) || !Array.isArray(jobEvidence.branchJobs)) {
|
|
516
|
+
return { ok: false, reason: 'the job-level evidence could not be measured' };
|
|
517
|
+
}
|
|
518
|
+
const idx = indexBranchJobs(jobEvidence.branchJobs);
|
|
519
|
+
for (const red of jobEvidence.redJobs) {
|
|
520
|
+
// A dry-run instance (#474) is the job's branch evidence like any other — redJobsProvenOnBranch
|
|
521
|
+
// already held it to D1–D3, which imply the superset below. See the late-skip note.
|
|
522
|
+
const entry = idx.get(jobKey(red));
|
|
523
|
+
if (!entry) return { ok: false, reason: `job \`${jobLabel(red)}\` is absent on the branch` };
|
|
524
|
+
const mine = entry.job;
|
|
525
|
+
if (!Array.isArray(red.ranSteps) || !red.ranSteps.length) {
|
|
526
|
+
return { ok: false, reason: `the steps that ran in job \`${jobLabel(red)}\` on trunk could not be read` };
|
|
527
|
+
}
|
|
528
|
+
if (!Array.isArray(mine.steps)) {
|
|
529
|
+
return { ok: false, reason: `the steps of job \`${jobLabel(red)}\` on the branch could not be read` };
|
|
530
|
+
}
|
|
531
|
+
let last = -1;
|
|
532
|
+
for (const stepName of red.ranSteps) {
|
|
533
|
+
const at = mine.steps.findIndex((s) => s && s.name === stepName);
|
|
534
|
+
if (at === -1) {
|
|
535
|
+
return { ok: false, reason: `step \`${stepName}\` ran in job \`${jobLabel(red)}\` on trunk and is absent on the branch` };
|
|
536
|
+
}
|
|
537
|
+
if (mine.steps[at].conclusion !== 'success') {
|
|
538
|
+
return { ok: false,
|
|
539
|
+
reason: `step \`${stepName}\` ran in job \`${jobLabel(red)}\` on trunk and concluded \`${mine.steps[at].conclusion}\` on the branch` };
|
|
540
|
+
}
|
|
541
|
+
if (at > last) last = at;
|
|
542
|
+
}
|
|
543
|
+
if (noLateSkip) {
|
|
544
|
+
// A dry run (#474) skips its `[publish]` steps by design, and D3 already refused any OTHER skip
|
|
545
|
+
// in it — so those, and only those, are not a dropped tool.
|
|
546
|
+
const late = mine.steps.slice(last + 1)
|
|
547
|
+
.find((s) => s && s.conclusion === 'skipped' && !(mine.dryRun && isPublishStepName(s.name)));
|
|
548
|
+
if (late) {
|
|
549
|
+
return { ok: false,
|
|
550
|
+
reason: `step \`${late.name}\` in job \`${jobLabel(red)}\` comes after trunk's failure point and was skipped on the branch — ` +
|
|
551
|
+
'trunk never reached it, so whether the pin dropped the tool it needs is unmeasurable' };
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return { ok: true, reason: '' };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Would a dry run on the branch supply the evidence 2b is missing (#474)? PURE. Returns the sorted
|
|
560
|
+
* workflow names to dispatch, or `[]`. Non-empty only when EVERY red job is either already passing
|
|
561
|
+
* on the branch (completed `success`, nothing red or pending beside it) or ABSENT from the branch's
|
|
562
|
+
* runs in a workflow listed in `dryRunCapable` — and at least one is absent. A red job that is
|
|
563
|
+
* present-but-failing, pending, or absent in a workflow without a dry-run mode means no dispatch
|
|
564
|
+
* would help, so none is asked for. Whether the dry run, once it exists, passes D1–D3 is decided
|
|
565
|
+
* then, not predicted now.
|
|
566
|
+
*/
|
|
567
|
+
function dryRunDispatchPlan(jobEvidence, dryRunCapable) {
|
|
568
|
+
const capable = new Set(Array.isArray(dryRunCapable) ? dryRunCapable : dryRunCapable instanceof Set ? [...dryRunCapable] : []);
|
|
569
|
+
if (!capable.size || !jobEvidence || !Array.isArray(jobEvidence.redJobs) || !jobEvidence.redJobs.length) return [];
|
|
570
|
+
const idx = indexBranchJobs(Array.isArray(jobEvidence.branchJobs) ? jobEvidence.branchJobs : []);
|
|
571
|
+
const want = new Set();
|
|
572
|
+
for (const red of jobEvidence.redJobs) {
|
|
573
|
+
if (!red || !red.name) return [];
|
|
574
|
+
const entry = idx.get(jobKey(red));
|
|
575
|
+
if (!entry) {
|
|
576
|
+
if (!red.workflowName || !capable.has(red.workflowName)) return [];
|
|
577
|
+
want.add(red.workflowName);
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
const mine = entry.job;
|
|
581
|
+
if (mine.status !== 'completed' || entry.hasPending || mine.conclusion !== 'success' || entry.hasRed) return [];
|
|
582
|
+
}
|
|
583
|
+
return [...want].sort();
|
|
584
|
+
}
|
|
585
|
+
|
|
405
586
|
/**
|
|
406
587
|
* The cure verdict for one branch's attempt to ship into a red trunk.
|
|
407
588
|
*
|
|
@@ -429,10 +610,17 @@ function workflowCarveOut(jobEvidence) {
|
|
|
429
610
|
* which refuses: a caller that did not measure it has not shown the instrument is intact.
|
|
430
611
|
* `manifestPaths` — the manifests whose scripts changed, named in the refusal.
|
|
431
612
|
*
|
|
613
|
+
* `manifestScriptsAddOnly` (#475) — cure-diff's classifier: `[{path, added}]` when every touched
|
|
614
|
+
* manifest's scripts change is add-only, anything else (null/undefined) when not. Only consulted when
|
|
615
|
+
* `manifestScriptsTouched` is true; a caller that does not pass it gets the pre-#475 refusal.
|
|
616
|
+
*
|
|
432
617
|
* `pythonManifestTouched` — bool, whether the diff changes a Python dependency manifest the Python
|
|
433
618
|
* template installs from (condition 6, #377). `null`/`undefined` = unmeasured, which refuses.
|
|
434
619
|
* `pythonManifestPaths` — those files, named in the refusal.
|
|
435
620
|
*
|
|
621
|
+
* `pythonPinOnly` (#476) — cure-diff's classifier: `[{path, pins}]` when every touched Python
|
|
622
|
+
* manifest changed only version specifiers. Same posture as `manifestScriptsAddOnly`.
|
|
623
|
+
*
|
|
436
624
|
* `jobEvidence` — `shapeJobEvidence(...)`'s output, or `null`. Read on EVERY cure since #297 —
|
|
437
625
|
* condition 2b (`redJobsProvenOnBranch`) — and again by the #321 carve-out when workflows were
|
|
438
626
|
* touched. `null`, an empty `redJobs`, an empty `branchJobs`, an unreadable step list and an
|
|
@@ -448,12 +636,15 @@ function workflowCarveOut(jobEvidence) {
|
|
|
448
636
|
* branch touching both — exactly the "two instrument paths, two doors" composition #321 asked for.
|
|
449
637
|
*
|
|
450
638
|
* Returns `{ok, reason}`; on success also `provenJobs` (the red job names 2b proved, additive,
|
|
451
|
-
* #297)
|
|
639
|
+
* #297), `admitted` (#475/#476 — `{scripts: [{path, added}], pins: [{path, pins}]}`, present only
|
|
640
|
+
* when a manifest admission was used) and — ONLY on a cure that went through the carve-out —
|
|
641
|
+
* `carveOut: {jobs}`. The ordinary
|
|
452
642
|
* cure's reason text is unchanged, which is what lets the caller answer "which door was this?" by
|
|
453
643
|
* the presence of `carveOut` rather than by re-deriving it.
|
|
454
644
|
*/
|
|
455
645
|
function cureVerdict({ containsRedSha, evidence, redSha, stacking, workflowsTouched, jobEvidence,
|
|
456
|
-
manifestScriptsTouched, manifestPaths, pythonManifestTouched, pythonManifestPaths
|
|
646
|
+
manifestScriptsTouched, manifestPaths, manifestScriptsAddOnly, pythonManifestTouched, pythonManifestPaths,
|
|
647
|
+
pythonPinOnly, dryRunCapable }) {
|
|
457
648
|
if (!containsRedSha) {
|
|
458
649
|
return { ok: false,
|
|
459
650
|
reason: `branch does not contain trunk's current red head \`${redSha}\` as an ancestor — ` +
|
|
@@ -473,10 +664,26 @@ function cureVerdict({ containsRedSha, evidence, redSha, stacking, workflowsTouc
|
|
|
473
664
|
}
|
|
474
665
|
const proven = redJobsProvenOnBranch(jobEvidence);
|
|
475
666
|
if (!proven.ok) {
|
|
476
|
-
|
|
667
|
+
const out = { ok: false,
|
|
477
668
|
reason: `branch's run is green, but the check trunk is red on is not proven here: ${proven.reason} — ` +
|
|
478
669
|
'a cure must pass the named failing job(s), not merely produce a green run (#297)' };
|
|
670
|
+
// #474: say which dry run would supply the missing evidence — only when every LATER condition
|
|
671
|
+
// already holds, so a dispatch is never asked for on a branch that would refuse anyway.
|
|
672
|
+
const wanted = dryRunDispatchPlan(jobEvidence, dryRunCapable);
|
|
673
|
+
// An admissible manifest change (#475/#476) does not suppress the ask: the admission is judged on
|
|
674
|
+
// the dry run's steps once it exists, exactly like any other branch instance.
|
|
675
|
+
const scriptsOk = manifestScriptsTouched === false
|
|
676
|
+
|| (manifestScriptsTouched === true && Array.isArray(manifestScriptsAddOnly) && manifestScriptsAddOnly.length > 0);
|
|
677
|
+
const pythonOk = pythonManifestTouched === false
|
|
678
|
+
|| (pythonManifestTouched === true && Array.isArray(pythonPinOnly) && pythonPinOnly.length > 0);
|
|
679
|
+
if (wanted.length && stacking && stacking.ok && scriptsOk && pythonOk
|
|
680
|
+
&& typeof workflowsTouched === 'boolean') {
|
|
681
|
+
out.dryRunWanted = wanted;
|
|
682
|
+
}
|
|
683
|
+
return out;
|
|
479
684
|
}
|
|
685
|
+
const dry = proven.dryRunJobs && proven.dryRunJobs.length ? { jobs: proven.dryRunJobs } : null;
|
|
686
|
+
const drySuffix = dry ? ` — the main-only job(s) ${dry.jobs.map((n) => `\`${n}\``).join(', ')} proven by a dry run on the branch (#474)` : '';
|
|
480
687
|
if (!stacking || !stacking.ok) {
|
|
481
688
|
return { ok: false, reason: (stacking && stacking.reason) || 'anti-stacking verdict unavailable' };
|
|
482
689
|
}
|
|
@@ -485,28 +692,61 @@ function cureVerdict({ containsRedSha, evidence, redSha, stacking, workflowsTouc
|
|
|
485
692
|
return { ok: false,
|
|
486
693
|
reason: 'branch diff could not be measured (which CI files and manifests it touches) — an unmeasured diff is never a cure' };
|
|
487
694
|
}
|
|
695
|
+
const admitted = {};
|
|
488
696
|
if (manifestScriptsTouched) {
|
|
489
697
|
const named = Array.isArray(manifestPaths) && manifestPaths.length ? manifestPaths.join(', ') : 'package.json';
|
|
490
|
-
|
|
698
|
+
if (!Array.isArray(manifestScriptsAddOnly) || !manifestScriptsAddOnly.length) {
|
|
699
|
+
return { ok: false, reason: `${MANIFEST_SCRIPTS_REFUSAL} (changed: ${named}; not add-only — a script removed, renamed, ` +
|
|
700
|
+
'changed, or a lifecycle hook added)' };
|
|
701
|
+
}
|
|
702
|
+
const proof = manifestStepProof(jobEvidence);
|
|
703
|
+
if (!proof.ok) {
|
|
704
|
+
return { ok: false, reason: `${MANIFEST_SCRIPTS_REFUSAL} (changed: ${named}). The add-only admission (#475) does not ` +
|
|
705
|
+
`admit it either: ${proof.reason}` };
|
|
706
|
+
}
|
|
707
|
+
admitted.scripts = manifestScriptsAddOnly;
|
|
491
708
|
}
|
|
492
709
|
if (pythonManifestTouched) {
|
|
493
710
|
const named = Array.isArray(pythonManifestPaths) && pythonManifestPaths.length
|
|
494
711
|
? pythonManifestPaths.join(', ') : 'a Python dependency manifest';
|
|
495
|
-
|
|
712
|
+
if (!Array.isArray(pythonPinOnly) || !pythonPinOnly.length) {
|
|
713
|
+
return { ok: false, reason: `${PYTHON_MANIFEST_REFUSAL} (changed: ${named}; not pin-only — a requirement, extra, ` +
|
|
714
|
+
'marker, include or option changed, or the file is setup.py/setup.cfg)' };
|
|
715
|
+
}
|
|
716
|
+
const proof = manifestStepProof(jobEvidence, { noLateSkip: true });
|
|
717
|
+
if (!proof.ok) {
|
|
718
|
+
return { ok: false, reason: `${PYTHON_MANIFEST_REFUSAL} (changed: ${named}). The pin-only admission (#476) does not ` +
|
|
719
|
+
`admit it either: ${proof.reason}` };
|
|
720
|
+
}
|
|
721
|
+
admitted.pins = pythonPinOnly;
|
|
496
722
|
}
|
|
723
|
+
const via = admittedText(admitted);
|
|
497
724
|
if (workflowsTouched) {
|
|
498
725
|
const carve = workflowCarveOut(jobEvidence);
|
|
499
726
|
if (!carve.ok) {
|
|
500
727
|
return { ok: false, reason: `${WORKFLOW_REFUSAL}. The #321 carve-out does not admit it either: ${carve.reason}` };
|
|
501
728
|
}
|
|
502
729
|
const detail = carve.jobs.map((j) => `\`${j.name}\` (${j.redMs}ms red on trunk, ${j.branchMs}ms passing here)`).join(', ');
|
|
503
|
-
return { ok: true, provenJobs: proven.jobs, carveOut: { jobs: carve.jobs },
|
|
730
|
+
return { ok: true, provenJobs: proven.jobs, carveOut: { jobs: carve.jobs }, ...(dry ? { dryRun: dry } : {}),
|
|
731
|
+
...(via ? { admitted } : {}),
|
|
504
732
|
reason: `branch contains red \`${redSha}\` as an ancestor AND is green at its own current head (\`${evidence.sha}\`) — proven cure, ` +
|
|
505
|
-
`admitted through the #321 workflow carve-out: every job red on trunk ran to success here with every step it took on trunk — ${detail}` };
|
|
733
|
+
`admitted through the #321 workflow carve-out: every job red on trunk ran to success here with every step it took on trunk — ${detail}${drySuffix}${via}` };
|
|
734
|
+
}
|
|
735
|
+
return { ok: true, provenJobs: proven.jobs, ...(dry ? { dryRun: dry } : {}), ...(via ? { admitted } : {}),
|
|
736
|
+
reason: `branch contains red \`${redSha}\` as an ancestor AND is green at its own current head (\`${evidence.sha}\`) — proven cure${drySuffix}${via}` };
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** The reason-text suffix naming which manifest admission(s) a cure used (#475/#476), or ''. */
|
|
740
|
+
function admittedText(admitted) {
|
|
741
|
+
const parts = [];
|
|
742
|
+
if (admitted.scripts) {
|
|
743
|
+
parts.push(`add-only package.json scripts (${admitted.scripts.map((a) => `${a.path}: ${a.added.join(',')}`).join('; ')})`);
|
|
744
|
+
}
|
|
745
|
+
if (admitted.pins) {
|
|
746
|
+
parts.push(`pin-only Python requirements (${admitted.pins.map((a) => `${a.path}: ${a.pins.join(',')}`).join('; ')})`);
|
|
506
747
|
}
|
|
507
|
-
return {
|
|
508
|
-
reason: `branch contains red \`${redSha}\` as an ancestor AND is green at its own current head (\`${evidence.sha}\`) — proven cure` };
|
|
748
|
+
return parts.length ? `; manifest change admitted as ${parts.join(' and ')}, every step trunk ran passing here` : '';
|
|
509
749
|
}
|
|
510
750
|
|
|
511
|
-
module.exports = { cureVerdict, redJobsProvenOnBranch, workflowCarveOut,
|
|
512
|
-
PYTHON_MANIFEST_REFUSAL };
|
|
751
|
+
module.exports = { cureVerdict, redJobsProvenOnBranch, workflowCarveOut, manifestStepProof, shapeJobEvidence, dryRunDispatchPlan,
|
|
752
|
+
WORKFLOW_REFUSAL, MANIFEST_SCRIPTS_REFUSAL, PYTHON_MANIFEST_REFUSAL, PUBLISH_STEP_MARKER, DRY_RUN_STEP };
|
package/tools/lib/cure-diff.js
CHANGED
|
@@ -48,6 +48,26 @@
|
|
|
48
48
|
* (`poetry.lock`, `uv.lock`, `Pipfile.lock`) are NOT read by the template and do not count; an
|
|
49
49
|
* adopter whose CI installs from one has edited the template and owns extending this list.
|
|
50
50
|
*
|
|
51
|
+
* TWO NARROW ADMISSIONS (#475, #476) — the signals above stay whole (any change still sets the flag),
|
|
52
|
+
* and next to each sits a classifier saying whether EVERY touched manifest's change is of one shape
|
|
53
|
+
* the verdict may admit on step evidence (tools/lib/ci-cure.js):
|
|
54
|
+
*
|
|
55
|
+
* - `manifestScriptsAddOnly` (#475) — every touched `package.json` exists on both sides, keeps every
|
|
56
|
+
* base script byte-for-byte (canonically), and only ADDS keys. Adding a script makes the Node
|
|
57
|
+
* template run more, never less. An added npm LIFECYCLE hook is not admitted: `postinstall`,
|
|
58
|
+
* `prepare`, or `pre<x>`/`post<x>` for a script `<x>` run inside a step that already exists and
|
|
59
|
+
* can rewrite what that step measures (e.g. replace a test binary) without a name changing.
|
|
60
|
+
* - `pythonPinOnly` (#476) — every touched Python manifest exists on both sides and differs ONLY in
|
|
61
|
+
* the version specifier (or `--hash`) of requirements present at the same position on both sides:
|
|
62
|
+
* no requirement added, removed, reordered or renamed, no extras or marker changed, and no option
|
|
63
|
+
* line (`-r`/`-c`/`-e`/index) changed. Requirements files are read line-wise; a `pyproject.toml`
|
|
64
|
+
* only inside its dependency arrays (`[project] dependencies`, `[project.optional-dependencies]`,
|
|
65
|
+
* `[dependency-groups]`, `[build-system] requires`) — every other byte must match. `setup.py` is
|
|
66
|
+
* code and `setup.cfg` is not read here: a change to either is never pin-only.
|
|
67
|
+
*
|
|
68
|
+
* Each classifier is `null` whenever the shape is not met (or not measurable) — which leaves the
|
|
69
|
+
* condition refusing exactly as before. It is a list of what changed when it IS met.
|
|
70
|
+
*
|
|
51
71
|
* FAIL CLOSED. Every unmeasurable input is `null`, never `false`: a failed diff read, a manifest
|
|
52
72
|
* blob that could not be read, a manifest that does not parse, a manifest that is a symlink or a
|
|
53
73
|
* submodule. ci-cure.js's `cureVerdict` refuses on `null`.
|
|
@@ -187,6 +207,150 @@ function scriptsBlockDiffers(baseText, headText) {
|
|
|
187
207
|
return a !== b;
|
|
188
208
|
}
|
|
189
209
|
|
|
210
|
+
/** The `scripts` object as the Node template reads it, or null when not a JSON object / not an
|
|
211
|
+
* object-valued `scripts`. */
|
|
212
|
+
function scriptsObject(text) {
|
|
213
|
+
let obj;
|
|
214
|
+
try { obj = JSON.parse(String(text).replace(/^/, '')); } catch (_) { return null; }
|
|
215
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return null;
|
|
216
|
+
const sc = obj.scripts === undefined ? {} : obj.scripts;
|
|
217
|
+
if (!sc || typeof sc !== 'object' || Array.isArray(sc)) return null;
|
|
218
|
+
return sc;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** npm runs these on its own (install, publish, pack) — never by a template step naming them. */
|
|
222
|
+
const NPM_LIFECYCLE = new Set(['preinstall', 'install', 'postinstall', 'prepare', 'prepublish',
|
|
223
|
+
'prepublishOnly', 'prepack', 'postpack', 'dependencies', 'preuninstall', 'uninstall', 'postuninstall']);
|
|
224
|
+
/** Scripts npm knows by name, whose `pre`/`post` hooks fire even when the script itself is absent. */
|
|
225
|
+
const NPM_BUILTIN = new Set(['install', 'uninstall', 'publish', 'pack', 'test', 'start', 'stop', 'restart',
|
|
226
|
+
'version', 'shrinkwrap']);
|
|
227
|
+
|
|
228
|
+
/** Whether adding script `key` (to a block whose keys are `keys`) adds a hook npm fires implicitly. */
|
|
229
|
+
function isLifecycleKey(key, keys) {
|
|
230
|
+
if (NPM_LIFECYCLE.has(key)) return true;
|
|
231
|
+
const m = /^(pre|post)(.+)$/.exec(key);
|
|
232
|
+
return !!m && (keys.has(m[2]) || NPM_BUILTIN.has(m[2]));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* PURE (#475). Whether a `package.json` scripts change is ADD-ONLY. Returns `{added: [names]}` when
|
|
237
|
+
* both sides are present, every base key is kept with an identical command, at least one key was
|
|
238
|
+
* added, and no added key is an npm lifecycle hook — else null (not admissible, or unmeasurable).
|
|
239
|
+
*/
|
|
240
|
+
function scriptsAddition(baseText, headText) {
|
|
241
|
+
if (baseText === ABSENT || headText === ABSENT || baseText === null || headText === null) return null;
|
|
242
|
+
const a = scriptsObject(baseText);
|
|
243
|
+
const b = scriptsObject(headText);
|
|
244
|
+
if (!a || !b) return null;
|
|
245
|
+
for (const k of Object.keys(a)) {
|
|
246
|
+
if (!Object.prototype.hasOwnProperty.call(b, k) || canonical(a[k]) !== canonical(b[k])) return null;
|
|
247
|
+
}
|
|
248
|
+
const keys = new Set(Object.keys(b));
|
|
249
|
+
const added = Object.keys(b).filter((k) => !Object.prototype.hasOwnProperty.call(a, k));
|
|
250
|
+
if (!added.length) return null;
|
|
251
|
+
if (added.some((k) => typeof b[k] !== 'string' || isLifecycleKey(k, keys))) return null;
|
|
252
|
+
return { added: added.sort() };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const SPEC_RE = /^(?:(?:~=|===|==|!=|<=|>=|<|>)\s*[A-Za-z0-9.*+!_-]+\s*)(?:,\s*(?:~=|===|==|!=|<=|>=|<|>)\s*[A-Za-z0-9.*+!_-]+\s*)*,?$/;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* PURE. One PEP 508 requirement split into its IDENTITY (normalised name, sorted extras, marker) and
|
|
259
|
+
* its version SPECIFIER — or null when it is not a plain name requirement (a URL `@`, a path, the old
|
|
260
|
+
* parenthesised form). Only the specifier may differ for a change to read as a pin.
|
|
261
|
+
*/
|
|
262
|
+
function parseRequirement(text) {
|
|
263
|
+
const s = String(text).trim();
|
|
264
|
+
const semi = s.indexOf(';');
|
|
265
|
+
const head = semi === -1 ? s : s.slice(0, semi);
|
|
266
|
+
// Whitespace outside quoted values is insignificant in a marker; inside one it is data.
|
|
267
|
+
const marker = semi === -1 ? '' : s.slice(semi + 1).split(/("[^"]*"|'[^']*')/)
|
|
268
|
+
.map((part, i) => (i % 2 ? part : part.replace(/\s+/g, ''))).join('');
|
|
269
|
+
if (head.includes('@')) return null;
|
|
270
|
+
const m = /^([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)\s*(?:\[([^\]]*)\])?\s*(.*)$/.exec(head.trim());
|
|
271
|
+
if (!m) return null;
|
|
272
|
+
const spec = m[3].replace(/\s+/g, '');
|
|
273
|
+
if (spec && !SPEC_RE.test(spec)) return null;
|
|
274
|
+
const name = m[1].toLowerCase().replace(/[-_.]+/g, '-');
|
|
275
|
+
const extras = (m[2] || '').split(',').map((e) => e.trim().toLowerCase()).filter(Boolean).sort().join(',');
|
|
276
|
+
return { name, identity: `${name}[${extras}];${marker}`, spec: spec.replace(/,$/, '') };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** A requirements-format file as `{skeleton: [...], reqs: [{name, spec}]}`: comment, blank and
|
|
280
|
+
* `--hash` stripped; each requirement line reduced to its identity; every other line kept verbatim
|
|
281
|
+
* (whitespace-collapsed), so an option line or an unparseable requirement must match exactly. */
|
|
282
|
+
function requirementsShape(text) {
|
|
283
|
+
const skeleton = [];
|
|
284
|
+
const reqs = [];
|
|
285
|
+
for (const raw of String(text).replace(/\\\r?\n/g, ' ').split(/\r?\n/)) {
|
|
286
|
+
const line = raw.replace(/(^|\s)#.*$/, '').replace(/\s+/g, ' ').trim();
|
|
287
|
+
if (!line) continue;
|
|
288
|
+
if (line.startsWith('-')) { skeleton.push(`opt ${line}`); continue; }
|
|
289
|
+
const bare = line.replace(/\s--hash(?:=|\s+)\S+/g, '').trim();
|
|
290
|
+
const r = parseRequirement(bare);
|
|
291
|
+
if (!r) { skeleton.push(`raw ${line}`); continue; }
|
|
292
|
+
skeleton.push(`req ${r.identity}`);
|
|
293
|
+
reqs.push({ name: r.name, spec: r.spec });
|
|
294
|
+
}
|
|
295
|
+
return { skeleton, reqs };
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Is this `pyproject.toml` array (key `key` in table `table`) a dependency list pip installs from? */
|
|
299
|
+
function isDependencyArray(table, key) {
|
|
300
|
+
const k = key.replace(/^["']|["']$/g, '');
|
|
301
|
+
return (table === 'project' && k === 'dependencies')
|
|
302
|
+
|| table === 'project.optional-dependencies'
|
|
303
|
+
|| table === 'dependency-groups'
|
|
304
|
+
|| (table === 'build-system' && k === 'requires');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const TOML_STRING = /"((?:[^"\\]|\\.)*)"|'([^']*)'/g;
|
|
308
|
+
|
|
309
|
+
/** A `pyproject.toml` as `{skeleton, reqs}`: every line verbatim, except that inside a dependency array
|
|
310
|
+
* each requirement string is reduced to its identity. */
|
|
311
|
+
function pyprojectShape(text) {
|
|
312
|
+
const skeleton = [];
|
|
313
|
+
const reqs = [];
|
|
314
|
+
let table = '';
|
|
315
|
+
let depth = 0; // bracket depth of the dependency array we are inside; 0 = not in one
|
|
316
|
+
for (const line of String(text).split(/\r?\n/)) {
|
|
317
|
+
const bare = line.replace(TOML_STRING, '""');
|
|
318
|
+
if (!depth) {
|
|
319
|
+
const sec = /^\s*\[\[?\s*([^\]]+?)\s*\]\]?\s*(#.*)?$/.exec(line);
|
|
320
|
+
if (sec) { table = sec[1].replace(/\s+/g, ''); skeleton.push(line); continue; }
|
|
321
|
+
const kv = /^\s*("[^"]*"|'[^']*'|[A-Za-z0-9_.-]+)\s*=\s*\[/.exec(line);
|
|
322
|
+
if (!kv || !isDependencyArray(table, kv[1])) { skeleton.push(line); continue; }
|
|
323
|
+
}
|
|
324
|
+
depth += (bare.match(/\[/g) || []).length - (bare.match(/\]/g) || []).length;
|
|
325
|
+
if (depth < 0) depth = 0;
|
|
326
|
+
skeleton.push(line.replace(TOML_STRING, (all, dq, sq) => {
|
|
327
|
+
const r = parseRequirement(dq !== undefined ? dq : sq);
|
|
328
|
+
if (!r) return all;
|
|
329
|
+
reqs.push({ name: r.name, spec: r.spec });
|
|
330
|
+
return `<${r.identity}>`;
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
return { skeleton, reqs };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* PURE (#476). Whether a Python manifest change is PIN-ONLY. Returns `{pins: [names]}` — the
|
|
338
|
+
* requirements whose specifier changed — when both sides are present, the shapes match line for
|
|
339
|
+
* line and at least one specifier differs; else null. `setup.py`/`setup.cfg` → always null.
|
|
340
|
+
*/
|
|
341
|
+
function pythonPinChange(filePath, baseText, headText) {
|
|
342
|
+
if (baseText === ABSENT || headText === ABSENT || baseText === null || headText === null) return null;
|
|
343
|
+
const base = filePath.slice(filePath.lastIndexOf('/') + 1);
|
|
344
|
+
if (base === 'setup.py' || base === 'setup.cfg') return null;
|
|
345
|
+
const shape = base === 'pyproject.toml' ? pyprojectShape : requirementsShape;
|
|
346
|
+
const a = shape(baseText);
|
|
347
|
+
const b = shape(headText);
|
|
348
|
+
if (a.skeleton.length !== b.skeleton.length || a.skeleton.some((l, i) => l !== b.skeleton[i])) return null;
|
|
349
|
+
const pins = [];
|
|
350
|
+
for (let i = 0; i < a.reqs.length; i += 1) if (a.reqs[i].spec !== b.reqs[i].spec) pins.push(b.reqs[i].name);
|
|
351
|
+
return pins.length ? { pins } : null;
|
|
352
|
+
}
|
|
353
|
+
|
|
190
354
|
/** One side's text for a raw-diff entry: `ABSENT`, the blob text, or null on a failed read. */
|
|
191
355
|
function sideText(git, repo, sha) {
|
|
192
356
|
if (!sha || ZERO_SHA.test(sha)) return ABSENT;
|
|
@@ -197,35 +361,57 @@ function sideText(git, repo, sha) {
|
|
|
197
361
|
/**
|
|
198
362
|
* The diff signals for one branch against trunk, over the merge-base range (`trunk...branch` — the
|
|
199
363
|
* same tree a squash lands). Returns `{ ok, reason, workflowsTouched, manifestScriptsTouched,
|
|
200
|
-
* manifestPaths, pythonManifestTouched, pythonManifestPaths
|
|
201
|
-
*
|
|
202
|
-
*
|
|
364
|
+
* manifestPaths, manifestScriptsAddOnly, pythonManifestTouched, pythonManifestPaths, pythonPinOnly }`
|
|
365
|
+
* (the Python pair: condition 6, #377): `ok:false` with every flag `null` when the diff itself could
|
|
366
|
+
* not be read; `manifestScriptsTouched` `true`/`false`/`null` (unmeasurable), with `manifestPaths`
|
|
367
|
+
* listing every manifest whose scripts changed. `manifestScriptsAddOnly` (#475) and `pythonPinOnly`
|
|
368
|
+
* (#476): `[]` when their condition is untouched, `[{path, added|pins}]` when EVERY touched manifest
|
|
369
|
+
* is of the admissible shape, `null` otherwise. Never throws.
|
|
203
370
|
*/
|
|
204
371
|
function cureDiffSignals(git, repo, trunk, branch) {
|
|
205
372
|
const raw = git.git(['diff', '-z', '--no-renames', '--raw', '--no-abbrev', `${trunk}...${branch}`], repo);
|
|
206
373
|
if (!raw.ok) {
|
|
207
374
|
return { ok: false, reason: `git diff ${trunk}...${branch} failed: ${(raw.stderr || '').split('\n')[0] || raw.code}`,
|
|
208
|
-
workflowsTouched: null, manifestScriptsTouched: null, manifestPaths: [],
|
|
209
|
-
pythonManifestTouched: null, pythonManifestPaths: [] };
|
|
375
|
+
workflowsTouched: null, manifestScriptsTouched: null, manifestPaths: [], manifestScriptsAddOnly: null,
|
|
376
|
+
pythonManifestTouched: null, pythonManifestPaths: [], pythonPinOnly: null };
|
|
210
377
|
}
|
|
211
378
|
const entries = parseRaw(raw.stdout);
|
|
212
379
|
const workflowsTouched = entries.some((e) => e.path.startsWith('.github/workflows/'));
|
|
213
380
|
|
|
214
381
|
const touched = [];
|
|
215
382
|
const unmeasured = [];
|
|
383
|
+
let additions = [];
|
|
216
384
|
for (const e of entries) {
|
|
217
385
|
if (!isManifest(e.path)) continue;
|
|
218
386
|
if (!FILE_MODES.has(e.oldMode) || !FILE_MODES.has(e.newMode)) { unmeasured.push(e.path); continue; }
|
|
219
387
|
if (e.oldSha && e.oldSha === e.newSha) continue; // mode-only change: same content
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
388
|
+
const before = sideText(git, repo, e.oldSha);
|
|
389
|
+
const after = sideText(git, repo, e.newSha);
|
|
390
|
+
const differs = scriptsBlockDiffers(before, after);
|
|
391
|
+
if (differs === true) {
|
|
392
|
+
touched.push(e.path);
|
|
393
|
+
const add = additions && scriptsAddition(before, after);
|
|
394
|
+
additions = add ? additions.concat([{ path: e.path, added: add.added }]) : null;
|
|
395
|
+
} else if (differs === null) unmeasured.push(e.path);
|
|
223
396
|
}
|
|
224
397
|
let manifestScriptsTouched = false;
|
|
225
398
|
if (touched.length) manifestScriptsTouched = true;
|
|
226
399
|
else if (unmeasured.length) manifestScriptsTouched = null;
|
|
227
400
|
|
|
228
401
|
const py = pythonSignal(git, repo, trunk, branch, entries);
|
|
402
|
+
// #476: whether every touched Python manifest changed only a version specifier. Read only when
|
|
403
|
+
// condition 6 actually fires, so an ordinary diff pays nothing for it.
|
|
404
|
+
let pins = py.touched === true ? [] : (py.touched === false ? [] : null);
|
|
405
|
+
if (py.touched === true) {
|
|
406
|
+
const byPath = new Map(entries.map((e) => [e.path, e]));
|
|
407
|
+
for (const p of py.paths) {
|
|
408
|
+
const e = byPath.get(p);
|
|
409
|
+
const pin = e && FILE_MODES.has(e.oldMode) && FILE_MODES.has(e.newMode)
|
|
410
|
+
&& pythonPinChange(p, sideText(git, repo, e.oldSha), sideText(git, repo, e.newSha));
|
|
411
|
+
if (!pin) { pins = null; break; }
|
|
412
|
+
pins.push({ path: p, pins: pin.pins });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
229
415
|
const reasons = [];
|
|
230
416
|
if (unmeasured.length && !touched.length) reasons.push(`could not read the scripts of: ${unmeasured.join(', ')}`);
|
|
231
417
|
if (py.touched === null) reasons.push(py.reason);
|
|
@@ -233,7 +419,9 @@ function cureDiffSignals(git, repo, trunk, branch) {
|
|
|
233
419
|
ok: true,
|
|
234
420
|
reason: reasons.join('; '),
|
|
235
421
|
workflowsTouched, manifestScriptsTouched, manifestPaths: touched,
|
|
422
|
+
manifestScriptsAddOnly: manifestScriptsTouched === false ? [] : (manifestScriptsTouched === true ? additions : null),
|
|
236
423
|
pythonManifestTouched: py.touched, pythonManifestPaths: py.paths,
|
|
424
|
+
pythonPinOnly: pins,
|
|
237
425
|
};
|
|
238
426
|
}
|
|
239
427
|
|
|
@@ -264,4 +452,5 @@ function pythonSignal(git, repo, trunk, branch, entries) {
|
|
|
264
452
|
return { touched: paths.length > 0, paths, reason: '' };
|
|
265
453
|
}
|
|
266
454
|
|
|
267
|
-
module.exports = { cureDiffSignals, scriptsBlockDiffers,
|
|
455
|
+
module.exports = { cureDiffSignals, scriptsBlockDiffers, scriptsAddition, pythonPinChange, parseRequirement,
|
|
456
|
+
isPythonManifest, pythonIncludes, ABSENT };
|
package/tools/lib/git.js
CHANGED
|
@@ -1157,6 +1157,25 @@ function ghRunJobs(repo, runDatabaseId) {
|
|
|
1157
1157
|
}));
|
|
1158
1158
|
}
|
|
1159
1159
|
|
|
1160
|
+
/**
|
|
1161
|
+
* Dispatch `workflowFile` on `ref` (#474) — `gh workflow run <file> --ref <ref> -f k=v…`. Returns
|
|
1162
|
+
* `{ok, withInputs, detail}`. If the call with inputs is refused (GitHub can validate inputs against
|
|
1163
|
+
* a workflow file that does not declare them yet), it is retried ONCE without them: the release-auto
|
|
1164
|
+
* template forces dry mode on any ref other than main, so an input-less dispatch of a capable file is
|
|
1165
|
+
* still a dry run. The caller only ever dispatches a file it read as dry-run capable at that ref.
|
|
1166
|
+
* Never waits for the run.
|
|
1167
|
+
*/
|
|
1168
|
+
function ghWorkflowDispatch(repo, workflowFile, ref, inputs = {}) {
|
|
1169
|
+
const flags = [];
|
|
1170
|
+
for (const [k, v] of Object.entries(inputs)) flags.push('-f', `${k}=${v}`);
|
|
1171
|
+
const first = run('gh', ['workflow', 'run', workflowFile, '--ref', ref, ...flags], { cwd: repo });
|
|
1172
|
+
if (first.ok) return { ok: true, withInputs: true, detail: '' };
|
|
1173
|
+
if (!flags.length) return { ok: false, withInputs: false, detail: (first.stderr || first.stdout || '').trim().split('\n')[0] || 'gh workflow run failed' };
|
|
1174
|
+
const second = run('gh', ['workflow', 'run', workflowFile, '--ref', ref], { cwd: repo });
|
|
1175
|
+
if (second.ok) return { ok: true, withInputs: false, detail: (first.stderr || '').trim().split('\n')[0] || '' };
|
|
1176
|
+
return { ok: false, withInputs: false, detail: (second.stderr || second.stdout || '').trim().split('\n')[0] || 'gh workflow run failed' };
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1160
1179
|
/**
|
|
1161
1180
|
* Issues claimed by the current gh user in a repo = assigned to @me AND labeled in-progress
|
|
1162
1181
|
* (that pairing is exactly what `colab claim` writes). Returns array of numbers, or null on failure.
|
|
@@ -1177,7 +1196,7 @@ module.exports = {
|
|
|
1177
1196
|
dirtyTracked, dirtyUntracked, dirtyAny,
|
|
1178
1197
|
ghAvailable, ghState, ghIssueEdit, ghListLabels, ghOpenIssueNumbersByLabel, ghAssignedIssues,
|
|
1179
1198
|
ghCurrentLogin, ghIssueView, ghIssueComment, ghRunForSha, ghRunForCommit, ghRunsForCommit, ghRunsForRef, ghRunsAtCommit, ghRunForCommitAnyRef, commitTimeMs, ghRunsSince, summarizeRunsForCommit, isRepoOwnedRun,
|
|
1180
|
-
ghRunJobCount, ghRunJobs,
|
|
1199
|
+
ghRunJobCount, ghRunJobs, ghWorkflowDispatch,
|
|
1181
1200
|
ghIssueListByLabel, ghLabelDelete, ghLabelCreate, ghListLabelsDetailed, ghLabelEditDescription,
|
|
1182
1201
|
ghApi, isGraphqlRateLimit, ghIssueRelease, ghClaimHolder, ghIssueLabelEvents, ghIssueLabelActors,
|
|
1183
1202
|
ghPrForBranch, ghPrCreate, ghPrClose, ghRepoVisibility,
|
|
@@ -265,9 +265,57 @@ function prereleaseTagTriggers({ readFile, workflows, deploy }) {
|
|
|
265
265
|
return out;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
// --------------------------------------------------- workflow_dispatch inputs (#474)
|
|
269
|
+
//
|
|
270
|
+
// The names declared under `on: workflow_dispatch: inputs:`, in order. `[]` for a bare
|
|
271
|
+
// `workflow_dispatch:` (or one with no inputs), and for a workflow with no dispatch trigger at all —
|
|
272
|
+
// a caller asking "can this be dispatched with dry_run?" needs the same answer for both. Same
|
|
273
|
+
// pragmatic, indentation-aware scan as parseWorkflowOn; the inline `on:` forms carry no inputs.
|
|
274
|
+
function workflowDispatchInputs(text) {
|
|
275
|
+
if (!text) return [];
|
|
276
|
+
const all = text.split(/\r?\n/);
|
|
277
|
+
const start = all.findIndex((l) => /^(on|["']on["'])\s*:\s*(#.*)?$/.test(l));
|
|
278
|
+
if (start === -1) return [];
|
|
279
|
+
const body = [];
|
|
280
|
+
for (let i = start + 1; i < all.length; i++) {
|
|
281
|
+
if (/^\S/.test(all[i])) break;
|
|
282
|
+
body.push(all[i]);
|
|
283
|
+
}
|
|
284
|
+
const indentOf = (l) => l.match(/^(\s*)/)[1].length;
|
|
285
|
+
const meaningful = (l) => l.trim() && !/^\s*#/.test(l);
|
|
286
|
+
const block = (from, parentIndent) => {
|
|
287
|
+
const out = [];
|
|
288
|
+
for (let j = from; j < body.length; j++) {
|
|
289
|
+
if (!meaningful(body[j])) continue;
|
|
290
|
+
if (indentOf(body[j]) <= parentIndent) break;
|
|
291
|
+
out.push(j);
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
294
|
+
};
|
|
295
|
+
const wd = body.findIndex((l) => /^\s*workflow_dispatch\s*:/.test(l));
|
|
296
|
+
if (wd === -1) return [];
|
|
297
|
+
const wdIndent = indentOf(body[wd]);
|
|
298
|
+
const inp = block(wd + 1, wdIndent).find((j) => /^\s*inputs\s*:\s*(#.*)?$/.test(body[j]));
|
|
299
|
+
if (inp === undefined) return [];
|
|
300
|
+
const lines = block(inp + 1, indentOf(body[inp]));
|
|
301
|
+
if (!lines.length) return [];
|
|
302
|
+
const keyIndent = Math.min(...lines.map((j) => indentOf(body[j])));
|
|
303
|
+
return lines.filter((j) => indentOf(body[j]) === keyIndent)
|
|
304
|
+
.map((j) => (body[j].match(/^\s*([A-Za-z_][\w-]*)\s*:/) || [])[1]).filter(Boolean);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// A workflow's top-level `name:` — what the runs API reports as `workflowName` — or null.
|
|
308
|
+
function workflowNameOf(text) {
|
|
309
|
+
if (!text) return null;
|
|
310
|
+
const m = text.match(/^name:\s*(.+?)\s*$/m);
|
|
311
|
+
if (!m) return null;
|
|
312
|
+
return m[1].replace(/\s+#.*$/, '').replace(/^["']|["']$/g, '').trim() || null;
|
|
313
|
+
}
|
|
314
|
+
|
|
268
315
|
module.exports = {
|
|
269
316
|
PRERELEASE_TAG_PROBE,
|
|
270
317
|
parseWorkflowOn, listField, githubFilterRegex, githubFilterMatches, workflowFiresOnTag,
|
|
271
318
|
workflowFiresOnBranchPush, workflowsFiringOnBranchPush,
|
|
272
319
|
isDeployWorkflow, isReleaseTagTemplateCopy, prereleaseTagTriggers,
|
|
320
|
+
workflowDispatchInputs, workflowNameOf,
|
|
273
321
|
};
|