@kungfu-tech/buildchain 4.1.3-alpha.1 → 4.1.3-alpha.3
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/architecture/action-taxonomy.json +24 -0
- package/architecture/agent-change-map.md +256 -2
- package/architecture/ci-lane-change-budget.json +374 -0
- package/architecture/decisions/0005-minimal-consumer-contract.md +122 -0
- package/architecture/decisions/0006-business-attempt-journal.md +89 -0
- package/architecture/decisions/0007-hosted-pipeline-controller.md +106 -0
- package/architecture/decisions/0008-pipeline-product-publication.md +99 -0
- package/architecture/decisions/0009-pipeline-version-preparation.md +186 -0
- package/architecture/internal-capabilities.json +361 -2
- package/architecture/maintainability-debt.json +6 -4
- package/architecture/maintainability-policy.json +8 -8
- package/architecture/minimal-consumer-migration.json +7567 -0
- package/architecture/product-upstreams.json +20 -0
- package/architecture/release-topology.json +282 -11
- package/architecture/universal-workflow-bootstrap.json +12 -0
- package/architecture/universal-workflow-capability-policy.json +1 -1
- package/architecture/workflow-taxonomy.json +66 -0
- package/dist/readers/business-attempt.cjs +809 -0
- package/dist/site/buildchain-contract.json +7 -5
- package/dist/site/buildchain-site.json +18 -13
- package/dist/site/capability-registry.json +3 -3
- package/dist/site/kfd-claims.json +385 -10
- package/dist/site/kfd-upstream-aggregate.json +1 -1
- package/dist/site/manual-registry.json +1 -1
- package/dist/site/node-api-registry.json +21 -21
- package/dist/site/page-registry.json +13 -8
- package/dist/site/public-surface-audit.json +258 -7
- package/dist/site/publication-authority-registry.json +141 -1
- package/dist/site/publication-registry.json +4 -4
- package/dist/site/site-manifest.json +5 -5
- package/dist/site/workflow-registry.json +522 -7
- package/docs/node-api-reference.md +39 -39
- package/docs/runtime-entry.md +45 -5
- package/docs/workflow-catalog.md +6 -0
- package/package.json +4 -3
- package/packages/core/build/standalone/build.js +7 -1
- package/packages/core/consumer/buildchain-config.js +2 -21
- package/packages/core/consumer/contract/entries.js +85 -0
- package/packages/core/consumer/contract/examples.js +96 -0
- package/packages/core/consumer/contract/identity.js +65 -0
- package/packages/core/consumer/contract/inspection.js +45 -0
- package/packages/core/consumer/contract/plan.js +146 -0
- package/packages/core/consumer/contract/products.js +119 -0
- package/packages/core/consumer/contract/reader.js +47 -0
- package/packages/core/consumer/contract/shape.js +46 -0
- package/packages/core/dev-delivery/candidate/admission.js +9 -5
- package/packages/core/dev-delivery/candidate/reservation.js +11 -0
- package/packages/core/dev-delivery/candidate/source-paths.js +12 -4
- package/packages/core/dev-delivery/commands/project-cut-merge-queue-admission.mjs +47 -20
- package/packages/core/dev-delivery/native/actions.js +7 -1
- package/packages/core/dev-delivery/native/heartbeat-action.js +16 -0
- package/packages/core/dev-delivery/native/heartbeat.js +6 -4
- package/packages/core/dev-delivery/queue/landing-action.js +5 -0
- package/packages/core/governance/buildchain-publication-authority.js +6 -0
- package/packages/core/paper/operations/bootstrap.js +2 -0
- package/packages/core/paper/paper-npm-bootstrap.js +2 -2
- package/packages/core/providers/github/attempt-index.js +60 -0
- package/packages/core/providers/github/attempt-journal.js +154 -0
- package/packages/core/providers/github/discussions/materials.js +7 -2
- package/packages/core/providers/github/pipeline-checkout.js +49 -0
- package/packages/core/providers/github/pipeline-entry-runs.js +203 -0
- package/packages/core/providers/github/pipeline-events.js +52 -0
- package/packages/core/providers/github/pipeline-integration.js +95 -0
- package/packages/core/providers/github/pipeline-policy.js +213 -0
- package/packages/core/providers/github/pipeline-product-payload.js +50 -0
- package/packages/core/providers/github/pipeline-product-release.js +191 -0
- package/packages/core/providers/github/pipeline-publication-artifacts.js +153 -0
- package/packages/core/providers/github/pipeline-release-evidence.js +111 -0
- package/packages/core/providers/github/pipeline-run-entry.js +86 -0
- package/packages/core/providers/github/pipeline-runs.js +132 -0
- package/packages/core/providers/github/pipeline-source.js +178 -0
- package/packages/core/providers/github/pipeline-stable-source.js +354 -0
- package/packages/core/providers/github/pipeline-version-artifacts.js +91 -0
- package/packages/core/providers/github/pipeline-version-readback.js +117 -0
- package/packages/core/providers/github/pipeline-version.js +199 -0
- package/packages/core/providers/github/pipeline-worker.js +108 -0
- package/packages/core/publication/candidate/registry-hydration.js +2 -2
- package/packages/core/publication/npm/pack-preview.js +2 -2
- package/packages/core/publication/npm/pack-result.js +31 -0
- package/packages/core/publication/npm/package.js +3 -6
- package/packages/core/publication/npm/pipeline-channel.js +87 -0
- package/packages/core/publication/npm/pipeline-provider.js +109 -0
- package/packages/core/publication/npm/registry.js +12 -9
- package/packages/core/publication/pipeline/actions.js +116 -0
- package/packages/core/publication/pipeline/apply.js +188 -0
- package/packages/core/publication/pipeline/build-segments.js +107 -0
- package/packages/core/publication/pipeline/capsules.js +89 -0
- package/packages/core/publication/pipeline/context.js +39 -0
- package/packages/core/publication/pipeline/development-anchor.js +91 -0
- package/packages/core/publication/pipeline/development-current.js +63 -0
- package/packages/core/publication/pipeline/development-pr.js +112 -0
- package/packages/core/publication/pipeline/development-proof.js +76 -0
- package/packages/core/publication/pipeline/development-transition.js +112 -0
- package/packages/core/publication/pipeline/distribution.js +124 -0
- package/packages/core/publication/pipeline/documents.js +192 -0
- package/packages/core/publication/pipeline/effects.js +162 -0
- package/packages/core/publication/pipeline/files.js +66 -0
- package/packages/core/publication/pipeline/imported-materials.js +32 -0
- package/packages/core/publication/pipeline/journal.js +110 -0
- package/packages/core/publication/pipeline/next-development.js +117 -0
- package/packages/core/publication/pipeline/pack.js +157 -0
- package/packages/core/publication/pipeline/package-policy.js +22 -0
- package/packages/core/publication/pipeline/plan.js +136 -0
- package/packages/core/publication/pipeline/prepare.js +139 -0
- package/packages/core/publication/pipeline/qualification.js +175 -0
- package/packages/core/publication/pipeline/qualify.js +104 -0
- package/packages/core/publication/pipeline/recovery-admission.js +122 -0
- package/packages/core/publication/pipeline/recovery-build-download.js +80 -0
- package/packages/core/publication/pipeline/recovery-build-plan.js +122 -0
- package/packages/core/publication/pipeline/recovery-build-readback.js +68 -0
- package/packages/core/publication/pipeline/recovery-capsules.js +54 -0
- package/packages/core/publication/pipeline/recovery-import.js +80 -0
- package/packages/core/publication/pipeline/recovery-inspection.js +218 -0
- package/packages/core/publication/pipeline/recovery-materials.js +104 -0
- package/packages/core/publication/pipeline/recovery-plan.js +46 -0
- package/packages/core/publication/pipeline/recovery-prepare.js +73 -0
- package/packages/core/publication/pipeline/recovery-qualification.js +128 -0
- package/packages/core/publication/pipeline/recovery-readback.js +56 -0
- package/packages/core/publication/pipeline/recovery-signing.js +58 -0
- package/packages/core/publication/pipeline/sealed-products.js +79 -0
- package/packages/core/publication/pipeline/settle.js +43 -0
- package/packages/core/publication/pipeline/signing.js +140 -0
- package/packages/core/publication/pipeline/source-plan.js +83 -0
- package/packages/core/publication/pipeline/stable-entry.js +215 -0
- package/packages/core/publication/pipeline/stable-products.js +317 -0
- package/packages/core/publication/pipeline/stable-wait.js +170 -0
- package/packages/core/publication/pipeline/stable.js +82 -0
- package/packages/core/publication/pipeline/version-actions.js +93 -0
- package/packages/core/publication/pipeline/version-build.js +130 -0
- package/packages/core/publication/pipeline/version-context.js +143 -0
- package/packages/core/publication/pipeline/version-material.js +36 -0
- package/packages/core/publication/pipeline/version-preparation.js +69 -0
- package/packages/core/publication/pipeline/version-regeneration.js +162 -0
- package/packages/core/publication/pipeline/version-source-guard.js +69 -0
- package/packages/core/publication/pipeline/version.js +81 -0
- package/packages/core/publication/pipeline/worker.js +72 -0
- package/packages/core/publication/publication-reproducibility.js +2 -2
- package/packages/core/release/promote-candidate/product-provider-adapters.js +4 -3
- package/packages/core/release/promote-ref/internal/npm-existing-evidence.js +2 -1
- package/packages/core/release/promote-ref/internal/publish-command.js +16 -5
- package/packages/core/release/stable-release-gate.js +11 -0
- package/packages/core/runtime/buildchain-domain.wasm +0 -0
- package/packages/core/runtime/domain-wasm-artifact.js +2 -2
- package/packages/core/runtime/entry/actions.js +27 -25
- package/packages/core/runtime/entry/attempt.js +25 -0
- package/packages/core/runtime/entry/selection.js +14 -0
- package/packages/core/runtime/entry/source.js +62 -0
- package/packages/core/workflow/attempt/identity.js +170 -0
- package/packages/core/workflow/attempt/journal.js +87 -0
- package/packages/core/workflow/attempt/materials.js +72 -0
- package/packages/core/workflow/attempt/reader-entry.js +12 -0
- package/packages/core/workflow/attempt/reader.js +149 -0
- package/packages/core/workflow/attempt/records.js +153 -0
- package/packages/core/workflow/attempt/store.js +75 -0
- package/packages/core/workflow/commands/pipeline-build.mjs +23 -0
- package/packages/core/workflow/pipeline/action-output.js +11 -0
- package/packages/core/workflow/pipeline/actions.js +75 -0
- package/packages/core/workflow/pipeline/build-control.js +140 -0
- package/packages/core/workflow/pipeline/build-evidence.js +92 -0
- package/packages/core/workflow/pipeline/build-qualification.js +145 -0
- package/packages/core/workflow/pipeline/build-result.js +69 -0
- package/packages/core/workflow/pipeline/build.js +142 -0
- package/packages/core/workflow/pipeline/cancellation.js +169 -0
- package/packages/core/workflow/pipeline/channel-control.js +127 -0
- package/packages/core/workflow/pipeline/controller.js +133 -0
- package/packages/core/workflow/pipeline/delivery-control.js +204 -0
- package/packages/core/workflow/pipeline/delivery-observation.js +118 -0
- package/packages/core/workflow/pipeline/delivery-request.js +198 -0
- package/packages/core/workflow/pipeline/events.js +84 -0
- package/packages/core/workflow/pipeline/fence.js +42 -0
- package/packages/core/workflow/pipeline/group-control.js +56 -0
- package/packages/core/workflow/pipeline/guard-build.js +37 -0
- package/packages/core/workflow/pipeline/guard.js +156 -0
- package/packages/core/workflow/pipeline/host.js +114 -0
- package/packages/core/workflow/pipeline/materials.js +58 -0
- package/packages/core/workflow/pipeline/notifications.js +36 -0
- package/packages/core/workflow/pipeline/parent-notification.js +27 -0
- package/packages/core/workflow/pipeline/platforms.js +21 -0
- package/packages/core/workflow/pipeline/progress.js +108 -0
- package/packages/core/workflow/pipeline/projection.js +20 -0
- package/packages/core/workflow/pipeline/reconcile.js +194 -0
- package/packages/core/workflow/pipeline/recovery-action.js +30 -0
- package/packages/core/workflow/pipeline/recovery-admission.js +122 -0
- package/packages/core/workflow/pipeline/recovery-build-control.js +95 -0
- package/packages/core/workflow/pipeline/recovery-build-evidence.js +71 -0
- package/packages/core/workflow/pipeline/recovery-build.js +121 -0
- package/packages/core/workflow/pipeline/recovery-controller.js +91 -0
- package/packages/core/workflow/pipeline/recovery-integration.js +66 -0
- package/packages/core/workflow/pipeline/recovery-merge-proof.js +90 -0
- package/packages/core/workflow/pipeline/recovery-ownership-settlement.js +150 -0
- package/packages/core/workflow/pipeline/recovery-ownership.js +91 -0
- package/packages/core/workflow/pipeline/recovery-plan.js +126 -0
- package/packages/core/workflow/pipeline/recovery-runtime.js +68 -0
- package/packages/core/workflow/pipeline/recovery-session.js +129 -0
- package/packages/core/workflow/pipeline/recovery-transition.js +135 -0
- package/packages/core/workflow/pipeline/recovery-unrecorded-build.js +74 -0
- package/packages/core/workflow/pipeline/runtime-source.js +111 -0
- package/packages/core/workflow/pipeline/selection.js +106 -0
- package/packages/core/workflow/pipeline/session.js +72 -0
- package/packages/core/workflow/pipeline/settlement.js +137 -0
- package/packages/core/workflow/pipeline/wake.js +38 -0
- package/packages/core/workflow/pipeline/web-status.js +108 -0
- package/scripts/build-release-discussion-reader.mjs +11 -7
- package/scripts/check-pipeline-publication-topology.mjs +48 -0
- package/scripts/check-release-topology.mjs +7 -1
- package/scripts/generate-minimal-consumer-contract.mjs +155 -0
- package/scripts/generate-site-bundle.mjs +1 -1
- package/scripts/verify-golden-path.mjs +5 -1
- package/scripts/verify-standalone-product.mjs +42 -0
- package/templates/minimal-consumer/binary/.buildchain/buildchain.toml +45 -0
- package/templates/minimal-consumer/binary/.github/workflows/buildchain-recover.yml +30 -0
- package/templates/minimal-consumer/binary/.github/workflows/buildchain.yml +28 -0
- package/templates/minimal-consumer/binary/package.json +6 -0
- package/templates/minimal-consumer/binary/src/build.mjs +5 -0
- package/templates/minimal-consumer/binary/src/hello.c +2 -0
- package/templates/minimal-consumer/binary/src/verify.mjs +3 -0
- package/templates/minimal-consumer/npm/.buildchain/buildchain.toml +46 -0
- package/templates/minimal-consumer/npm/.github/workflows/buildchain-recover.yml +30 -0
- package/templates/minimal-consumer/npm/.github/workflows/buildchain.yml +28 -0
- package/templates/minimal-consumer/npm/package.json +6 -0
- package/templates/minimal-consumer/npm/src/build.mjs +5 -0
- package/templates/minimal-consumer/npm/src/verify.mjs +3 -0
- package/templates/minimal-consumer/paper/.buildchain/buildchain.toml +45 -0
- package/templates/minimal-consumer/paper/.github/workflows/buildchain-recover.yml +30 -0
- package/templates/minimal-consumer/paper/.github/workflows/buildchain.yml +28 -0
- package/templates/minimal-consumer/paper/package.json +6 -0
- package/templates/minimal-consumer/paper/src/build.mjs +12 -0
- package/templates/minimal-consumer/paper/src/verify.mjs +3 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { githubAuthEnv } from "../source-checkout/auth.js";
|
|
6
|
+
import { createNativeChildEnvironment } from "../../dev-delivery/native/execution.js";
|
|
7
|
+
|
|
8
|
+
// Read-only Git object access for credentialed source qualification. This is a
|
|
9
|
+
// bare repository: no consumer checkout, hooks or build scripts are executed.
|
|
10
|
+
export async function withPipelineSourceObjects(
|
|
11
|
+
{ repository, sourceHead, baseCommit, token },
|
|
12
|
+
operation,
|
|
13
|
+
) {
|
|
14
|
+
if (
|
|
15
|
+
!/^[\w.-]+\/[\w.-]+$/u.test(repository || "") ||
|
|
16
|
+
![sourceHead, baseCommit].every((sha) => /^[0-9a-f]{40}$/u.test(sha || ""))
|
|
17
|
+
)
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Pipeline qualification requires exact repository source coordinates",
|
|
20
|
+
);
|
|
21
|
+
const directory = fs.mkdtempSync(
|
|
22
|
+
path.join(os.tmpdir(), "buildchain-pipeline-source-"),
|
|
23
|
+
);
|
|
24
|
+
const environment = {
|
|
25
|
+
...createNativeChildEnvironment(process.env),
|
|
26
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
27
|
+
...githubAuthEnv(token),
|
|
28
|
+
};
|
|
29
|
+
const git = (args) =>
|
|
30
|
+
execFileSync("git", ["-C", directory, ...args], {
|
|
31
|
+
env: environment,
|
|
32
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
33
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
git(["init", "--bare", "--quiet"]);
|
|
37
|
+
git([
|
|
38
|
+
"fetch",
|
|
39
|
+
"--quiet",
|
|
40
|
+
"--no-tags",
|
|
41
|
+
`https://github.com/${repository}.git`,
|
|
42
|
+
sourceHead,
|
|
43
|
+
baseCommit,
|
|
44
|
+
]);
|
|
45
|
+
return await operation(directory);
|
|
46
|
+
} finally {
|
|
47
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { runtimeSelector } from "../../runtime/entry/selection.js";
|
|
3
|
+
import { pipelineRunEntry, readPipelineCaller } from "./pipeline-run-entry.js";
|
|
4
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
5
|
+
|
|
6
|
+
export async function pipelineEntryRuns(host, publishedAt) {
|
|
7
|
+
const created = encodeURIComponent(
|
|
8
|
+
`>=${new Date(publishedAt).toISOString()}`,
|
|
9
|
+
);
|
|
10
|
+
const prefix = `/repos/${host.repository}/actions/workflows/buildchain.yml/runs`;
|
|
11
|
+
const runs = [],
|
|
12
|
+
ids = new Set();
|
|
13
|
+
for (let page = 1; page <= 10; page++) {
|
|
14
|
+
const result = await host.request(
|
|
15
|
+
`${prefix}?event=pull_request&status=completed&created=${created}&per_page=100&page=${page}`,
|
|
16
|
+
{ allow404: true },
|
|
17
|
+
);
|
|
18
|
+
if (!result && page === 1) return [];
|
|
19
|
+
if (
|
|
20
|
+
!Array.isArray(result?.workflow_runs) ||
|
|
21
|
+
result.workflow_runs.length > 100
|
|
22
|
+
)
|
|
23
|
+
throw new Error("Published entry run inventory is incomplete");
|
|
24
|
+
for (const run of result.workflow_runs) {
|
|
25
|
+
if (
|
|
26
|
+
!Number.isSafeInteger(run.id) ||
|
|
27
|
+
run.id < 1 ||
|
|
28
|
+
ids.has(run.id) ||
|
|
29
|
+
!Number.isSafeInteger(run.run_attempt) ||
|
|
30
|
+
run.run_attempt < 1 ||
|
|
31
|
+
!Number.isFinite(Date.parse(run.created_at))
|
|
32
|
+
)
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Published entry run inventory has ambiguous coordinates",
|
|
35
|
+
);
|
|
36
|
+
ids.add(run.id);
|
|
37
|
+
runs.push(run);
|
|
38
|
+
}
|
|
39
|
+
if (result.workflow_runs.length < 100)
|
|
40
|
+
return runs.sort(
|
|
41
|
+
(a, b) =>
|
|
42
|
+
Date.parse(b.created_at) - Date.parse(a.created_at) || b.id - a.id,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
throw new Error(
|
|
46
|
+
"Published entry run inventory exceeds its complete-read bound",
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function sourceLock(host, source, channel) {
|
|
51
|
+
const pathname =
|
|
52
|
+
channel === "v4-alpha"
|
|
53
|
+
? ".buildchain/alpha-contract-lock.json"
|
|
54
|
+
: ".buildchain/contract-lock.json";
|
|
55
|
+
const file = await host.request(
|
|
56
|
+
`/repos/${host.repository}/contents/${pathname}?ref=${source.commit}`,
|
|
57
|
+
{ allow404: true },
|
|
58
|
+
);
|
|
59
|
+
if (!file) return { value: undefined, evidence: null };
|
|
60
|
+
if (
|
|
61
|
+
file.type !== "file" ||
|
|
62
|
+
file.encoding !== "base64" ||
|
|
63
|
+
!Number.isSafeInteger(file.size) ||
|
|
64
|
+
file.size < 1 ||
|
|
65
|
+
file.size > 1024 * 1024 ||
|
|
66
|
+
typeof file.content !== "string" ||
|
|
67
|
+
file.content.length > 2 * 1024 * 1024
|
|
68
|
+
)
|
|
69
|
+
throw new Error("Published entry runtime lock exceeds its source boundary");
|
|
70
|
+
const bytes = Buffer.from(file.content, "base64");
|
|
71
|
+
const blob = createHash("sha1")
|
|
72
|
+
.update(`blob ${bytes.length}\0`)
|
|
73
|
+
.update(bytes)
|
|
74
|
+
.digest("hex");
|
|
75
|
+
if (bytes.length !== file.size || blob !== file.sha)
|
|
76
|
+
throw new Error("Published entry runtime lock bytes changed");
|
|
77
|
+
const value = JSON.parse(
|
|
78
|
+
new TextDecoder("utf-8", { fatal: true }).decode(bytes),
|
|
79
|
+
);
|
|
80
|
+
if (
|
|
81
|
+
value.schema === "buildchain.consumer-contract-lock/v2" &&
|
|
82
|
+
value.configDigest !== source.configDigest
|
|
83
|
+
)
|
|
84
|
+
throw new Error(
|
|
85
|
+
"Published entry runtime lock belongs to another consumer configuration",
|
|
86
|
+
);
|
|
87
|
+
return {
|
|
88
|
+
value,
|
|
89
|
+
evidence: {
|
|
90
|
+
path: pathname,
|
|
91
|
+
blob,
|
|
92
|
+
digest: `sha256:${createHash("sha256").update(bytes).digest("hex")}`,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function pipelineEntryRun(run, plan, source, host) {
|
|
98
|
+
if (
|
|
99
|
+
run.event !== "pull_request" ||
|
|
100
|
+
run.status !== "completed" ||
|
|
101
|
+
run.repository?.full_name !== host.repository ||
|
|
102
|
+
run.head_repository?.full_name !== host.repository ||
|
|
103
|
+
run.path?.split("@")[0] !== ".github/workflows/buildchain.yml" ||
|
|
104
|
+
!Number.isFinite(Date.parse(run.created_at)) ||
|
|
105
|
+
Date.parse(run.created_at) < Date.parse(source.candidate.publishedAt)
|
|
106
|
+
)
|
|
107
|
+
return null;
|
|
108
|
+
const entry = pipelineRunEntry(run);
|
|
109
|
+
if (entry.recovery || entry.definition.sha !== source.candidate.sha)
|
|
110
|
+
return null;
|
|
111
|
+
const consumer = await host.source.source(
|
|
112
|
+
run.head_sha,
|
|
113
|
+
plan.source.configPath,
|
|
114
|
+
);
|
|
115
|
+
if (recordDigest(consumer.plan) !== plan.contractRoot) return null;
|
|
116
|
+
if (
|
|
117
|
+
consumer.identity.commit !== run.head_sha ||
|
|
118
|
+
consumer.identity.configPath !== plan.source.configPath ||
|
|
119
|
+
consumer.identity.repository !== host.repository
|
|
120
|
+
)
|
|
121
|
+
throw new Error("Published entry consumer source changed during readback");
|
|
122
|
+
await readPipelineCaller(
|
|
123
|
+
run,
|
|
124
|
+
consumer.identity.configPath,
|
|
125
|
+
host.request,
|
|
126
|
+
host.repository,
|
|
127
|
+
);
|
|
128
|
+
const lock = await sourceLock(host, consumer.identity, entry.channel);
|
|
129
|
+
const selection = runtimeSelector({
|
|
130
|
+
lock: lock.value,
|
|
131
|
+
workflowSha: entry.definition.sha,
|
|
132
|
+
});
|
|
133
|
+
if (selection.ref !== source.candidate.sha) return null;
|
|
134
|
+
return {
|
|
135
|
+
source: consumer.identity,
|
|
136
|
+
entry: entry.definition,
|
|
137
|
+
selection,
|
|
138
|
+
lock: lock.evidence,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function pipelineEntryCheck(run, host) {
|
|
143
|
+
const checks = [],
|
|
144
|
+
ids = new Set();
|
|
145
|
+
const prefix = `/repos/${host.repository}/commits/${run.head_sha}/check-runs`;
|
|
146
|
+
for (let page = 1; page <= 10; page++) {
|
|
147
|
+
const result = await host.request(
|
|
148
|
+
`${prefix}?check_name=check&filter=all&per_page=100&page=${page}`,
|
|
149
|
+
);
|
|
150
|
+
if (!Array.isArray(result?.check_runs) || result.check_runs.length > 100)
|
|
151
|
+
throw new Error("Published entry check inventory is incomplete");
|
|
152
|
+
for (const check of result.check_runs) {
|
|
153
|
+
if (!Number.isSafeInteger(check.id) || check.id < 1 || ids.has(check.id))
|
|
154
|
+
throw new Error(
|
|
155
|
+
"Published entry check inventory has ambiguous identities",
|
|
156
|
+
);
|
|
157
|
+
ids.add(check.id);
|
|
158
|
+
checks.push(check);
|
|
159
|
+
}
|
|
160
|
+
if (result.check_runs.length < 100)
|
|
161
|
+
return exactCheck(checks, run, host.repository);
|
|
162
|
+
}
|
|
163
|
+
throw new Error(
|
|
164
|
+
"Published entry check inventory exceeds its complete-read bound",
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function exactCheck(checks, run, repository) {
|
|
169
|
+
const url = `https://github.com/${repository}/actions/runs/${run.id}/attempts/${run.run_attempt}`;
|
|
170
|
+
const matches = checks.filter(
|
|
171
|
+
(check) => check.name === "check" && check.details_url === url,
|
|
172
|
+
);
|
|
173
|
+
if (!matches.length) return null;
|
|
174
|
+
const values = matches.map((check) => {
|
|
175
|
+
const parsed =
|
|
176
|
+
/^buildchain:(attempt-[0-9a-f]{64}):([1-9][0-9]*):([1-9][0-9]*)$/u.exec(
|
|
177
|
+
check.external_id || "",
|
|
178
|
+
);
|
|
179
|
+
if (
|
|
180
|
+
!parsed ||
|
|
181
|
+
Number(parsed[2]) !== run.id ||
|
|
182
|
+
Number(parsed[3]) !== run.run_attempt ||
|
|
183
|
+
check.head_sha !== run.head_sha ||
|
|
184
|
+
check.status !== "completed" ||
|
|
185
|
+
!["success", "failure"].includes(check.conclusion) ||
|
|
186
|
+
check.app?.slug !== "github-actions"
|
|
187
|
+
)
|
|
188
|
+
throw new Error(
|
|
189
|
+
"Published entry check does not bind its exact native attempt",
|
|
190
|
+
);
|
|
191
|
+
return {
|
|
192
|
+
attempt: parsed[1],
|
|
193
|
+
outcome: check.conclusion,
|
|
194
|
+
summary: check.output?.summary || "",
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
if (values.some((value) => recordDigest(value) !== recordDigest(values[0])))
|
|
198
|
+
throw new Error("Published entry checks disagree about the same execution");
|
|
199
|
+
return {
|
|
200
|
+
...values[0],
|
|
201
|
+
ids: matches.map(({ id }) => id).sort((a, b) => a - b),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readBusinessAttempt } from "../../workflow/attempt/reader.js";
|
|
2
|
+
|
|
3
|
+
// Branch/terminal notifications wake existing intents only. They cannot create
|
|
4
|
+
// historical releases or infer an execution request from an untracked old PR.
|
|
5
|
+
export function githubPipelineEvents(request, journal, repository) {
|
|
6
|
+
if (!/^[\w.-]+\/[\w.-]+$/u.test(repository || ""))
|
|
7
|
+
throw new Error("Invalid pipeline event repository");
|
|
8
|
+
const base = `/repos/${repository}`;
|
|
9
|
+
async function list(url) {
|
|
10
|
+
const rows = [];
|
|
11
|
+
for (let page = 1; page <= 100; page++) {
|
|
12
|
+
const entries = await request(
|
|
13
|
+
`${url}${url.includes("?") ? "&" : "?"}per_page=100&page=${page}`,
|
|
14
|
+
);
|
|
15
|
+
if (!Array.isArray(entries))
|
|
16
|
+
throw new Error("Invalid pipeline PR event readback");
|
|
17
|
+
rows.push(...entries);
|
|
18
|
+
if (entries.length < 100) return rows;
|
|
19
|
+
}
|
|
20
|
+
throw new Error("Pipeline PR event readback exceeds its bound");
|
|
21
|
+
}
|
|
22
|
+
async function branch(branch, commit = "") {
|
|
23
|
+
if (
|
|
24
|
+
!/^(?:dev|alpha|release|publish-gate)\/[A-Za-z0-9/._-]+$/u.test(
|
|
25
|
+
branch || "",
|
|
26
|
+
) ||
|
|
27
|
+
branch.includes("..")
|
|
28
|
+
)
|
|
29
|
+
throw new Error("Invalid pipeline branch event");
|
|
30
|
+
const pulls = await list(
|
|
31
|
+
`${base}/pulls?state=open&base=${encodeURIComponent(branch)}`,
|
|
32
|
+
);
|
|
33
|
+
if (commit) {
|
|
34
|
+
if (!/^[0-9a-f]{40}$/u.test(commit))
|
|
35
|
+
throw new Error("Branch wake requires exact source commit");
|
|
36
|
+
pulls.push(...(await list(`${base}/commits/${commit}/pulls`)));
|
|
37
|
+
}
|
|
38
|
+
const result = new Set();
|
|
39
|
+
for (const number of [
|
|
40
|
+
...new Set(
|
|
41
|
+
pulls.filter((pr) => pr.base?.ref === branch).map((pr) => pr.number),
|
|
42
|
+
),
|
|
43
|
+
]) {
|
|
44
|
+
const retained = await journal.lookup(repository, number, branch);
|
|
45
|
+
if (!retained) continue;
|
|
46
|
+
const state = readBusinessAttempt(retained.snapshot);
|
|
47
|
+
if (state.attempt) result.add(state.attempt);
|
|
48
|
+
}
|
|
49
|
+
return [...result];
|
|
50
|
+
}
|
|
51
|
+
return { branch };
|
|
52
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
2
|
+
import { pipelinePlatforms } from "../../workflow/pipeline/platforms.js";
|
|
3
|
+
|
|
4
|
+
export function githubPipelineIntegration(request, repository, source, runs) {
|
|
5
|
+
const base = `/repos/${repository}`;
|
|
6
|
+
async function observe(current) {
|
|
7
|
+
const number = current.intent.source.pullRequest;
|
|
8
|
+
const branch = current.intent.source.targetBranch;
|
|
9
|
+
const pr = await request(`${base}/pulls/${number}`);
|
|
10
|
+
if (
|
|
11
|
+
!pr.merged ||
|
|
12
|
+
pr.head?.sha !== current.generation.source.commit ||
|
|
13
|
+
pr.base?.ref !== branch ||
|
|
14
|
+
pr.head?.repo?.full_name !== repository ||
|
|
15
|
+
pr.base?.repo?.full_name !== repository ||
|
|
16
|
+
!/^[0-9a-f]{40}$/u.test(pr.merge_commit_sha || "")
|
|
17
|
+
)
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Integration needs the exact source PR merged into its protected target",
|
|
20
|
+
);
|
|
21
|
+
const mergeCommit = pr.merge_commit_sha;
|
|
22
|
+
const protectedHead = await source.branchHead(branch);
|
|
23
|
+
const ancestry = await request(
|
|
24
|
+
`${base}/compare/${mergeCommit}...${protectedHead}`,
|
|
25
|
+
);
|
|
26
|
+
if (
|
|
27
|
+
!["identical", "ahead"].includes(ancestry.status) ||
|
|
28
|
+
ancestry.merge_base_commit?.sha !== mergeCommit
|
|
29
|
+
)
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Exact merge commit is not contained in the protected branch",
|
|
32
|
+
);
|
|
33
|
+
const commits = await source.source(
|
|
34
|
+
mergeCommit,
|
|
35
|
+
current.generation.source.configPath,
|
|
36
|
+
);
|
|
37
|
+
const response = await request(
|
|
38
|
+
`${base}/actions/runs?event=merge_group&head_sha=${mergeCommit}&per_page=100`,
|
|
39
|
+
);
|
|
40
|
+
if (!Array.isArray(response.workflow_runs) || response.total_count > 100)
|
|
41
|
+
throw new Error(
|
|
42
|
+
"Exact merge-group run inventory is unavailable or ambiguous",
|
|
43
|
+
);
|
|
44
|
+
const candidates = response.workflow_runs.filter(
|
|
45
|
+
(run) =>
|
|
46
|
+
run.status === "completed" &&
|
|
47
|
+
run.conclusion === "success" &&
|
|
48
|
+
run.path?.split("@")[0] === ".github/workflows/buildchain.yml",
|
|
49
|
+
);
|
|
50
|
+
if (!candidates.length)
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Exact merged commit has no successful normal pipeline merge-group run",
|
|
53
|
+
);
|
|
54
|
+
const chosen = candidates.sort((a, b) => b.id - a.id)[0];
|
|
55
|
+
const { run } = await runs.read(chosen.id, chosen.run_attempt);
|
|
56
|
+
if (
|
|
57
|
+
run.status !== "completed" ||
|
|
58
|
+
run.conclusion !== "success" ||
|
|
59
|
+
run.event !== "merge_group" ||
|
|
60
|
+
run.head_sha !== mergeCommit
|
|
61
|
+
)
|
|
62
|
+
throw new Error("Integration merge-group execution changed");
|
|
63
|
+
const build = await runs.build(
|
|
64
|
+
run.id,
|
|
65
|
+
run.run_attempt,
|
|
66
|
+
commits.identity,
|
|
67
|
+
pipelinePlatforms(commits.plan).map((item) => item.platform),
|
|
68
|
+
);
|
|
69
|
+
if (build.outcome !== "success")
|
|
70
|
+
throw new Error("Exact merged tree product verification failed");
|
|
71
|
+
const again = await request(`${base}/pulls/${number}`);
|
|
72
|
+
if (
|
|
73
|
+
!again.merged ||
|
|
74
|
+
again.merge_commit_sha !== mergeCommit ||
|
|
75
|
+
again.head.sha !== pr.head.sha ||
|
|
76
|
+
again.base.ref !== branch
|
|
77
|
+
)
|
|
78
|
+
throw new Error("Integration provider source changed during readback");
|
|
79
|
+
const body = {
|
|
80
|
+
schema: "buildchain.pipeline-integration-readback/v1",
|
|
81
|
+
repository,
|
|
82
|
+
pullRequest: number,
|
|
83
|
+
sourceHead: pr.head.sha,
|
|
84
|
+
branch,
|
|
85
|
+
protectedHead,
|
|
86
|
+
mergeCommit,
|
|
87
|
+
mergeTree: commits.identity.tree,
|
|
88
|
+
run,
|
|
89
|
+
build,
|
|
90
|
+
ancestry,
|
|
91
|
+
};
|
|
92
|
+
return { ...body, root: recordDigest(body) };
|
|
93
|
+
}
|
|
94
|
+
return { observe };
|
|
95
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { recordDigest } from "../../release/discussion/envelope.js";
|
|
2
|
+
|
|
3
|
+
const QUERY = `query PipelinePolicy($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){id number headRefOid baseRefName isDraft reviewDecision author{login}}}}`;
|
|
4
|
+
const BRANCH_QUERY = `query PipelineBranchPolicy($owner:String!,$name:String!,$branch:String!,$ref:String!){repository(owner:$owner,name:$name){ref(qualifiedName:$ref){branchProtectionRule{requiresApprovingReviews requiredApprovingReviewCount requiresCodeOwnerReviews requiresStatusChecks requiredStatusChecks{context app{databaseId}}}}mergeQueue(branch:$branch){id}}}`;
|
|
5
|
+
|
|
6
|
+
async function classicPolicy(request, owner, name, branch) {
|
|
7
|
+
// REST /branches/:branch/protection requires Administration:read. Ordinary
|
|
8
|
+
// workflow credentials instead read effective rules and GraphQL metadata.
|
|
9
|
+
const result = await request("/graphql", {
|
|
10
|
+
method: "POST",
|
|
11
|
+
body: {
|
|
12
|
+
query: BRANCH_QUERY,
|
|
13
|
+
variables: { owner, name, branch, ref: `refs/heads/${branch}` },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const repository = result.data?.repository;
|
|
17
|
+
if (!repository) throw new Error("Protected branch metadata is unavailable");
|
|
18
|
+
const rule = repository.ref?.branchProtectionRule;
|
|
19
|
+
return {
|
|
20
|
+
required_merge_queue: Boolean(repository.mergeQueue?.id),
|
|
21
|
+
required_pull_request_reviews: rule?.requiresApprovingReviews
|
|
22
|
+
? {
|
|
23
|
+
require_code_owner_reviews: rule.requiresCodeOwnerReviews,
|
|
24
|
+
required_approving_review_count: rule.requiredApprovingReviewCount,
|
|
25
|
+
}
|
|
26
|
+
: null,
|
|
27
|
+
required_status_checks: {
|
|
28
|
+
checks: rule?.requiresStatusChecks
|
|
29
|
+
? (rule.requiredStatusChecks || []).map((check) => ({
|
|
30
|
+
context: check.context,
|
|
31
|
+
app_id: check.app?.databaseId || null,
|
|
32
|
+
}))
|
|
33
|
+
: [],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function inventory(request, url, key = "") {
|
|
39
|
+
const rows = [];
|
|
40
|
+
for (let page = 1; page <= 100; page++) {
|
|
41
|
+
const response = await request(
|
|
42
|
+
`${url}${url.includes("?") ? "&" : "?"}per_page=100&page=${page}`,
|
|
43
|
+
);
|
|
44
|
+
const entries = key ? response[key] : response;
|
|
45
|
+
if (!Array.isArray(entries))
|
|
46
|
+
throw new Error("Missing protected policy inventory");
|
|
47
|
+
rows.push(...entries);
|
|
48
|
+
if (entries.length < 100) return rows;
|
|
49
|
+
}
|
|
50
|
+
throw new Error("Protected policy inventory exceeds its bound");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function protections(rules, classic, policy) {
|
|
54
|
+
const reviews = rules
|
|
55
|
+
.filter((rule) => rule.type === "pull_request")
|
|
56
|
+
.map((rule) => rule.parameters);
|
|
57
|
+
if (classic?.required_pull_request_reviews)
|
|
58
|
+
reviews.push({
|
|
59
|
+
...classic.required_pull_request_reviews,
|
|
60
|
+
require_code_owner_review:
|
|
61
|
+
classic.required_pull_request_reviews.require_code_owner_reviews,
|
|
62
|
+
});
|
|
63
|
+
if (
|
|
64
|
+
!reviews.some((rule) => rule?.require_code_owner_review === true) ||
|
|
65
|
+
!reviews.some(
|
|
66
|
+
(rule) =>
|
|
67
|
+
rule?.required_approving_review_count >= policy.minimum_approvals,
|
|
68
|
+
) ||
|
|
69
|
+
!(
|
|
70
|
+
classic?.required_merge_queue ||
|
|
71
|
+
rules.some((rule) => rule.type === "merge_queue")
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
throw new Error(
|
|
75
|
+
"Protected branch must enforce declared approvals, code owners and merge queue",
|
|
76
|
+
);
|
|
77
|
+
const contexts = rules
|
|
78
|
+
.filter((rule) => rule.type === "required_status_checks")
|
|
79
|
+
.flatMap((rule) => rule.parameters?.required_status_checks || []);
|
|
80
|
+
for (const check of classic?.required_status_checks?.checks || [])
|
|
81
|
+
contexts.push({ context: check.context, integration_id: check.app_id });
|
|
82
|
+
if (!contexts.length || contexts.some((check) => !check.context))
|
|
83
|
+
throw new Error(
|
|
84
|
+
"Protected pipeline requires provider-enforced status checks",
|
|
85
|
+
);
|
|
86
|
+
return contexts;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function approved(pr, reviews, minimum) {
|
|
90
|
+
const latest = new Map();
|
|
91
|
+
for (const review of [...reviews].sort((a, b) => a.id - b.id)) {
|
|
92
|
+
if (
|
|
93
|
+
review.user?.login &&
|
|
94
|
+
["APPROVED", "CHANGES_REQUESTED", "DISMISSED"].includes(review.state)
|
|
95
|
+
)
|
|
96
|
+
latest.set(review.user.login, review);
|
|
97
|
+
}
|
|
98
|
+
const independent = [...latest.values()].filter(
|
|
99
|
+
(review) => review.user.login !== pr.author?.login,
|
|
100
|
+
);
|
|
101
|
+
return (
|
|
102
|
+
pr.reviewDecision === "APPROVED" &&
|
|
103
|
+
!independent.some((review) => review.state === "CHANGES_REQUESTED") &&
|
|
104
|
+
independent.filter(
|
|
105
|
+
(review) =>
|
|
106
|
+
review.state === "APPROVED" && review.commit_id === pr.headRefOid,
|
|
107
|
+
).length >= minimum
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function checksPass(contexts, checks, statuses) {
|
|
112
|
+
return contexts.every(({ context, integration_id: app }) => {
|
|
113
|
+
const candidates = checks.filter(
|
|
114
|
+
(check) =>
|
|
115
|
+
check.name === context && (!app || app === -1 || check.app?.id === app),
|
|
116
|
+
);
|
|
117
|
+
const latest = candidates.sort((a, b) => b.id - a.id)[0];
|
|
118
|
+
if (latest)
|
|
119
|
+
return (
|
|
120
|
+
latest.status === "completed" &&
|
|
121
|
+
["success", "neutral", "skipped"].includes(latest.conclusion)
|
|
122
|
+
);
|
|
123
|
+
if (app && app !== -1) return false;
|
|
124
|
+
return (
|
|
125
|
+
statuses
|
|
126
|
+
.filter((status) => status.context === context)
|
|
127
|
+
.sort((a, b) => b.id - a.id)[0]?.state === "success"
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function githubPipelinePolicy(request, repository) {
|
|
133
|
+
const [owner, name] = repository.split("/");
|
|
134
|
+
const base = `/repos/${repository}`;
|
|
135
|
+
async function pull(number) {
|
|
136
|
+
const response = await request("/graphql", {
|
|
137
|
+
method: "POST",
|
|
138
|
+
body: { query: QUERY, variables: { owner, name, number } },
|
|
139
|
+
});
|
|
140
|
+
const pr = response.data?.repository?.pullRequest;
|
|
141
|
+
if (!pr?.id || pr.number !== number)
|
|
142
|
+
throw new Error("Protected PR policy identity is unavailable");
|
|
143
|
+
return pr;
|
|
144
|
+
}
|
|
145
|
+
async function observe(current, policy, integratedHead) {
|
|
146
|
+
const { source, baseCommit } = current.generation;
|
|
147
|
+
const number = current.intent.source.pullRequest,
|
|
148
|
+
branch = current.intent.source.targetBranch;
|
|
149
|
+
const pr = await pull(number);
|
|
150
|
+
if (pr.headRefOid !== source.commit || pr.baseRefName !== branch)
|
|
151
|
+
throw new Error("Protected PR policy source drift");
|
|
152
|
+
const branchPath = encodeURIComponent(branch);
|
|
153
|
+
const rules = await inventory(
|
|
154
|
+
request,
|
|
155
|
+
`${base}/rules/branches/${branchPath}`,
|
|
156
|
+
);
|
|
157
|
+
const classic = await classicPolicy(request, owner, name, branch);
|
|
158
|
+
const contexts = protections(rules, classic, policy);
|
|
159
|
+
const reviews = await inventory(request, `${base}/pulls/${number}/reviews`);
|
|
160
|
+
const checks = await inventory(
|
|
161
|
+
request,
|
|
162
|
+
`${base}/commits/${source.commit}/check-runs?filter=latest`,
|
|
163
|
+
"check_runs",
|
|
164
|
+
);
|
|
165
|
+
const statuses = await inventory(
|
|
166
|
+
request,
|
|
167
|
+
`${base}/commits/${source.commit}/statuses`,
|
|
168
|
+
);
|
|
169
|
+
const again = await pull(number);
|
|
170
|
+
const ref = await request(`${base}/git/ref/heads/${branch}`);
|
|
171
|
+
if (
|
|
172
|
+
recordDigest(pr) !== recordDigest(again) ||
|
|
173
|
+
ref.object?.sha !== (integratedHead || baseCommit)
|
|
174
|
+
)
|
|
175
|
+
throw new Error("Protected policy changed during readback");
|
|
176
|
+
const body = {
|
|
177
|
+
schema: "buildchain.pipeline-policy-readback/v1",
|
|
178
|
+
source,
|
|
179
|
+
baseCommit,
|
|
180
|
+
pr,
|
|
181
|
+
rules,
|
|
182
|
+
classic: classic || null,
|
|
183
|
+
reviews,
|
|
184
|
+
checks,
|
|
185
|
+
statuses,
|
|
186
|
+
contexts,
|
|
187
|
+
review: !pr.isDraft && approved(pr, reviews, policy.minimum_approvals),
|
|
188
|
+
checksPassing: checksPass(contexts, checks, statuses),
|
|
189
|
+
...(integratedHead ? { integratedHead } : {}),
|
|
190
|
+
};
|
|
191
|
+
return { ...body, root: recordDigest(body) };
|
|
192
|
+
}
|
|
193
|
+
async function observeMerged(current, policy, integration) {
|
|
194
|
+
const { root, ...body } = integration;
|
|
195
|
+
if (
|
|
196
|
+
root !== recordDigest(body) ||
|
|
197
|
+
body.schema !== "buildchain.pipeline-integration-readback/v1" ||
|
|
198
|
+
body.repository !== repository ||
|
|
199
|
+
body.sourceHead !== current.generation.source.commit ||
|
|
200
|
+
body.branch !== current.intent.source.targetBranch ||
|
|
201
|
+
body.pullRequest !== current.intent.source.pullRequest ||
|
|
202
|
+
!/^[0-9a-f]{40}$/u.test(body.protectedHead || "")
|
|
203
|
+
)
|
|
204
|
+
throw new Error(
|
|
205
|
+
"Merged review qualification requires exact protected integration evidence",
|
|
206
|
+
);
|
|
207
|
+
return observe(current, policy, body.protectedHead);
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
observe: (current, policy) => observe(current, policy),
|
|
211
|
+
observeMerged,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { canonicalJson } from "../../release/discussion/envelope.js";
|
|
3
|
+
import {
|
|
4
|
+
publicationFile,
|
|
5
|
+
publicationPath,
|
|
6
|
+
} from "../../publication/pipeline/files.js";
|
|
7
|
+
const sha256 = (bytes) =>
|
|
8
|
+
`sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
9
|
+
|
|
10
|
+
export function pipelineProductPayload({
|
|
11
|
+
qualified,
|
|
12
|
+
documents,
|
|
13
|
+
directory,
|
|
14
|
+
evidence,
|
|
15
|
+
}) {
|
|
16
|
+
const payload = (effect) => {
|
|
17
|
+
if (effect.product.startsWith("evidence:")) {
|
|
18
|
+
const asset = evidence.find(
|
|
19
|
+
(entry) => `evidence:${entry.id}` === effect.product,
|
|
20
|
+
);
|
|
21
|
+
if (
|
|
22
|
+
!asset ||
|
|
23
|
+
sha256(asset.bytes) !== effect.digest ||
|
|
24
|
+
asset.bytes.length !== effect.size
|
|
25
|
+
)
|
|
26
|
+
throw new Error(
|
|
27
|
+
"Release evidence differs from admitted immutable bytes",
|
|
28
|
+
);
|
|
29
|
+
return asset.bytes;
|
|
30
|
+
}
|
|
31
|
+
if (effect.product === "release-passport")
|
|
32
|
+
return Buffer.from(`${canonicalJson(documents.passport)}\n`);
|
|
33
|
+
const artifact = qualified.artifacts.find(
|
|
34
|
+
(entry) => entry.id === effect.product,
|
|
35
|
+
);
|
|
36
|
+
if (
|
|
37
|
+
!artifact ||
|
|
38
|
+
artifact.digest !== effect.digest ||
|
|
39
|
+
artifact.size !== effect.size
|
|
40
|
+
)
|
|
41
|
+
throw new Error(
|
|
42
|
+
"GitHub Release payload does not match qualified product",
|
|
43
|
+
);
|
|
44
|
+
const file = publicationFile(publicationPath(directory, artifact.file));
|
|
45
|
+
if (file.digest !== artifact.digest || file.size !== artifact.size)
|
|
46
|
+
throw new Error("GitHub Release payload bytes changed");
|
|
47
|
+
return file.bytes;
|
|
48
|
+
};
|
|
49
|
+
return payload;
|
|
50
|
+
}
|