@intentius/chant 0.124.88 → 0.124.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actor.d.ts +36 -1
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +39 -1
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +1 -2
- package/dist/ci-base.d.ts +30 -0
- package/dist/ci-base.d.ts.map +1 -0
- package/dist/ci-base.js +33 -0
- package/dist/ci-comment-commands.d.ts +193 -0
- package/dist/ci-comment-commands.d.ts.map +1 -0
- package/dist/ci-comment-commands.js +353 -0
- package/dist/ci-comment-replies.d.ts +40 -0
- package/dist/ci-comment-replies.d.ts.map +1 -0
- package/dist/ci-comment-replies.js +59 -0
- package/dist/ci-evidence-from-job.d.ts +25 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -1
- package/dist/ci-evidence-from-job.js +43 -2
- package/dist/ci-evidence-jobs.d.ts +30 -1
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +46 -3
- package/dist/ci-image.d.ts +21 -4
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +62 -10
- package/dist/ci-job-guard.d.ts +42 -45
- package/dist/ci-job-guard.d.ts.map +1 -1
- package/dist/ci-job-guard.js +206 -3
- package/dist/ci-note-commands.d.ts +104 -4
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +131 -38
- package/dist/ci-product-words.d.ts +42 -0
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +25 -0
- package/dist/ci-product.d.ts +72 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +73 -6
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +29 -2
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +2 -1
- package/dist/cli/handlers/ci-check.d.ts +1 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +17 -7
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +33 -7
- package/dist/cli/handlers/components.d.ts.map +1 -1
- package/dist/cli/handlers/components.js +3 -1
- package/dist/cli/handlers/generated-check.d.ts +8 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -1
- package/dist/cli/handlers/generated-check.js +31 -1
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +121 -4
- package/dist/cli/handlers/pr-comment.d.ts +33 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
- package/dist/cli/handlers/pr-comment.js +201 -0
- package/dist/cli/handlers/pr-env.d.ts.map +1 -1
- package/dist/cli/handlers/pr-env.js +6 -3
- package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
- package/dist/cli/handlers/pr-notes.js +23 -1
- package/dist/cli/handlers/pr.d.ts +23 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +71 -23
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +2 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +11 -2
- package/dist/cli/handlers/run-wave.d.ts.map +1 -1
- package/dist/cli/handlers/run-wave.js +180 -4
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +41 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +31 -0
- package/dist/cli/registry.d.ts +19 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/auto-release.d.ts.map +1 -1
- package/dist/components/auto-release.js +2 -1
- package/dist/components/pr-checks.d.ts +97 -6
- package/dist/components/pr-checks.d.ts.map +1 -1
- package/dist/components/pr-checks.js +107 -13
- package/dist/components/pr-pipeline.d.ts +19 -14
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +7 -13
- package/dist/components/product-pipeline.d.ts +96 -3
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +120 -14
- package/dist/components/product-plan.d.ts +203 -6
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +250 -43
- package/dist/drift-record.d.ts +7 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +19 -0
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +63 -31
- package/dist/forge-check/contract.d.ts +11 -1
- package/dist/forge-check/contract.d.ts.map +1 -1
- package/dist/forge-check/contract.js +4 -1
- package/dist/forge-check/index.d.ts +2 -0
- package/dist/forge-check/index.d.ts.map +1 -1
- package/dist/forge-check/index.js +2 -0
- package/dist/gate-resume-run.d.ts +9 -1
- package/dist/gate-resume-run.d.ts.map +1 -1
- package/dist/gate-resume-run.js +26 -3
- package/dist/generated-check.d.ts +18 -4
- package/dist/generated-check.d.ts.map +1 -1
- package/dist/generated-check.js +37 -5
- package/dist/image-pins.d.ts +26 -0
- package/dist/image-pins.d.ts.map +1 -0
- package/dist/image-pins.js +19 -0
- package/dist/lexicon.d.ts +93 -4
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-applied.d.ts +9 -0
- package/dist/lifecycle/gate-applied.d.ts.map +1 -1
- package/dist/lifecycle/git.d.ts +11 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +30 -3
- package/dist/lifecycle/publish-npm.d.ts +11 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +27 -1
- package/dist/lifecycle/reach-locks.d.ts +131 -0
- package/dist/lifecycle/reach-locks.d.ts.map +1 -0
- package/dist/lifecycle/reach-locks.js +118 -0
- package/dist/lifecycle/release-cut.d.ts +3 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +15 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +1 -2
- package/dist/notify-product.d.ts +12 -3
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +10 -6
- package/dist/op/activities/source-release.d.ts.map +1 -1
- package/dist/op/activities/source-release.js +2 -1
- package/dist/op/activities/source-rollback.d.ts.map +1 -1
- package/dist/op/activities/source-rollback.js +2 -1
- package/dist/op/apply-status.d.ts +84 -0
- package/dist/op/apply-status.d.ts.map +1 -0
- package/dist/op/apply-status.js +106 -0
- package/dist/op/before-merge-decide.d.ts +102 -0
- package/dist/op/before-merge-decide.d.ts.map +1 -0
- package/dist/op/before-merge-decide.js +142 -0
- package/dist/op/before-merge-done.d.ts +56 -0
- package/dist/op/before-merge-done.d.ts.map +1 -0
- package/dist/op/before-merge-done.js +69 -0
- package/dist/op/before-merge-store.d.ts +20 -0
- package/dist/op/before-merge-store.d.ts.map +1 -0
- package/dist/op/before-merge-store.js +48 -0
- package/dist/op/before-merge.d.ts +150 -0
- package/dist/op/before-merge.d.ts.map +1 -0
- package/dist/op/before-merge.js +207 -0
- package/dist/op/follow-on-run.d.ts +117 -0
- package/dist/op/follow-on-run.d.ts.map +1 -0
- package/dist/op/follow-on-run.js +154 -0
- package/dist/op/follow-on-store.d.ts +17 -0
- package/dist/op/follow-on-store.d.ts.map +1 -0
- package/dist/op/follow-on-store.js +54 -0
- package/dist/op/gate.d.ts +6 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +10 -1
- package/dist/op/index.d.ts +5 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +2 -0
- package/dist/op/op-waves-after-plan.d.ts +13 -0
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.d.ts +10 -2
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.js +19 -5
- package/dist/op/op-waves-follow-on.d.ts +162 -0
- package/dist/op/op-waves-follow-on.d.ts.map +1 -0
- package/dist/op/op-waves-follow-on.js +355 -0
- package/dist/op/op-waves-render-spec.d.ts +100 -0
- package/dist/op/op-waves-render-spec.d.ts.map +1 -0
- package/dist/op/op-waves-render-spec.js +162 -0
- package/dist/op/op-waves-run.d.ts +148 -6
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +873 -100
- package/dist/op/op-waves-split.d.ts +122 -0
- package/dist/op/op-waves-split.d.ts.map +1 -0
- package/dist/op/op-waves-split.js +166 -0
- package/dist/op/op-waves.d.ts +24 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +18 -1
- package/dist/op/schedule-overdue.d.ts +15 -1
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +77 -5
- package/dist/op/stage-hooks.d.ts +36 -1
- package/dist/op/stage-hooks.d.ts.map +1 -1
- package/dist/op/stage-hooks.js +17 -3
- package/dist/op/wave-stop.d.ts +67 -0
- package/dist/op/wave-stop.d.ts.map +1 -0
- package/dist/op/wave-stop.js +129 -0
- package/dist/planned-files.d.ts +76 -0
- package/dist/planned-files.d.ts.map +1 -0
- package/dist/planned-files.js +108 -0
- package/dist/pr-forge-job.d.ts +22 -0
- package/dist/pr-forge-job.d.ts.map +1 -0
- package/dist/pr-forge-job.js +46 -0
- package/dist/pr-loop.d.ts +3 -6
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +4 -81
- package/dist/pr-plan-note.d.ts +97 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +94 -1
- package/dist/pr-post.d.ts +28 -3
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +146 -13
- package/dist/pr-status.d.ts +16 -0
- package/dist/pr-status.d.ts.map +1 -0
- package/dist/pr-status.js +90 -0
- package/dist/ref-gate-init.d.ts +16 -2
- package/dist/ref-gate-init.d.ts.map +1 -1
- package/dist/ref-gate-init.js +24 -13
- package/dist/release-floors.d.ts +39 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +63 -25
- package/dist/render-module.d.ts +15 -0
- package/dist/render-module.d.ts.map +1 -0
- package/dist/render-module.js +73 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/wave-blocked.d.ts +7 -1
- package/dist/wave-blocked.d.ts.map +1 -1
- package/dist/wave-blocked.js +7 -2
- package/dist/wave-runtime.mjs +366 -350
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +3 -2
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +2 -1
- package/dist/workspace/release-workflow.d.ts +4 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +10 -7
- package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +15 -8
- package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +30 -10
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -1
- package/package.json +1 -1
- package/src/actor.test.ts +68 -2
- package/src/actor.ts +61 -1
- package/src/chant-install.test.ts +2 -3
- package/src/chant-install.ts +1 -2
- package/src/ci-base.test.ts +41 -0
- package/src/ci-base.ts +43 -0
- package/src/ci-comment-commands.test.ts +439 -0
- package/src/ci-comment-commands.ts +428 -0
- package/src/ci-comment-replies.ts +78 -0
- package/src/ci-commit.test.ts +2 -3
- package/src/ci-evidence-from-job.test.ts +18 -0
- package/src/ci-evidence-from-job.ts +58 -2
- package/src/ci-evidence-jobs.ts +50 -5
- package/src/ci-image.test.ts +130 -10
- package/src/ci-image.ts +85 -12
- package/src/ci-job-guard.before-merge.test.ts +148 -0
- package/src/ci-job-guard.follow-on-record.test.ts +137 -0
- package/src/ci-job-guard.follow-on.test.ts +144 -0
- package/src/ci-job-guard.ts +221 -3
- package/src/ci-note-commands.test.ts +76 -1
- package/src/ci-note-commands.ts +198 -46
- package/src/ci-product-words.ts +59 -0
- package/src/ci-product.ts +90 -6
- package/src/cli/commands/build.test.ts +41 -0
- package/src/cli/commands/build.ts +27 -2
- package/src/cli/handlers/approve.ts +2 -1
- package/src/cli/handlers/ci-check.ts +19 -7
- package/src/cli/handlers/ci-evidence.ts +29 -8
- package/src/cli/handlers/components.ts +3 -1
- package/src/cli/handlers/generated-check.ts +31 -1
- package/src/cli/handlers/lock-reach.test.ts +103 -0
- package/src/cli/handlers/lock.ts +100 -4
- package/src/cli/handlers/pr-comment.ts +187 -0
- package/src/cli/handlers/pr-env.ts +6 -3
- package/src/cli/handlers/pr-notes.ts +30 -6
- package/src/cli/handlers/pr-record.test.ts +1 -1
- package/src/cli/handlers/pr.ts +64 -21
- package/src/cli/handlers/promote.ts +2 -1
- package/src/cli/handlers/release.e2e.test.ts +35 -0
- package/src/cli/handlers/release.ts +14 -2
- package/src/cli/handlers/run-wave.ts +170 -4
- package/src/cli/handlers/run.ts +2 -1
- package/src/cli/main.ts +41 -2
- package/src/cli/parse-args.ts +23 -0
- package/src/cli/registry.ts +19 -1
- package/src/components/auto-release.ts +2 -1
- package/src/components/pr-checks.ts +165 -17
- package/src/components/pr-pipeline.ts +22 -18
- package/src/components/product-pipeline.apply-status.test.ts +50 -0
- package/src/components/product-pipeline.ts +204 -17
- package/src/components/product-plan.test.ts +60 -4
- package/src/components/product-plan.ts +367 -50
- package/src/drift-record.test.ts +20 -0
- package/src/drift-record.ts +16 -0
- package/src/floor-table.data.ts +63 -31
- package/src/forge-check/contract.ts +12 -1
- package/src/forge-check/forge-check.test.ts +17 -0
- package/src/forge-check/index.ts +2 -0
- package/src/gate-resume-run.ts +27 -3
- package/src/generated-check.e2e.test.ts +21 -1
- package/src/generated-check.test.ts +66 -0
- package/src/generated-check.ts +51 -10
- package/src/image-pins.ts +31 -0
- package/src/lexicon.ts +89 -1
- package/src/lifecycle/gate-applied.ts +7 -0
- package/src/lifecycle/git.test.ts +48 -0
- package/src/lifecycle/git.ts +27 -4
- package/src/lifecycle/publish-npm.ts +31 -1
- package/src/lifecycle/reach-locks.test.ts +87 -0
- package/src/lifecycle/reach-locks.ts +169 -0
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +56 -0
- package/src/lifecycle/release-images.ts +1 -2
- package/src/notify-product.ts +19 -8
- package/src/op/activities/source-release.ts +2 -1
- package/src/op/activities/source-rollback.ts +2 -1
- package/src/op/apply-status.test.ts +83 -0
- package/src/op/apply-status.ts +132 -0
- package/src/op/before-merge-decide.ts +190 -0
- package/src/op/before-merge-done.ts +99 -0
- package/src/op/before-merge-store.ts +44 -0
- package/src/op/before-merge.test.ts +201 -0
- package/src/op/before-merge.ts +266 -0
- package/src/op/follow-on-run.ts +206 -0
- package/src/op/follow-on-store.ts +54 -0
- package/src/op/gate-resume.test.ts +27 -0
- package/src/op/gate.ts +16 -1
- package/src/op/index.ts +15 -0
- package/src/op/op-waves-after-plan.ts +13 -0
- package/src/op/op-waves-evidence-jobs.ts +21 -7
- package/src/op/op-waves-follow-on-record.test.ts +152 -0
- package/src/op/op-waves-follow-on.test.ts +247 -0
- package/src/op/op-waves-follow-on.ts +385 -0
- package/src/op/op-waves-notify-words.test.ts +18 -0
- package/src/op/op-waves-render-spec.test.ts +159 -0
- package/src/op/op-waves-render-spec.ts +171 -0
- package/src/op/op-waves-run.ts +973 -94
- package/src/op/op-waves-split-product.test.ts +288 -0
- package/src/op/op-waves-split-step.test.ts +298 -0
- package/src/op/op-waves-split.test.ts +196 -0
- package/src/op/op-waves-split.ts +189 -0
- package/src/op/op-waves.ts +31 -3
- package/src/op/schedule-overdue.test.ts +72 -1
- package/src/op/schedule-overdue.ts +84 -6
- package/src/op/stage-hooks.ts +52 -4
- package/src/op/wave-stop.test.ts +72 -0
- package/src/op/wave-stop.ts +139 -0
- package/src/planned-files.test.ts +80 -0
- package/src/planned-files.ts +134 -0
- package/src/pr-forge-job.test.ts +53 -0
- package/src/pr-forge-job.ts +46 -0
- package/src/pr-loop-narrowed.test.ts +2 -1
- package/src/pr-loop-words.test.ts +2 -1
- package/src/pr-loop.test.ts +1 -2
- package/src/pr-loop.ts +4 -80
- package/src/pr-plan-note.ts +155 -3
- package/src/pr-post-replan.test.ts +144 -0
- package/src/pr-post-subject.test.ts +230 -0
- package/src/pr-post.test.ts +2 -1
- package/src/pr-post.ts +151 -15
- package/src/pr-status.ts +91 -0
- package/src/ref-gate-init.ts +30 -11
- package/src/release-floors.ts +81 -25
- package/src/render-module.ts +73 -0
- package/src/state-migration-record.test.ts +2 -3
- package/src/state-migration.ts +1 -2
- package/src/wave-blocked.ts +9 -4
- package/src/workspace/ci-green-cli.ts +3 -2
- package/src/workspace/ci-green-workflow.test.ts +32 -1
- package/src/workspace/release-train.ts +2 -1
- package/src/workspace/release-workflow.test.ts +36 -5
- package/src/workspace/release-workflow.ts +10 -7
- package/src/workspace/trust/check-evidence-report.ts +15 -8
- package/src/workspace/trust/check-evidence.test.ts +5 -0
- package/src/workspace/trust/ref-gate-cli.ts +30 -8
- package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
- package/src/workspace/trust/ref-gate.test.ts +10 -0
- package/src/workspace/workspace-run.ts +2 -1
|
@@ -41,6 +41,22 @@ export interface ScheduledWatch {
|
|
|
41
41
|
* missing schedule's line names it.
|
|
42
42
|
*/
|
|
43
43
|
schedule?: ScheduledRunsQuery["schedule"];
|
|
44
|
+
/**
|
|
45
|
+
* The product plan's targets whose note checks this watch (#4988), such
|
|
46
|
+
* as the environment a drift watch reads. Left out, every target's note
|
|
47
|
+
* does. A note of another target checks neither the watch nor a
|
|
48
|
+
* discovered Op of the same name.
|
|
49
|
+
*/
|
|
50
|
+
targets?: readonly string[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The watches the note of `target` checks (#4988): the ones with no
|
|
55
|
+
* `targets`, and the ones naming it. Without a target, every one.
|
|
56
|
+
*/
|
|
57
|
+
export function watchesForTarget(watches: readonly ScheduledWatch[], target: string | undefined): ScheduledWatch[] {
|
|
58
|
+
if (target === undefined) return [...watches];
|
|
59
|
+
return watches.filter((w) => w.targets === undefined || w.targets.includes(target));
|
|
44
60
|
}
|
|
45
61
|
|
|
46
62
|
/** An Op the plan note warns about. */
|
|
@@ -213,9 +229,61 @@ function yamlDocs(repoRoot: string, path: string): Record<string, unknown>[] {
|
|
|
213
229
|
|
|
214
230
|
/** When `path` was first committed (ISO 8601), if the checkout's history has it. */
|
|
215
231
|
export function fileAdded(repoRoot: string, path: string): string | undefined {
|
|
216
|
-
|
|
232
|
+
return addedCommit(repoRoot, path)?.at;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The oldest commit the checkout's history says added `path`, with its commit time. */
|
|
236
|
+
function addedCommit(repoRoot: string, path: string): { sha: string; at: string } | undefined {
|
|
237
|
+
const r = spawnSync("git", ["-C", repoRoot, "log", "--format=%H %cI", "--diff-filter=A", "--", path], { encoding: "utf-8" });
|
|
217
238
|
if (r.status !== 0) return undefined;
|
|
218
|
-
|
|
239
|
+
const last = r.stdout.trim().split("\n").filter(Boolean).pop();
|
|
240
|
+
if (!last) return undefined;
|
|
241
|
+
const [sha, at] = last.split(" ");
|
|
242
|
+
return sha && at ? { sha, at } : undefined;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* The commits a shallow checkout's history stops at (#4952), from git's
|
|
247
|
+
* `shallow` file. Empty for a full clone.
|
|
248
|
+
*/
|
|
249
|
+
function shallowBoundary(repoRoot: string): Set<string> {
|
|
250
|
+
const r = spawnSync("git", ["-C", repoRoot, "rev-parse", "--path-format=absolute", "--git-path", "shallow"], { encoding: "utf-8" });
|
|
251
|
+
if (r.status !== 0) return new Set();
|
|
252
|
+
try {
|
|
253
|
+
return new Set(readFileSync(r.stdout.trim(), "utf-8").split("\n").map((l) => l.trim()).filter(Boolean));
|
|
254
|
+
} catch {
|
|
255
|
+
return new Set();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** How long the check waits for the fetch that deepens a shallow checkout. */
|
|
260
|
+
const DEEPEN_TIMEOUT_MS = 120_000;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* When `path` was added, read so a shallow checkout does not under-report
|
|
264
|
+
* (#4952). A CI checkout is often shallow, and its oldest commit lists
|
|
265
|
+
* every file as added, so a job that never ran would count from that
|
|
266
|
+
* commit. When the commit found is at the shallow boundary, the check
|
|
267
|
+
* fetches the rest of the history once per run (`git fetch --unshallow`,
|
|
268
|
+
* with the job's own credentials) and reads the file again. When that fetch
|
|
269
|
+
* fails, the boundary's time is still a lower bound, so the check counts
|
|
270
|
+
* from it and says so in the log.
|
|
271
|
+
*/
|
|
272
|
+
function addedDate(repoRoot: string, path: string, op: string, state: { deepened?: boolean; failed?: string }, log: (line: string) => void): string | undefined {
|
|
273
|
+
let found = addedCommit(repoRoot, path);
|
|
274
|
+
if (!found || !shallowBoundary(repoRoot).has(found.sha)) return found?.at;
|
|
275
|
+
if (!state.deepened) {
|
|
276
|
+
state.deepened = true;
|
|
277
|
+
const r = spawnSync("git", ["-C", repoRoot, "fetch", "--quiet", "--unshallow"], { encoding: "utf-8", timeout: DEEPEN_TIMEOUT_MS });
|
|
278
|
+
if (r.status !== 0) state.failed = (r.stderr || r.error?.message || `git fetch exited ${r.status}`).trim().split("\n")[0];
|
|
279
|
+
// A checkout with no remote answers 0 and stays shallow.
|
|
280
|
+
else if (shallowBoundary(repoRoot).size > 0) state.failed = "git fetch --unshallow left it shallow";
|
|
281
|
+
found = addedCommit(repoRoot, path) ?? found;
|
|
282
|
+
}
|
|
283
|
+
if (state.failed !== undefined && shallowBoundary(repoRoot).has(found.sha)) {
|
|
284
|
+
log(`schedule check: the checkout is shallow and its history could not be fetched, so Op ${op} counts from its oldest commit, ${found.at.slice(0, 10)}: ${state.failed}`);
|
|
285
|
+
}
|
|
286
|
+
return found.at;
|
|
219
287
|
}
|
|
220
288
|
|
|
221
289
|
const HINT: Record<ForgeKind, string> = {
|
|
@@ -278,6 +346,8 @@ export async function checkOverdueOps(input: {
|
|
|
278
346
|
if (!forge.scheduledRuns) return [];
|
|
279
347
|
const log = (line: string): void => input.log(`${input.logPrefix ?? ""}${line}`);
|
|
280
348
|
const out: OverdueOp[] = [];
|
|
349
|
+
// One fetch at most per check, however many Ops count from a shallow boundary (#4952).
|
|
350
|
+
const history: { deepened?: boolean; failed?: string } = {};
|
|
281
351
|
for (const watch of input.watches) {
|
|
282
352
|
const file = opPipelineFile(input.repoRoot, forge.kind, watch, input.member);
|
|
283
353
|
if (!file) continue;
|
|
@@ -288,7 +358,7 @@ export async function checkOverdueOps(input: {
|
|
|
288
358
|
log(`schedule check: ${forge.kind} did not say when Op ${watch.op} last ran, so it is not checked: ${(err instanceof Error ? err.message : String(err)).split("\n")[0]}`);
|
|
289
359
|
continue;
|
|
290
360
|
}
|
|
291
|
-
const found = overdueVerdict(watch, forge.kind, runs, runs.last ? undefined :
|
|
361
|
+
const found = overdueVerdict(watch, forge.kind, runs, runs.last ? undefined : addedDate(input.repoRoot, file, watch.op, history, log), input.now);
|
|
292
362
|
if (found) {
|
|
293
363
|
log(found.message);
|
|
294
364
|
out.push(input.label ? { ...found, message: `${input.label}${found.message}` } : found);
|
|
@@ -319,6 +389,8 @@ export const PLAN_WATCHES_ENV = "CHANT_PLAN_WATCHES";
|
|
|
319
389
|
const OP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.:-]*$/;
|
|
320
390
|
const REL_PATH = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9_.\/-]+$/;
|
|
321
391
|
const VAR_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
392
|
+
/** A product plan target's name, as ../components/product-plan.ts takes it. */
|
|
393
|
+
const WATCH_TARGET = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
322
394
|
|
|
323
395
|
/**
|
|
324
396
|
* Why `watch` is not a scheduled watch a pipeline may name (#4888), or
|
|
@@ -339,6 +411,8 @@ export function scheduledWatchProblem(watch: unknown): string | undefined {
|
|
|
339
411
|
if (s.value !== undefined && !plain(s.value)) return `watch ${watch.op}'s schedule value is not a plain word`;
|
|
340
412
|
if (s.not !== undefined && (!Array.isArray(s.not) || !s.not.every(plain))) return `watch ${watch.op}'s schedule not is not a list of plain words`;
|
|
341
413
|
}
|
|
414
|
+
// #4988: the targets whose note checks the watch, by name.
|
|
415
|
+
if (watch.targets !== undefined && (!Array.isArray(watch.targets) || watch.targets.length === 0 || watch.targets.some((t) => typeof t !== "string" || !WATCH_TARGET.test(t)))) return `watch ${watch.op}'s targets are not a list of target names`;
|
|
342
416
|
return undefined;
|
|
343
417
|
}
|
|
344
418
|
|
|
@@ -389,14 +463,18 @@ export async function overdueOpsAt(
|
|
|
389
463
|
/**
|
|
390
464
|
* A product's own scheduled watches (#4888), checked beside the
|
|
391
465
|
* discovered Ops; one of the same name takes the discovered Op's place.
|
|
392
|
-
* They are checked even when discovery fails.
|
|
466
|
+
* They are checked even when discovery fails. #4988: with `member`, the
|
|
467
|
+
* product plan's target, a watch whose `targets` leave it out is not
|
|
468
|
+
* checked, and neither is the discovered Op of its name.
|
|
393
469
|
*/
|
|
394
470
|
watches?: readonly ScheduledWatch[];
|
|
395
471
|
} & OverdueWords,
|
|
396
472
|
): Promise<OverdueOp[]> {
|
|
397
473
|
const { forge } = input;
|
|
398
474
|
if (!forge?.scheduledRuns) return [];
|
|
399
|
-
const
|
|
475
|
+
const all = input.watches ?? [];
|
|
476
|
+
const own = watchesForTarget(all, input.member);
|
|
477
|
+
const elsewhere = all.filter((w) => !own.includes(w));
|
|
400
478
|
let discovered: ScheduledWatch[] = [];
|
|
401
479
|
try {
|
|
402
480
|
const { discoverOps } = await import("./discover");
|
|
@@ -406,7 +484,7 @@ export async function overdueOpsAt(
|
|
|
406
484
|
input.log(`${input.logPrefix ?? ""}could not check the scheduled Ops, so none is reported overdue: ${err instanceof Error ? err.message : String(err)}`);
|
|
407
485
|
if (own.length === 0) return [];
|
|
408
486
|
}
|
|
409
|
-
const watches = [...discovered.filter((d) => !own.some((w) => w.op === d.op)), ...own];
|
|
487
|
+
const watches = [...discovered.filter((d) => !own.some((w) => w.op === d.op) && !elsewhere.some((w) => w.op === d.op)), ...own];
|
|
410
488
|
if (watches.length === 0) return [];
|
|
411
489
|
try {
|
|
412
490
|
const top = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd: input.cwd, encoding: "utf-8" });
|
package/src/op/stage-hooks.ts
CHANGED
|
@@ -101,6 +101,36 @@ export const spawnExec: OpWaveExec = (argv, cwd, env) => {
|
|
|
101
101
|
/** {@link OpWaveExec} for {@link runStageHooksAsync} (#4334): the exit code comes back as a promise, so the event loop runs while a hook does. */
|
|
102
102
|
export type OpWaveAsyncExec = (argv: string[], cwd: string, env?: Record<string, string>) => Promise<number>;
|
|
103
103
|
|
|
104
|
+
/**
|
|
105
|
+
* One call of a hook a product serves in its own process (#4994), as
|
|
106
|
+
* {@link OpWaveInProcessHook} gets it: the hook's name and moment, its run
|
|
107
|
+
* for a `perRun` hook, the argv its command would have run with, the job's
|
|
108
|
+
* directory and the `CHANT_*` variables the command would have had.
|
|
109
|
+
*/
|
|
110
|
+
export interface OpWaveInProcessHookCall {
|
|
111
|
+
name: string;
|
|
112
|
+
moment: CiHookMoment;
|
|
113
|
+
target?: string;
|
|
114
|
+
argv: string[];
|
|
115
|
+
cwd: string;
|
|
116
|
+
env: Record<string, string>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A hook a product's bin serves in the job's own process (#4994), in place
|
|
121
|
+
* of the hook's command: the spec, read at base, still names the hook and
|
|
122
|
+
* its command, and a job whose process hands a function under that name
|
|
123
|
+
* calls it with the command's argv and variables. Its exit code counts as
|
|
124
|
+
* the command's would, a hold included: it writes `CHANT_HOLD` and returns
|
|
125
|
+
* non-zero. It runs in whichever job runs the hook, so one split wave's plan,
|
|
126
|
+
* gate and applying jobs each call it in their own process; what it needs
|
|
127
|
+
* from an earlier job it reads from files that job left, such as its own
|
|
128
|
+
* under `opWaveProductStateDir` (`./op-waves-split.ts`), which the plan job
|
|
129
|
+
* hands the gate and applying jobs. This replaces a hook that called back
|
|
130
|
+
* into a long-lived product process over a socket.
|
|
131
|
+
*/
|
|
132
|
+
export type OpWaveInProcessHook = (call: OpWaveInProcessHookCall) => Promise<number>;
|
|
133
|
+
|
|
104
134
|
/** {@link spawnExec} on `spawn`: it rejects when the command cannot start. */
|
|
105
135
|
export const spawnExecAsync: OpWaveAsyncExec = (argv, cwd, env) =>
|
|
106
136
|
new Promise((resolve, reject) => {
|
|
@@ -220,6 +250,10 @@ export interface HookPlace {
|
|
|
220
250
|
/** One hook call {@link hookListSteps} asks its driver to run. The driver sends back the exit code. */
|
|
221
251
|
interface HookCall {
|
|
222
252
|
label: string;
|
|
253
|
+
/** The hook's name and moment, and its run for a `perRun` hook: what an in-process hook is found by and gets (#4994). */
|
|
254
|
+
name: string;
|
|
255
|
+
moment: CiHookMoment;
|
|
256
|
+
target?: string;
|
|
223
257
|
argv: string[];
|
|
224
258
|
cwd: string;
|
|
225
259
|
env: Record<string, string>;
|
|
@@ -269,7 +303,7 @@ function* hookListSteps(
|
|
|
269
303
|
for (const call of calls) {
|
|
270
304
|
const label = `${moment} hook ${name}${call.target ? ` (${call.target})` : ""}`;
|
|
271
305
|
rmSync(join(cwd, holdPath), { force: true });
|
|
272
|
-
const code = yield { label, argv: call.argv, cwd, env: call.env };
|
|
306
|
+
const code = yield { label, name, moment, ...(call.target ? { target: call.target } : {}), argv: call.argv, cwd, env: call.env };
|
|
273
307
|
const base = { moment, name, ...(call.target ? { target: call.target } : {}), exit: code };
|
|
274
308
|
if (code === 0) {
|
|
275
309
|
out.outcomes.push({ ...base, outcome: "passed" });
|
|
@@ -296,6 +330,13 @@ function* hookListSteps(
|
|
|
296
330
|
return out;
|
|
297
331
|
}
|
|
298
332
|
|
|
333
|
+
/** The in-process hook a product serves under `name` (#4994), or undefined: an own property that is a function. */
|
|
334
|
+
export function inProcessHookOf(hooks: Readonly<Record<string, OpWaveInProcessHook>> | undefined, name: string): OpWaveInProcessHook | undefined {
|
|
335
|
+
if (!hooks || !Object.prototype.hasOwnProperty.call(hooks, name)) return undefined;
|
|
336
|
+
const fn = hooks[name];
|
|
337
|
+
return typeof fn === "function" ? fn : undefined;
|
|
338
|
+
}
|
|
339
|
+
|
|
299
340
|
/** The exit code a call that did not start counts as, after its error is logged. */
|
|
300
341
|
function didNotRun(call: HookCall, err: unknown, log: (line: string) => void): number {
|
|
301
342
|
log(`${call.label} did not run: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -330,9 +371,13 @@ export function runHookList(
|
|
|
330
371
|
return step.value;
|
|
331
372
|
}
|
|
332
373
|
|
|
333
|
-
/**
|
|
374
|
+
/**
|
|
375
|
+
* {@link runHookList} with an exec that returns a promise (#4334). A hook
|
|
376
|
+
* whose name `at.inProcess` holds is called in this process in place of its
|
|
377
|
+
* command (#4994).
|
|
378
|
+
*/
|
|
334
379
|
export async function runHookListAsync(
|
|
335
|
-
at: Omit<HookPlace, "exec"> & { exec: OpWaveAsyncExec },
|
|
380
|
+
at: Omit<HookPlace, "exec"> & { exec: OpWaveAsyncExec; inProcess?: Readonly<Record<string, OpWaveInProcessHook>> },
|
|
336
381
|
moment: CiHookMoment,
|
|
337
382
|
hooks: readonly OpWaveHook[] | undefined,
|
|
338
383
|
runs: readonly OpWaveHookRun[],
|
|
@@ -345,7 +390,10 @@ export async function runHookListAsync(
|
|
|
345
390
|
const call = step.value;
|
|
346
391
|
let code: number;
|
|
347
392
|
try {
|
|
348
|
-
|
|
393
|
+
const own = inProcessHookOf(at.inProcess, call.name);
|
|
394
|
+
code = own
|
|
395
|
+
? await own({ name: call.name, moment: call.moment, ...(call.target ? { target: call.target } : {}), argv: call.argv, cwd: call.cwd, env: call.env })
|
|
396
|
+
: await at.exec(call.argv, call.cwd, call.env);
|
|
349
397
|
} catch (err) {
|
|
350
398
|
code = didNotRun(call, err, at.log);
|
|
351
399
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4979: the wave stop a comment writes before a re-run, `_waves/<op>.stops.json`
|
|
3
|
+
* on `chant/lifecycle`, and what a wave job says when it waits behind it.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, test } from "vitest";
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { mkdtempSync, realpathSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { parseWaveStops, renderWaveStops, setWaveStop, waveStopAt, waveStopLine, waveStopped, WAVE_STOPS_KEPT } from "./wave-stop";
|
|
11
|
+
|
|
12
|
+
const SHA = "a".repeat(40);
|
|
13
|
+
|
|
14
|
+
function git(cwd: string, ...args: string[]): string {
|
|
15
|
+
return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function initRepo(): string {
|
|
19
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), "chant-wave-stop-")));
|
|
20
|
+
git(dir, "init", "-q", "-b", "main");
|
|
21
|
+
git(dir, "config", "user.email", "test@chant.dev");
|
|
22
|
+
git(dir, "config", "user.name", "Test");
|
|
23
|
+
git(dir, "config", "commit.gpgsign", "false");
|
|
24
|
+
writeFileSync(join(dir, "README.md"), "# t\n");
|
|
25
|
+
git(dir, "add", "README.md");
|
|
26
|
+
git(dir, "commit", "-q", "-m", "init");
|
|
27
|
+
return dir;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("the stops file (#4979)", () => {
|
|
31
|
+
test("reads back what it wrote, drops what is not a stop, and keeps the newest", () => {
|
|
32
|
+
const file = { version: 1 as const, stops: { [SHA]: { through: 2, at: "2026-11-10T00:00:00.000Z", by: "alice", pr: 12 } } };
|
|
33
|
+
expect(parseWaveStops(renderWaveStops(file))).toEqual(file);
|
|
34
|
+
expect(parseWaveStops('{"version":1,"stops":{"nope":{"through":1,"at":"x"},"' + SHA + '":{"through":0,"at":"x"}}}')).toEqual({ version: 1, stops: {} });
|
|
35
|
+
expect(parseWaveStops("not json")).toEqual({ version: 1, stops: {} });
|
|
36
|
+
const many = { version: 1 as const, stops: Object.fromEntries(Array.from({ length: WAVE_STOPS_KEPT + 5 }, (_, i) => [i.toString(16).padStart(40, "0"), { through: 1, at: `2026-11-10T00:00:${String(i).padStart(2, "0")}.000Z` }])) };
|
|
37
|
+
const kept = parseWaveStops(renderWaveStops(many)).stops;
|
|
38
|
+
expect(Object.keys(kept)).toHaveLength(WAVE_STOPS_KEPT);
|
|
39
|
+
expect(kept["0".repeat(40)]).toBeUndefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a wave after the stop waits, and the stop's own wave runs", () => {
|
|
43
|
+
const stop = { through: 2, at: "x" };
|
|
44
|
+
expect(waveStopped(stop, 2)).toBe(false);
|
|
45
|
+
expect(waveStopped(stop, 3)).toBe(true);
|
|
46
|
+
expect(waveStopped(undefined, 9)).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("a stop on chant/lifecycle (#4979)", () => {
|
|
51
|
+
test("is written for a commit, read by the wave job at that commit, and cleared", async () => {
|
|
52
|
+
const dir = initRepo();
|
|
53
|
+
const head = git(dir, "rev-parse", "HEAD");
|
|
54
|
+
expect(await waveStopLine("tf-apply", 3, { cwd: dir })).toBeUndefined();
|
|
55
|
+
expect(await setWaveStop("tf-apply", head, { through: 2, at: "2026-11-10T00:00:00.000Z", by: "alice", pr: 12 }, { cwd: dir })).toEqual({ changed: true, pushed: false });
|
|
56
|
+
expect(await waveStopAt("tf-apply", head, { cwd: dir })).toEqual({ through: 2, at: "2026-11-10T00:00:00.000Z", by: "alice", pr: 12 });
|
|
57
|
+
expect(git(dir, "show", "chant/lifecycle:_waves/tf-apply.stops.json")).toContain('"through": 2');
|
|
58
|
+
expect(await waveStopLine("tf-apply", 2, { cwd: dir })).toBeUndefined();
|
|
59
|
+
expect(await waveStopLine("tf-apply", 3, { cwd: dir })).toBe(`wave 3 waits: alice's comment on pull request 12 ran tf-apply again at ${head.slice(0, 12)} through wave 2; comment the apply again without a wave to run the waves after it`);
|
|
60
|
+
// Another op's waves, and another commit, are not stopped.
|
|
61
|
+
expect(await waveStopLine("other", 3, { cwd: dir })).toBeUndefined();
|
|
62
|
+
expect(await waveStopAt("tf-apply", SHA, { cwd: dir })).toBeUndefined();
|
|
63
|
+
expect(await setWaveStop("tf-apply", head, null, { cwd: dir })).toEqual({ changed: true, pushed: false });
|
|
64
|
+
expect(await waveStopLine("tf-apply", 3, { cwd: dir })).toBeUndefined();
|
|
65
|
+
expect(await setWaveStop("tf-apply", head, null, { cwd: dir })).toEqual({ changed: false, pushed: false });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("refuses an op or a commit that is not one", async () => {
|
|
69
|
+
await expect(setWaveStop("a b", SHA, null)).rejects.toThrow(/not a stops file name/);
|
|
70
|
+
await expect(setWaveStop("tf-apply", "main", null)).rejects.toThrow(/not a commit sha/);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wave stop on a re-run (#4979): `/<product> apply wave-<n>` on a merged
|
|
3
|
+
* pull request runs its apply again and stops after wave n.
|
|
4
|
+
*
|
|
5
|
+
* A forge re-run cannot be told where to stop: GitHub's re-run of a run's
|
|
6
|
+
* failed jobs runs every job after them, Forgejo's dispatch runs the whole
|
|
7
|
+
* workflow, and GitLab runs the jobs after a retried one by itself. So the
|
|
8
|
+
* comment's job writes the stop on `chant/lifecycle` before it starts the
|
|
9
|
+
* run, `_waves/<op>.stops.json`, keyed by the commit the run applies, and
|
|
10
|
+
* each wave job of op `<op>` at that commit reads it before it plans: a wave
|
|
11
|
+
* after the stop waits, as a wave whose gate has no approval waits (exit 3),
|
|
12
|
+
* so a later `/<product> apply` runs it. An apply comment without a wave
|
|
13
|
+
* clears the commit's stop. The newest {@link WAVE_STOPS_KEPT} stops are
|
|
14
|
+
* kept.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { fetchLifecycleStatus, getHeadCommit, pushLifecycleStatus, readBlobBySha, readPathSha, writeBlobToPath } from "../lifecycle/git";
|
|
18
|
+
|
|
19
|
+
/** The directory of the stops on `chant/lifecycle`. */
|
|
20
|
+
export const WAVE_STOPS_DIR = "_waves";
|
|
21
|
+
|
|
22
|
+
/** How many commits' stops the file keeps. */
|
|
23
|
+
export const WAVE_STOPS_KEPT = 50;
|
|
24
|
+
|
|
25
|
+
/** The stops file of op `op`. */
|
|
26
|
+
export function waveStopsFile(op: string): string {
|
|
27
|
+
return `${op}.stops.json`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** One commit's stop: the last wave that runs, and who asked. */
|
|
31
|
+
export interface WaveStop {
|
|
32
|
+
through: number;
|
|
33
|
+
at: string;
|
|
34
|
+
by?: string;
|
|
35
|
+
pr?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The stops file. */
|
|
39
|
+
export interface WaveStopsFile {
|
|
40
|
+
version: 1;
|
|
41
|
+
stops: Record<string, WaveStop>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
45
|
+
const OP = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/;
|
|
46
|
+
|
|
47
|
+
/** Read a stops file; anything that is not one reads as no stops, and a malformed entry is dropped. */
|
|
48
|
+
export function parseWaveStops(text: string | null): WaveStopsFile {
|
|
49
|
+
let doc: unknown;
|
|
50
|
+
try {
|
|
51
|
+
doc = JSON.parse(text ?? "null");
|
|
52
|
+
} catch {
|
|
53
|
+
return { version: 1, stops: {} };
|
|
54
|
+
}
|
|
55
|
+
const stops: Record<string, WaveStop> = {};
|
|
56
|
+
const given = doc && typeof doc === "object" && (doc as { version?: unknown }).version === 1 ? (doc as { stops?: unknown }).stops : undefined;
|
|
57
|
+
if (given && typeof given === "object") {
|
|
58
|
+
for (const [sha, s] of Object.entries(given as Record<string, unknown>)) {
|
|
59
|
+
const v = s as Partial<WaveStop> | null;
|
|
60
|
+
if (!SHA.test(sha) || !v || !Number.isInteger(v.through) || (v.through as number) < 1 || typeof v.at !== "string") continue;
|
|
61
|
+
stops[sha] = { through: v.through as number, at: v.at, ...(typeof v.by === "string" ? { by: v.by } : {}), ...(Number.isInteger(v.pr) ? { pr: v.pr as number } : {}) };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { version: 1, stops };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The file's text: the newest {@link WAVE_STOPS_KEPT} stops, by commit. */
|
|
68
|
+
export function renderWaveStops(file: WaveStopsFile): string {
|
|
69
|
+
const newest = Object.entries(file.stops).sort((a, b) => b[1].at.localeCompare(a[1].at)).slice(0, WAVE_STOPS_KEPT);
|
|
70
|
+
return `${JSON.stringify({ version: 1, stops: Object.fromEntries(newest.sort((a, b) => a[0].localeCompare(b[0]))) }, null, 2)}\n`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether wave `k` waits under `stop`. */
|
|
74
|
+
export function waveStopped(stop: WaveStop | undefined, k: number): boolean {
|
|
75
|
+
return stop !== undefined && k > stop.through;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The stop of op `op` at commit `sha`, from the local `chant/lifecycle` after a fetch. Undefined when there is none or the branch cannot be read. */
|
|
79
|
+
export async function waveStopAt(op: string, sha: string, opts: { cwd?: string } = {}): Promise<WaveStop | undefined> {
|
|
80
|
+
if (!OP.test(op) || !SHA.test(sha)) return undefined;
|
|
81
|
+
await fetchLifecycleStatus(opts);
|
|
82
|
+
const blob = await readPathSha(WAVE_STOPS_DIR, waveStopsFile(op), opts);
|
|
83
|
+
if (!blob) return undefined;
|
|
84
|
+
return parseWaveStops(await readBlobBySha(blob, opts)).stops[sha];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* What a wave job of op `op` says when wave `k` waits behind a comment's
|
|
89
|
+
* stop at the job's checkout (`git rev-parse HEAD`). Undefined when it runs:
|
|
90
|
+
* no stop, no commit to read, or a branch that cannot be read, so a stop
|
|
91
|
+
* never fails a wave that would have run. `sha` (#4987) names the commit
|
|
92
|
+
* in place of the checkout's: a split wave's gate job runs at the default
|
|
93
|
+
* branch and reads the stop of the decided head.
|
|
94
|
+
*/
|
|
95
|
+
export async function waveStopLine(op: string, k: number, opts: { cwd?: string; sha?: string } = {}): Promise<string | undefined> {
|
|
96
|
+
let sha: string;
|
|
97
|
+
try {
|
|
98
|
+
sha = opts.sha ?? (await getHeadCommit(opts));
|
|
99
|
+
} catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
let stop: WaveStop | undefined;
|
|
103
|
+
try {
|
|
104
|
+
stop = await waveStopAt(op, sha, opts);
|
|
105
|
+
} catch {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
if (!waveStopped(stop, k)) return undefined;
|
|
109
|
+
const who = stop!.by ? `${stop!.by}'s` : "a";
|
|
110
|
+
const where = stop!.pr !== undefined ? ` on pull request ${stop!.pr}` : "";
|
|
111
|
+
return `wave ${k} waits: ${who} comment${where} ran ${op} again at ${sha.slice(0, 12)} through wave ${stop!.through}; comment the apply again without a wave to run the waves after it`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Set op `op`'s stop at commit `sha`, or clear it (`stop` null), and push
|
|
116
|
+
* `chant/lifecycle`. Read, written and pushed again when another writer
|
|
117
|
+
* pushed first, up to three times.
|
|
118
|
+
*/
|
|
119
|
+
export async function setWaveStop(op: string, sha: string, stop: WaveStop | null, opts: { cwd?: string } = {}): Promise<{ changed: boolean; pushed: boolean }> {
|
|
120
|
+
if (!OP.test(op)) throw new Error(`the op name ${JSON.stringify(op)} is not a stops file name`);
|
|
121
|
+
if (!SHA.test(sha)) throw new Error(`${JSON.stringify(sha)} is not a commit sha`);
|
|
122
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
123
|
+
const fetched = await fetchLifecycleStatus(opts);
|
|
124
|
+
if (fetched.status === "unreachable") throw new Error("chant/lifecycle could not be fetched, so the stop was not written");
|
|
125
|
+
const blob = await readPathSha(WAVE_STOPS_DIR, waveStopsFile(op), opts);
|
|
126
|
+
const file = parseWaveStops(blob ? await readBlobBySha(blob, opts) : null);
|
|
127
|
+
const next: WaveStopsFile = { version: 1, stops: { ...file.stops } };
|
|
128
|
+
if (stop) next.stops[sha] = stop;
|
|
129
|
+
else delete next.stops[sha];
|
|
130
|
+
if (renderWaveStops(next) === renderWaveStops(file)) return { changed: false, pushed: false };
|
|
131
|
+
const what = stop ? `Stop ${op} after wave ${stop.through} at ${sha.slice(0, 12)}` : `Clear the stop of ${op} at ${sha.slice(0, 12)}`;
|
|
132
|
+
await writeBlobToPath(WAVE_STOPS_DIR, waveStopsFile(op), renderWaveStops(next), what, { ...opts, expectPriorPathSha: blob });
|
|
133
|
+
const pushed = await pushLifecycleStatus(opts);
|
|
134
|
+
if (pushed.status === "stale") continue;
|
|
135
|
+
if (pushed.status === "failed") throw new Error(`could not push the stop to chant/lifecycle (${pushed.stderr.trim()})`);
|
|
136
|
+
return { changed: true, pushed: pushed.status === "pushed" };
|
|
137
|
+
}
|
|
138
|
+
throw new Error("chant/lifecycle kept moving, so the stop was not written; comment again");
|
|
139
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** #4966: a product's planned files with their modes, and its stale generated files found by header. */
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { describe, expect, test } from "vitest";
|
|
6
|
+
import { planFile, planRemoval, staleGeneratedFiles, writePlannedFiles } from "./planned-files";
|
|
7
|
+
|
|
8
|
+
const dir = (): string => mkdtempSync(join(tmpdir(), "chant-planned-"));
|
|
9
|
+
const modeOf = (p: string): number => statSync(p).mode & 0o777;
|
|
10
|
+
|
|
11
|
+
describe("planFile and writePlannedFiles", () => {
|
|
12
|
+
test("plans against the disk, writes the plan with its modes, and leaves an unchanged file alone", () => {
|
|
13
|
+
const root = dir();
|
|
14
|
+
const script = join(root, "bin", "run.sh");
|
|
15
|
+
const config = join(root, "tool.yml");
|
|
16
|
+
writeFileSync(config, "a: 1\n");
|
|
17
|
+
const plan = [planFile(script, "#!/bin/sh\n", { mode: 0o755 }), planFile(config, "a: 1\n"), planFile(join(root, "new.txt"), "new\n")];
|
|
18
|
+
expect(plan.map((f) => f.status)).toEqual(["created", "unchanged", "created"]);
|
|
19
|
+
writePlannedFiles(plan);
|
|
20
|
+
expect(readFileSync(script, "utf-8")).toBe("#!/bin/sh\n");
|
|
21
|
+
expect(modeOf(script)).toBe(0o755);
|
|
22
|
+
expect(readFileSync(join(root, "new.txt"), "utf-8")).toBe("new\n");
|
|
23
|
+
expect(planFile(script, "#!/bin/sh\n", { mode: 0o755 }).status).toBe("unchanged");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("a file whose content is the same and whose mode is not is updated", () => {
|
|
27
|
+
const root = dir();
|
|
28
|
+
const script = join(root, "run.sh");
|
|
29
|
+
writeFileSync(script, "#!/bin/sh\n");
|
|
30
|
+
chmodSync(script, 0o644);
|
|
31
|
+
const plan = planFile(script, "#!/bin/sh\n", { mode: 0o755, local: true });
|
|
32
|
+
expect(plan).toEqual({ path: script, status: "updated", content: "#!/bin/sh\n", mode: 0o755, local: true });
|
|
33
|
+
writePlannedFiles([plan]);
|
|
34
|
+
expect(modeOf(script)).toBe(0o755);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("a removal is planned only for a file that is there, and written by unlinking it", () => {
|
|
38
|
+
const root = dir();
|
|
39
|
+
const old = join(root, "old.yml");
|
|
40
|
+
writeFileSync(old, "x\n");
|
|
41
|
+
expect(planRemoval(join(root, "absent.yml"))).toBeUndefined();
|
|
42
|
+
const removal = planRemoval(old)!;
|
|
43
|
+
expect(removal.status).toBe("removed");
|
|
44
|
+
writePlannedFiles([removal, removal]);
|
|
45
|
+
expect(existsSync(old)).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("staleGeneratedFiles", () => {
|
|
50
|
+
const HEADER = "# Rendered by tool ci from tool.config.ts.";
|
|
51
|
+
|
|
52
|
+
test("lists the files that open with the header and are not rendered now, never a person's own", () => {
|
|
53
|
+
const root = dir();
|
|
54
|
+
mkdirSync(join(root, ".github", "workflows"), { recursive: true });
|
|
55
|
+
mkdirSync(join(root, ".forgejo", "workflows"), { recursive: true });
|
|
56
|
+
writeFileSync(join(root, ".github/workflows/tool-pr.yml"), `${HEADER}\non: pull_request\n`);
|
|
57
|
+
writeFileSync(join(root, ".github/workflows/tool-old.yml"), `${HEADER}\r\non: push\n`);
|
|
58
|
+
writeFileSync(join(root, ".github/workflows/mine.yml"), "# my own\non: push\n");
|
|
59
|
+
writeFileSync(join(root, ".github/workflows/notes.md"), `${HEADER}\n`);
|
|
60
|
+
writeFileSync(join(root, ".forgejo/workflows/tool-pr.yml"), `${HEADER}\n`);
|
|
61
|
+
writeFileSync(join(root, ".gitlab-ci.yml"), `${HEADER}\n`);
|
|
62
|
+
const stale = staleGeneratedFiles({
|
|
63
|
+
root,
|
|
64
|
+
dirs: [".github/workflows", ".forgejo/workflows", ".gitlab"],
|
|
65
|
+
files: [".gitlab-ci.yml"],
|
|
66
|
+
match: /\.ya?ml$/,
|
|
67
|
+
header: HEADER,
|
|
68
|
+
rendered: [".github/workflows/tool-pr.yml"],
|
|
69
|
+
});
|
|
70
|
+
expect(stale).toEqual([".gitlab-ci.yml", ".github/workflows/tool-old.yml", ".forgejo/workflows/tool-pr.yml"]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("takes a test of the text in place of the header line", () => {
|
|
74
|
+
const root = dir();
|
|
75
|
+
writeFileSync(join(root, "a.yml"), "# generated by tool\n");
|
|
76
|
+
writeFileSync(join(root, "b.yml"), "# hand-written\n");
|
|
77
|
+
expect(staleGeneratedFiles({ root, dirs: ["."], header: (t) => t.includes("generated by tool"), rendered: [] })).toEqual(["a.yml"]);
|
|
78
|
+
expect(staleGeneratedFiles({ root, files: ["a.yml", "b.yml", "c.yml"], header: (t) => t.includes("generated by tool"), rendered: [] })).toEqual(["a.yml"]);
|
|
79
|
+
});
|
|
80
|
+
});
|