45 lines
2.4 KiB
JavaScript
45 lines
2.4 KiB
JavaScript
import { createHash } from "node:crypto";
|
|
import { readFile, writeFile } from "node:fs/promises";
|
|
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const execFileAsync = promisify(execFile);
|
|
const manifest = JSON.parse(
|
|
await readFile(path.join(root, "package.json"), "utf8"),
|
|
);
|
|
const artifacts = [];
|
|
for (const kind of ["Setup", "Portable"]) {
|
|
const name = `ForgeFlow-${kind}-${manifest.version}-win-x64.exe`;
|
|
const binary = await readFile(path.join(root, "dist", name));
|
|
const sha256 = createHash("sha256").update(binary).digest("hex");
|
|
await writeFile(
|
|
path.join(root, "dist", `${name}.sha256`),
|
|
`${sha256} ${name}\n`,
|
|
"utf8",
|
|
);
|
|
console.log(`${name}: ${sha256}`);
|
|
artifacts.push({ name, sha256 });
|
|
}
|
|
const commit = String(process.env.FORGEFLOW_BUILD_COMMIT || (await execFileAsync("git", ["rev-parse", "HEAD"], { cwd: root })).stdout).trim();
|
|
const buildId = String(process.env.FORGEFLOW_BUILD_ID || `${manifest.version}-${commit.slice(0, 12)}`);
|
|
const provenance = {
|
|
schemaVersion: 1,
|
|
product: "ForgeFlow",
|
|
version: manifest.version,
|
|
commit,
|
|
buildId,
|
|
createdAt: new Date().toISOString(),
|
|
publisherManifestSignature: "Ed25519",
|
|
authenticodeSigned: process.env.FORGEFLOW_SIGNED_RELEASE === "1",
|
|
expectedAuthenticodePublisher:
|
|
process.env.FORGEFLOW_EXPECTED_PUBLISHER || null,
|
|
artifacts,
|
|
};
|
|
await writeFile(path.join(root, "dist", `ForgeFlow-${manifest.version}-provenance.json`), `${JSON.stringify(provenance, null, 2)}\n`, "utf8");
|
|
const lock = JSON.parse(await readFile(path.join(root, "package-lock.json"), "utf8"));
|
|
const components = Object.entries(lock.packages || {}).filter(([name]) => name.startsWith("node_modules/")).map(([name, value]) => ({ type: "library", name: name.slice(13), version: value.version || "unknown", licenses: value.license ? [{ license: { id: value.license } }] : undefined })).sort((a, b) => a.name.localeCompare(b.name));
|
|
await writeFile(path.join(root, "dist", `ForgeFlow-${manifest.version}-sbom.cdx.json`), `${JSON.stringify({ bomFormat: "CycloneDX", specVersion: "1.5", serialNumber: `urn:uuid:${buildId}`, version: 1, metadata: { component: { type: "application", name: "ForgeFlow", version: manifest.version } }, components }, null, 2)}\n`, "utf8");
|