@kungfu-tech/buildchain 3.0.4 → 3.0.5-alpha.0
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/site/buildchain-contract.json +23 -18
- package/dist/site/buildchain-site.json +13 -13
- package/dist/site/controller-registry.json +6 -2
- package/dist/site/kfd-claims.json +6 -4
- package/dist/site/kfd-upstream-aggregate.json +1 -1
- package/dist/site/manual-registry.json +3 -3
- package/dist/site/node-api-registry.json +96 -5
- package/dist/site/page-registry.json +6 -6
- package/dist/site/public-surface-audit.json +12 -8
- package/dist/site/publication-registry.json +4 -4
- package/dist/site/site-manifest.json +7 -7
- package/dist/site/workflow-registry.json +10 -6
- package/docs/auditable-demo.md +7 -0
- package/docs/node-api-reference.md +12 -3
- package/docs/release-propagation.md +34 -0
- package/package.json +1 -1
- package/packages/core/release-propagation-capture.js +150 -0
- package/packages/core/release-propagation-stage-evidence.js +1 -1
- package/packages/core/release-propagation.js +5 -0
- package/scripts/auditable-demo-renditions.mjs +2 -3
- package/scripts/capture-package-release-propagation.mjs +240 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import {
|
|
10
|
+
createPackageReleasePropagationCapture,
|
|
11
|
+
normalizePackageReleasePropagationConfig,
|
|
12
|
+
} from "../packages/core/release-propagation-capture.js";
|
|
13
|
+
import { stableJson } from "../packages/core/release-propagation-common.js";
|
|
14
|
+
|
|
15
|
+
function parseArgs(argv) {
|
|
16
|
+
const args = {};
|
|
17
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
18
|
+
const token = argv[index];
|
|
19
|
+
if (!token.startsWith("--")) throw new Error(`unexpected argument: ${token}`);
|
|
20
|
+
const key = token.slice(2);
|
|
21
|
+
const value = argv[index + 1];
|
|
22
|
+
if (!value || value.startsWith("--")) throw new Error(`${token} requires a value`);
|
|
23
|
+
args[key] = value;
|
|
24
|
+
index += 1;
|
|
25
|
+
}
|
|
26
|
+
return args;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function required(args, key) {
|
|
30
|
+
const value = String(args[key] || "").trim();
|
|
31
|
+
if (!value) throw new Error(`--${key} is required`);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function sha256(bytes) {
|
|
36
|
+
return crypto.createHash("sha256").update(bytes).digest("hex");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function commandJson(command, args, options = {}) {
|
|
40
|
+
const text = execFileSync(command, args, { encoding: "utf8", ...options });
|
|
41
|
+
return JSON.parse(text);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function assertSourcePath(value) {
|
|
45
|
+
const sourcePath = String(value || "").trim();
|
|
46
|
+
if (!sourcePath || path.isAbsolute(sourcePath) || sourcePath.split("/").includes("..") || /[\r\n]/.test(sourcePath)) {
|
|
47
|
+
throw new Error("release propagation config path must be a safe repository-relative path");
|
|
48
|
+
}
|
|
49
|
+
return sourcePath;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function readConfigAtSource(sourceSha, configPath, cwd) {
|
|
53
|
+
const bytes = execFileSync("git", ["show", `${sourceSha}:${configPath}`], {
|
|
54
|
+
cwd,
|
|
55
|
+
encoding: "utf8",
|
|
56
|
+
});
|
|
57
|
+
const parsed = JSON.parse(bytes);
|
|
58
|
+
return { bytes, parsed, normalized: normalizePackageReleasePropagationConfig(parsed) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function resolveTagTarget(repository, tag) {
|
|
62
|
+
let object = commandJson("gh", ["api", `repos/${repository}/git/ref/tags/${tag}`]).object;
|
|
63
|
+
for (let depth = 0; depth < 8 && object?.type === "tag"; depth += 1) {
|
|
64
|
+
object = commandJson("gh", ["api", `repos/${repository}/git/tags/${object.sha}`]).object;
|
|
65
|
+
}
|
|
66
|
+
if (object?.type !== "commit" || !/^[0-9a-f]{40}$/i.test(object.sha || "")) {
|
|
67
|
+
throw new Error(`release tag ${tag} does not resolve to one exact commit`);
|
|
68
|
+
}
|
|
69
|
+
return object.sha.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function resolvePackageFact(packageName, version) {
|
|
73
|
+
const fact = commandJson("npm", [
|
|
74
|
+
"view",
|
|
75
|
+
`${packageName}@${version}`,
|
|
76
|
+
"version",
|
|
77
|
+
"dist.integrity",
|
|
78
|
+
"gitHead",
|
|
79
|
+
"--json",
|
|
80
|
+
"--registry=https://registry.npmjs.org/",
|
|
81
|
+
]);
|
|
82
|
+
return {
|
|
83
|
+
name: packageName,
|
|
84
|
+
version: String(fact.version || ""),
|
|
85
|
+
integrity: String(fact.dist?.integrity || fact["dist.integrity"] || ""),
|
|
86
|
+
gitHead: String(fact.gitHead || "").toLowerCase(),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function verifyPublicReleasePassport({ repository, tag, localPath }) {
|
|
91
|
+
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "buildchain-release-passport-"));
|
|
92
|
+
try {
|
|
93
|
+
execFileSync("gh", [
|
|
94
|
+
"release", "download", tag,
|
|
95
|
+
"--repo", repository,
|
|
96
|
+
"--pattern", "buildchain.release.json",
|
|
97
|
+
"--dir", temporary,
|
|
98
|
+
], { stdio: ["ignore", "pipe", "pipe"] });
|
|
99
|
+
const localBytes = fs.readFileSync(localPath);
|
|
100
|
+
const remotePath = path.join(temporary, "buildchain.release.json");
|
|
101
|
+
const remoteBytes = fs.readFileSync(remotePath);
|
|
102
|
+
const localDigest = sha256(localBytes);
|
|
103
|
+
const remoteDigest = sha256(remoteBytes);
|
|
104
|
+
if (localDigest !== remoteDigest) {
|
|
105
|
+
throw new Error("public release passport bytes disagree with finalized local passport");
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
url: `https://github.com/${repository}/releases/download/${tag}/buildchain.release.json`,
|
|
109
|
+
sha256: remoteDigest,
|
|
110
|
+
};
|
|
111
|
+
} finally {
|
|
112
|
+
fs.rmSync(temporary, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function resolveBaseShas(config) {
|
|
117
|
+
return Object.fromEntries(config.targets.map((targetId) => {
|
|
118
|
+
const node = config.graph.nodes.find((entry) => entry.id === targetId);
|
|
119
|
+
if (!node?.baseRef) throw new Error(`configured propagation target ${targetId} has no baseRef`);
|
|
120
|
+
const response = commandJson("gh", ["api", `repos/${node.repository}/commits/${node.baseRef}`]);
|
|
121
|
+
const sha = String(response.sha || "").toLowerCase();
|
|
122
|
+
if (!/^[0-9a-f]{40}$/.test(sha)) {
|
|
123
|
+
throw new Error(`configured propagation target ${targetId} baseRef did not resolve exactly`);
|
|
124
|
+
}
|
|
125
|
+
return [targetId, sha];
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function writeOutput(name, value) {
|
|
130
|
+
if (!process.env.GITHUB_OUTPUT) return;
|
|
131
|
+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `${name}=${value}\n`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function capturePackageReleasePropagation({
|
|
135
|
+
config,
|
|
136
|
+
upstreamRelease,
|
|
137
|
+
expectedBaseShas,
|
|
138
|
+
outputDir,
|
|
139
|
+
configBytes = "",
|
|
140
|
+
} = {}) {
|
|
141
|
+
const captured = createPackageReleasePropagationCapture({
|
|
142
|
+
config,
|
|
143
|
+
upstreamRelease,
|
|
144
|
+
expectedBaseShas,
|
|
145
|
+
});
|
|
146
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
147
|
+
fs.writeFileSync(
|
|
148
|
+
path.join(outputDir, "config.json"),
|
|
149
|
+
configBytes || stableJson(captured.config),
|
|
150
|
+
);
|
|
151
|
+
fs.writeFileSync(path.join(outputDir, "upstream-release.json"), stableJson(captured.upstreamRelease));
|
|
152
|
+
fs.writeFileSync(path.join(outputDir, "plan.json"), stableJson(captured.plan));
|
|
153
|
+
for (const item of captured.works) {
|
|
154
|
+
const targetDir = path.join(outputDir, "work", item.propagationKey);
|
|
155
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
156
|
+
fs.writeFileSync(path.join(targetDir, "work.json"), stableJson(item.work));
|
|
157
|
+
fs.writeFileSync(path.join(targetDir, "status.json"), stableJson(item.status));
|
|
158
|
+
}
|
|
159
|
+
return captured;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function main(argv = process.argv.slice(2)) {
|
|
163
|
+
const args = parseArgs(argv);
|
|
164
|
+
const repository = required(args, "repository");
|
|
165
|
+
const channel = required(args, "channel");
|
|
166
|
+
const sourceSha = required(args, "source-sha").toLowerCase();
|
|
167
|
+
const tag = required(args, "tag");
|
|
168
|
+
const configPath = assertSourcePath(required(args, "config-path"));
|
|
169
|
+
const releasePassportPath = path.resolve(required(args, "release-passport-path"));
|
|
170
|
+
const outputDir = path.resolve(required(args, "output-dir"));
|
|
171
|
+
if (!/^[0-9a-f]{40}$/.test(sourceSha)) throw new Error("--source-sha must be an exact commit SHA");
|
|
172
|
+
if (tag !== `v${tag.replace(/^v/, "")}`) throw new Error("--tag must be an exact v-prefixed release tag");
|
|
173
|
+
const version = tag.slice(1);
|
|
174
|
+
const configSource = readConfigAtSource(sourceSha, configPath, process.cwd());
|
|
175
|
+
const sourceNode = configSource.normalized.graph.nodes.find(
|
|
176
|
+
(node) => node.id === configSource.normalized.sourceNode,
|
|
177
|
+
);
|
|
178
|
+
const packageFact = resolvePackageFact(sourceNode.package, version);
|
|
179
|
+
const tagTargetSha = resolveTagTarget(repository, tag);
|
|
180
|
+
const releasePassport = verifyPublicReleasePassport({
|
|
181
|
+
repository,
|
|
182
|
+
tag,
|
|
183
|
+
localPath: releasePassportPath,
|
|
184
|
+
});
|
|
185
|
+
const upstreamRelease = {
|
|
186
|
+
repository,
|
|
187
|
+
channel,
|
|
188
|
+
tag,
|
|
189
|
+
sourceSha,
|
|
190
|
+
tagTargetSha,
|
|
191
|
+
package: packageFact,
|
|
192
|
+
releasePassport,
|
|
193
|
+
};
|
|
194
|
+
const expectedBaseShas = resolveBaseShas(configSource.normalized);
|
|
195
|
+
const captured = capturePackageReleasePropagation({
|
|
196
|
+
config: configSource.parsed,
|
|
197
|
+
configBytes: configSource.bytes,
|
|
198
|
+
upstreamRelease,
|
|
199
|
+
expectedBaseShas,
|
|
200
|
+
outputDir,
|
|
201
|
+
});
|
|
202
|
+
const artifactName = `package-propagation-work-${version}-${sourceSha}`;
|
|
203
|
+
const workRoots = captured.works.map((item) => item.work.contentRoot);
|
|
204
|
+
writeOutput("configured", "true");
|
|
205
|
+
writeOutput("artifact-name", artifactName);
|
|
206
|
+
writeOutput("work-roots-json", JSON.stringify(workRoots));
|
|
207
|
+
process.stdout.write(stableJson({
|
|
208
|
+
schemaVersion: 1,
|
|
209
|
+
contract: "kungfu-buildchain-package-release-propagation-capture-result",
|
|
210
|
+
artifactName,
|
|
211
|
+
release: {
|
|
212
|
+
repository,
|
|
213
|
+
channel,
|
|
214
|
+
tag,
|
|
215
|
+
sourceSha,
|
|
216
|
+
tagTargetSha,
|
|
217
|
+
package: packageFact,
|
|
218
|
+
releasePassport,
|
|
219
|
+
},
|
|
220
|
+
workCount: captured.works.length,
|
|
221
|
+
works: captured.works.map((item) => ({
|
|
222
|
+
target: item.target,
|
|
223
|
+
repository: item.repository,
|
|
224
|
+
propagationKey: item.propagationKey,
|
|
225
|
+
workId: item.work.workId,
|
|
226
|
+
workRoot: item.work.contentRoot,
|
|
227
|
+
nextAction: item.status.nextAction,
|
|
228
|
+
})),
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
233
|
+
if (isMain) {
|
|
234
|
+
try {
|
|
235
|
+
main();
|
|
236
|
+
} catch (error) {
|
|
237
|
+
console.error(error.message);
|
|
238
|
+
process.exitCode = 1;
|
|
239
|
+
}
|
|
240
|
+
}
|