@adea-ai/app-framework 0.31.0 → 0.33.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/README.md +33 -15
- package/dist/app/create-application.js +4 -3
- package/dist/app/serial-queue.d.ts +5 -0
- package/dist/app/serial-queue.js +14 -0
- package/dist/app/value-guards.d.ts +15 -0
- package/dist/app/value-guards.js +29 -0
- package/dist/ci/toolchain-identity.js +1 -1
- package/dist/desktop/channel-proof.js +2 -1
- package/dist/desktop/client-asset-stream.js +6 -12
- package/dist/desktop/desktop-host.d.ts +25 -5
- package/dist/desktop/desktop-host.js +75 -20
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.js +4 -3
- package/dist/installer/command-qualification-command.js +6 -5
- package/dist/installer/hosted-runner.d.ts +9 -2
- package/dist/installer/hosted-runner.js +18 -5
- package/dist/installer/installed-payload.js +20 -46
- package/dist/installer/installer-archive.d.ts +33 -0
- package/dist/installer/installer-archive.js +116 -0
- package/dist/installer/installer-ci-bootstrap.js +10 -6
- package/dist/installer/installer-extraction.js +54 -120
- package/dist/installer/installer-identity.js +33 -111
- package/dist/installer/installer-observation.js +3 -2
- package/dist/installer/installer-process-cleanup.js +7 -46
- package/dist/installer/installer-qualification-command.js +6 -5
- package/dist/installer/installer-upgrade-command.js +5 -5
- package/dist/installer/installer-worker-guard.js +2 -1
- package/dist/native/canonical-path.d.ts +5 -0
- package/dist/native/canonical-path.js +10 -0
- package/dist/native/cef-helper.js +5 -4
- package/dist/native/electrobun-source-patch.js +3 -2
- package/dist/native/{directory-exchange.d.ts → native-rename.d.ts} +2 -0
- package/dist/native/native-rename.js +126 -0
- package/dist/native/native-secret-store.js +2 -6
- package/dist/native/native-utilities.js +4 -4
- package/dist/native/posix-launcher-build.js +1 -1
- package/dist/native/posix-tree-removal.js +2 -2
- package/dist/native/windows-process.d.ts +9 -0
- package/dist/native/windows-process.js +60 -0
- package/dist/release/feed-release-cut.js +2 -1
- package/dist/release/framework-package-publish.js +1 -1
- package/dist/release/framework-update-lock.js +2 -1
- package/dist/release/github-cli.d.ts +18 -0
- package/dist/release/github-cli.js +13 -1
- package/dist/release/github-release-cut.js +3 -2
- package/dist/release/github-release-provenance.js +2 -1
- package/dist/release/github-release-publisher.js +2 -1
- package/dist/release/local-provenance.js +3 -2
- package/dist/release/local-release.js +6 -6
- package/dist/release/qualification-run.d.ts +25 -0
- package/dist/release/qualification-run.js +43 -0
- package/dist/release/release-artifact.js +3 -11
- package/dist/release/release-assets-plan.js +16 -6
- package/dist/release/release-config.js +14 -14
- package/dist/release/release-cut-command.js +14 -4
- package/dist/release/release-cut.js +3 -2
- package/dist/release/release-descriptor-staging.js +13 -27
- package/dist/release/release-finalize.js +2 -1
- package/dist/release/release-publication.js +3 -11
- package/dist/release/release-publish-command.js +15 -6
- package/dist/release/release-qualification.js +3 -2
- package/dist/release/retained-release-build.js +12 -12
- package/dist/update-helper.bundle.js +250 -178
- package/dist/updates/desktop-updater.js +53 -58
- package/dist/updates/packaged-launch-admission.js +3 -2
- package/dist/updates/packaged-release-config.js +6 -5
- package/dist/updates/packaged-update-startup.d.ts +25 -5
- package/dist/updates/packaged-update-startup.js +30 -5
- package/dist/updates/release-feed.js +9 -9
- package/dist/updates/signed-release.js +5 -5
- package/dist/updates/stable-file.d.ts +18 -0
- package/dist/updates/stable-file.js +65 -2
- package/dist/updates/update-adapter.d.ts +2 -13
- package/dist/updates/update-arm.js +13 -13
- package/dist/updates/update-channel-store.js +7 -9
- package/dist/updates/update-discovery.js +30 -34
- package/dist/updates/update-download-cleanup.js +2 -1
- package/dist/updates/update-download.js +2 -4
- package/dist/updates/update-extraction.js +1 -1
- package/dist/updates/update-generation-lease.js +4 -3
- package/dist/updates/update-handoff-plan.js +3 -2
- package/dist/updates/update-helper.js +8 -6
- package/dist/updates/update-instance-lease.js +3 -2
- package/dist/updates/update-launch-gate.js +12 -25
- package/dist/updates/update-launch.js +3 -2
- package/dist/updates/update-lock.js +3 -2
- package/dist/updates/update-marker.js +3 -2
- package/dist/updates/update-process-fence.js +10 -39
- package/dist/updates/update-process-liveness.js +2 -1
- package/dist/updates/update-resume.js +30 -27
- package/dist/updates/update-retention-marker.js +7 -5
- package/dist/updates/update-retention-plan.js +2 -2
- package/dist/updates/update-retirement.js +52 -52
- package/dist/updates/update-state-store.d.ts +2 -0
- package/dist/updates/update-state-store.js +34 -38
- package/dist/updates/update-state.d.ts +8 -3
- package/dist/updates/update-swap-stage.js +6 -5
- package/dist/updates/update-swap.d.ts +1 -1
- package/dist/updates/update-swap.js +8 -6
- package/package.json +4 -12
- package/src/desktop/client-asset-stream.ts +6 -12
- package/src/updates/update-adapter.ts +2 -14
- package/src/updates/update-state.ts +11 -2
- package/templates/application/src/bun/index.ts +13 -9
- package/dist/native/directory-exchange.js +0 -90
- package/dist/native/exclusive-rename.d.ts +0 -2
- package/dist/native/exclusive-rename.js +0 -52
- package/dist/release/retention-dry-run.d.ts +0 -46
- package/dist/release/retention-dry-run.js +0 -94
- package/dist/updates/update-exclusive-rename.d.ts +0 -3
- package/dist/updates/update-exclusive-rename.js +0 -5
|
@@ -1,38 +1,24 @@
|
|
|
1
|
+
import { errorCode, isRecord } from "../app/value-guards.js";
|
|
1
2
|
import { validateCommandReceipts, validateInstallerReceipt } from "./release-qualification.js";
|
|
2
3
|
import { signReleaseDescriptor, verifyReleaseDescriptor } from "../updates/signed-release.js";
|
|
3
4
|
import { feedUrl } from "../updates/release-feed.js";
|
|
4
5
|
import { discoveryPolicies, parseReleaseConfig, platformPayloads, platformTargets } from "./release-config.js";
|
|
5
6
|
import { planReleaseAssets } from "./release-assets-plan.js";
|
|
7
|
+
import { hashFileAt } from "../updates/stable-file.js";
|
|
6
8
|
import { commandReceiptName } from "../installer/command-qualification-command.js";
|
|
7
|
-
import { lstat,
|
|
9
|
+
import { lstat, readFile, writeFile } from "node:fs/promises";
|
|
8
10
|
import { join, resolve } from "node:path";
|
|
9
|
-
import {
|
|
11
|
+
import { createPublicKey } from "node:crypto";
|
|
10
12
|
// src/release/release-descriptor-staging.ts
|
|
11
|
-
var object = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
13
|
async function staged(path, name) {
|
|
13
14
|
const info = await lstat(path);
|
|
14
15
|
if (!info.isFile() || info.isSymbolicLink() || !Number.isSafeInteger(info.size) || info.size < 1) throw new Error("Invalid staged payload");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for await (const chunk of file.createReadStream({ autoClose: false })) {
|
|
22
|
-
size += chunk.length;
|
|
23
|
-
if (size > before.size) throw new Error("Staged payload changed");
|
|
24
|
-
hash.update(chunk);
|
|
25
|
-
}
|
|
26
|
-
const after = await file.stat();
|
|
27
|
-
if (size !== before.size || after.size !== before.size || after.mtimeMs !== before.mtimeMs || after.dev !== before.dev || after.ino !== before.ino) throw new Error("Staged payload changed");
|
|
28
|
-
return {
|
|
29
|
-
name,
|
|
30
|
-
size,
|
|
31
|
-
digest: "sha256:" + hash.digest("hex")
|
|
32
|
-
};
|
|
33
|
-
} finally {
|
|
34
|
-
await file.close();
|
|
35
|
-
}
|
|
16
|
+
const { size, sha256 } = await hashFileAt(path, info, "Staged payload changed");
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
size,
|
|
20
|
+
digest: "sha256:" + sha256
|
|
21
|
+
};
|
|
36
22
|
}
|
|
37
23
|
/** Sign and self-verify one descriptor per discovery policy, each naming its staged payload. */
|
|
38
24
|
function signDiscoveryDescriptors(options) {
|
|
@@ -79,7 +65,7 @@ async function writeDescriptors(directory, signed) {
|
|
|
79
65
|
await lstat(join(directory, value.name));
|
|
80
66
|
throw new Error("Descriptor already exists");
|
|
81
67
|
} catch (error) {
|
|
82
|
-
if (error
|
|
68
|
+
if (errorCode(error) !== "ENOENT") throw error;
|
|
83
69
|
}
|
|
84
70
|
for (const value of signed) await writeFile(join(directory, value.name), value.bytes, {
|
|
85
71
|
flag: "wx",
|
|
@@ -88,7 +74,7 @@ async function writeDescriptors(directory, signed) {
|
|
|
88
74
|
}
|
|
89
75
|
/** The configured public key for `keyId`, which must be the signing key's own. */
|
|
90
76
|
function configuredSigningKey(config, keyId, privateKey) {
|
|
91
|
-
if (!
|
|
77
|
+
if (!isRecord(config.releaseSigningKeys) || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(keyId) || privateKey.type !== "private" || privateKey.asymmetricKeyType !== "ed25519") throw new Error("Invalid descriptor signing context");
|
|
92
78
|
const encoded = config.releaseSigningKeys[keyId];
|
|
93
79
|
const publicKey = createPublicKey(privateKey).export({
|
|
94
80
|
type: "spki",
|
|
@@ -113,7 +99,7 @@ async function stageReleaseDescriptors(options) {
|
|
|
113
99
|
tag,
|
|
114
100
|
run: options.run
|
|
115
101
|
});
|
|
116
|
-
if (env.SOURCE_SHA !== plan.sourceSha || !
|
|
102
|
+
if (env.SOURCE_SHA !== plan.sourceSha || !isRecord(config) || typeof config.appId !== "string" || !isRecord(config.descriptors)) throw new Error("Invalid descriptor signing context");
|
|
117
103
|
const encoded = configuredSigningKey(config, keyId, privateKey);
|
|
118
104
|
const parsed = parseReleaseConfig(config), requirements = parsed.requirements(tag), feed = feedUrl(parsed.feed);
|
|
119
105
|
const policies = discoveryPolicies(config, tag);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isGitSha } from "../app/value-guards.js";
|
|
1
2
|
import { githubCli } from "./github-cli.js";
|
|
2
3
|
import { lookupRelease } from "./github-release-lookup.js";
|
|
3
4
|
import { isRepositorySlug } from "../updates/signed-release.js";
|
|
@@ -34,7 +35,7 @@ function parseFinalizationEvent(event, repository, eventName = "workflow_run") {
|
|
|
34
35
|
async function finalizeReleasePleaseDraft(options) {
|
|
35
36
|
const { env, config, tag, runId, runAttempt } = options;
|
|
36
37
|
const repository = env.GITHUB_REPOSITORY ?? "";
|
|
37
|
-
if (env.GITHUB_ACTIONS !== "true" || !["workflow_run", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") || env.GITHUB_REF !== "refs/heads/main" || !isRepositorySlug(repository) ||
|
|
38
|
+
if (env.GITHUB_ACTIONS !== "true" || !["workflow_run", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") || env.GITHUB_REF !== "refs/heads/main" || !isRepositorySlug(repository) || !isGitSha(env.GITHUB_SHA) || !/^[1-9]\d{0,19}$/.test(runId) || !Number.isSafeInteger(runAttempt) || runAttempt < 1 || !/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) || tag.length > 65) throw new Error("Invalid release finalization context");
|
|
38
39
|
const parsed = parseReleaseConfig(config);
|
|
39
40
|
if (!parsed.releasePleaseManifestPath || typeof config !== "object" || config === null || typeof config.appName !== "string") throw new Error("Release Please finalization is not configured");
|
|
40
41
|
const run = options.run ?? githubCli();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validateReleaseQualification } from "./release-qualification.js";
|
|
2
2
|
import { verifyReleaseDescriptor } from "../updates/signed-release.js";
|
|
3
3
|
import { releaseAssetNames } from "./release-config.js";
|
|
4
|
-
import {
|
|
4
|
+
import { hashUnchangedFile, openUnchangedFile } from "../updates/stable-file.js";
|
|
5
5
|
import { lstat, mkdtemp, open, rm, writeFile } from "node:fs/promises";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
@@ -17,19 +17,11 @@ async function fileIdentity(path, name) {
|
|
|
17
17
|
const { file, before } = await openUnchangedFile(path, info, "Invalid staged artifact");
|
|
18
18
|
try {
|
|
19
19
|
if (!Number.isSafeInteger(before.size) || before.size < 1) throw new Error("Invalid staged artifact");
|
|
20
|
-
const
|
|
21
|
-
let size = 0;
|
|
22
|
-
for await (const chunk of file.createReadStream({ autoClose: false })) {
|
|
23
|
-
size += chunk.length;
|
|
24
|
-
if (size > before.size) throw new Error("Staged artifact changed");
|
|
25
|
-
hash.update(chunk);
|
|
26
|
-
}
|
|
27
|
-
const after = await file.stat();
|
|
28
|
-
if (size !== before.size || !sameFile(before, after)) throw new Error("Staged artifact changed");
|
|
20
|
+
const { size, sha256 } = await hashUnchangedFile(file, before, "Staged artifact changed");
|
|
29
21
|
return {
|
|
30
22
|
name,
|
|
31
23
|
size,
|
|
32
|
-
digest: "sha256:" +
|
|
24
|
+
digest: "sha256:" + sha256
|
|
33
25
|
};
|
|
34
26
|
} finally {
|
|
35
27
|
await file.close();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isGitSha, isRecord } from "../app/value-guards.js";
|
|
2
|
+
import { githubCli, verifyWorkflowAttempt } from "./github-cli.js";
|
|
2
3
|
import { assertRepositorySlug } from "../updates/signed-release.js";
|
|
3
4
|
import { feedUrl } from "../updates/release-feed.js";
|
|
4
5
|
import { discoveryPolicies, parseReleaseConfig } from "./release-config.js";
|
|
@@ -8,7 +9,6 @@ import { createGitHubReleasePublisher } from "./github-release-publisher.js";
|
|
|
8
9
|
import { open } from "node:fs/promises";
|
|
9
10
|
import { join, resolve } from "node:path";
|
|
10
11
|
// src/release/release-publish-command.ts
|
|
11
|
-
var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
12
|
async function boundedJson(path) {
|
|
13
13
|
const handle = await open(path, "r");
|
|
14
14
|
try {
|
|
@@ -30,10 +30,10 @@ async function boundedJson(path) {
|
|
|
30
30
|
/** Publish only the current trusted release-assets attempt and its staged receipts. */
|
|
31
31
|
async function runReleasePublishCommand(options) {
|
|
32
32
|
const { env, config } = options;
|
|
33
|
-
if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !env.GITHUB_REPOSITORY ||
|
|
33
|
+
if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !env.GITHUB_REPOSITORY || !isGitSha(env.GITHUB_SHA) || !isGitSha(env.SOURCE_SHA) || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || !/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(env.RELEASE_TAG ?? "")) throw new Error("Publication requires a trusted release-assets workflow");
|
|
34
34
|
assertRepositorySlug(env.GITHUB_REPOSITORY);
|
|
35
35
|
const { requirements, releasePleaseManifestPath, releaseWorkflows, feed } = parseReleaseConfig(config);
|
|
36
|
-
if (!
|
|
36
|
+
if (!isRecord(config) || typeof config.appId !== "string" || !/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(config.appId) || config.appId.length > 255 || !isRecord(config.releaseSigningKeys) || !isRecord(config.descriptors)) throw new Error("Invalid release signing configuration");
|
|
37
37
|
const keyEntries = Object.entries(config.releaseSigningKeys);
|
|
38
38
|
if (!keyEntries.length || keyEntries.length > 16) throw new Error("Missing release verification keys");
|
|
39
39
|
const keys = /* @__PURE__ */ new Map();
|
|
@@ -59,8 +59,17 @@ async function runReleasePublishCommand(options) {
|
|
|
59
59
|
allowedPayloads: [policy.payload]
|
|
60
60
|
};
|
|
61
61
|
const run = options.run ?? githubCli();
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
await verifyWorkflowAttempt({
|
|
63
|
+
run,
|
|
64
|
+
repository,
|
|
65
|
+
env,
|
|
66
|
+
expected: {
|
|
67
|
+
headSha: env.GITHUB_SHA,
|
|
68
|
+
event: "workflow_dispatch",
|
|
69
|
+
path: releaseWorkflows.assets
|
|
70
|
+
},
|
|
71
|
+
mismatch: "Release-assets workflow provenance mismatch"
|
|
72
|
+
});
|
|
64
73
|
const directory = resolve(options.directory);
|
|
65
74
|
const installerReceipts = await Promise.all(Object.keys(releaseRequirements.platforms).map(async (platform) => await boundedJson(join(directory, `installer-test-${platform}.json`))));
|
|
66
75
|
const commandReceipts = releaseRequirements.commandArtifacts ? await Promise.all(Object.entries(releaseRequirements.commandArtifacts).flatMap(([kind, byPlatform]) => Object.keys(byPlatform).map(async (platform) => await boundedJson(join(directory, commandReceiptName(kind, platform)))))) : void 0;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isGitSha } from "../app/value-guards.js";
|
|
1
2
|
import { containsAsciiControl } from "../desktop/string-policy.js";
|
|
2
3
|
// src/release/release-qualification.ts
|
|
3
4
|
function assert(condition, message) {
|
|
@@ -75,7 +76,7 @@ function validateInstallerReceipt(identity, entry, platform, names, assets, offl
|
|
|
75
76
|
return true;
|
|
76
77
|
}
|
|
77
78
|
function assertIdentity(identity, platform) {
|
|
78
|
-
assert(/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(identity.tag) &&
|
|
79
|
+
assert(/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(identity.tag) && isGitSha(identity.sourceSha) && isGitSha(identity.workflowSha) && /^[1-9]\d{0,19}$/.test(identity.runId) && Number.isSafeInteger(identity.runAttempt) && identity.runAttempt > 0 && /^[a-z0-9-]+$/.test(platform), "Invalid receipt context");
|
|
79
80
|
}
|
|
80
81
|
/** Validate one command artifact receipt against the exact attempt and payload bytes. */
|
|
81
82
|
function validateCommandReceipt(identity, entry, kind, platform, name, assets) {
|
|
@@ -111,7 +112,7 @@ function validateCommandReceipts(identity, receipts, requirements, assets) {
|
|
|
111
112
|
function validateReleaseQualification(release, receipt, sourceSha, requirements) {
|
|
112
113
|
const required = expectedAssets(requirements);
|
|
113
114
|
const platforms = Object.keys(requirements.platforms);
|
|
114
|
-
assert(release.draft === false && receipt.schema === 2 && receipt.tag === release.tag_name && receipt.sourceSha === sourceSha &&
|
|
115
|
+
assert(release.draft === false && receipt.schema === 2 && receipt.tag === release.tag_name && receipt.sourceSha === sourceSha && isGitSha(sourceSha) && isGitSha(receipt.workflowSha) && /^[1-9]\d*$/.test(receipt.runId) && Number.isSafeInteger(receipt.runAttempt) && receipt.runAttempt > 0, "Qualification identity mismatch");
|
|
115
116
|
assert(receipt.platforms.length === platforms.length && receipt.installerTests.length === platforms.length && receipt.installerReceipts.length === platforms.length && platforms.every((platform) => receipt.platforms.filter((x) => x === platform).length === 1 && receipt.installerTests.filter((x) => x === platform).length === 1), "Missing or duplicate platform tests");
|
|
116
117
|
for (const platform of platforms) {
|
|
117
118
|
const entries = receipt.installerReceipts.filter((entry) => entry.platform === platform);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { isGitSha, isRecord } from "../app/value-guards.js";
|
|
1
2
|
import { githubCli } from "./github-cli.js";
|
|
2
3
|
import { lookupRelease } from "./github-release-lookup.js";
|
|
3
4
|
import { parseReleaseConfig, platformPayloads, workflowFile } from "./release-config.js";
|
|
4
5
|
import { createGitHubReleaseCutProvider } from "./github-release-cut.js";
|
|
5
6
|
import { planReleaseAssets, releasePlanGitHubEnvironment } from "./release-assets-plan.js";
|
|
6
7
|
// src/release/retained-release-build.ts
|
|
7
|
-
var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
8
|
var id = (value) => {
|
|
9
9
|
if (typeof value === "number" && !Number.isSafeInteger(value)) throw new Error("Invalid GitHub identity");
|
|
10
10
|
const text = String(value);
|
|
@@ -18,7 +18,7 @@ async function selectRetainedReleaseBuild(options) {
|
|
|
18
18
|
"macos-arm64",
|
|
19
19
|
"windows-x64",
|
|
20
20
|
"linux-x64"
|
|
21
|
-
].includes(platform) || !
|
|
21
|
+
].includes(platform) || !isRecord(config) || typeof config.appName !== "string" || env.RELEASE_TAG !== tag) throw new Error("Invalid retained build context");
|
|
22
22
|
const run = options.run ?? githubCli(releasePlanGitHubEnvironment(env));
|
|
23
23
|
const plan = await planReleaseAssets({
|
|
24
24
|
env,
|
|
@@ -39,7 +39,7 @@ async function selectRetainedReleaseBuild(options) {
|
|
|
39
39
|
includeDraft: true
|
|
40
40
|
});
|
|
41
41
|
const hiddenDraft = release === null;
|
|
42
|
-
if (!hiddenDraft && (!
|
|
42
|
+
if (!hiddenDraft && (!isRecord(release) || release.tag_name !== tag)) throw new Error("Invalid release assets");
|
|
43
43
|
const releaseAssets = [];
|
|
44
44
|
if (!hiddenDraft) {
|
|
45
45
|
const releaseId = id(release.id);
|
|
@@ -51,7 +51,7 @@ async function selectRetainedReleaseBuild(options) {
|
|
|
51
51
|
if (page === 10) throw new Error("Too many release assets");
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
if (releaseAssets.some((asset) => !
|
|
54
|
+
if (releaseAssets.some((asset) => !isRecord(asset) || typeof asset.name !== "string") || new Set(releaseAssets.map((asset) => asset.name)).size !== releaseAssets.length) throw new Error("Invalid release assets");
|
|
55
55
|
const published = expected.some((name) => releaseAssets.some((asset) => asset.name === name));
|
|
56
56
|
const provider = createGitHubReleaseCutProvider({
|
|
57
57
|
repository,
|
|
@@ -64,35 +64,35 @@ async function selectRetainedReleaseBuild(options) {
|
|
|
64
64
|
const candidates = [], seenArtifacts = /* @__PURE__ */ new Set(), seenRuns = /* @__PURE__ */ new Set();
|
|
65
65
|
for (let page = 1; page <= 10; page++) {
|
|
66
66
|
const response = await read(`${base}/actions/workflows/${workflowFile(assetsWorkflow)}/runs?event=workflow_dispatch&per_page=100&page=${page}`);
|
|
67
|
-
if (!
|
|
67
|
+
if (!isRecord(response) || !Array.isArray(response.workflow_runs) || response.workflow_runs.length > 100) throw new Error("Invalid release workflow listing");
|
|
68
68
|
for (const value of response.workflow_runs) {
|
|
69
|
-
if (!
|
|
69
|
+
if (!isRecord(value) || value.display_title !== `framework-release-assets:${tag}` || value.head_branch !== "main" || value.event !== "workflow_dispatch" || value.path !== assetsWorkflow) continue;
|
|
70
70
|
const runId = id(value.id);
|
|
71
71
|
if (seenRuns.has(runId)) throw new Error("Duplicate workflow run");
|
|
72
72
|
seenRuns.add(runId);
|
|
73
73
|
if (value.status !== "completed" && runId !== env.GITHUB_RUN_ID) continue;
|
|
74
|
-
if (typeof value.head_sha !== "string" ||
|
|
74
|
+
if (typeof value.head_sha !== "string" || !isGitSha(value.head_sha) || !await provider.isMainAncestor(value.head_sha)) throw new Error("Untrusted retained workflow");
|
|
75
75
|
for (let artifactPage = 1; artifactPage <= 10; artifactPage++) {
|
|
76
76
|
const listing = await read(`${base}/actions/runs/${runId}/artifacts?per_page=100&page=${artifactPage}`);
|
|
77
|
-
if (!
|
|
77
|
+
if (!isRecord(listing) || !Array.isArray(listing.artifacts) || listing.artifacts.length > 100) throw new Error("Invalid retained artifact listing");
|
|
78
78
|
for (const artifact of listing.artifacts) {
|
|
79
|
-
if (!
|
|
79
|
+
if (!isRecord(artifact) || typeof artifact.name !== "string") throw new Error("Invalid retained artifact");
|
|
80
80
|
const prefix = `framework-build-${tag}-${platform}-${plan.sourceSha}-r${runId}-a`;
|
|
81
81
|
if (!artifact.name.startsWith(prefix)) continue;
|
|
82
82
|
const attemptText = artifact.name.slice(prefix.length);
|
|
83
83
|
if (artifact.expired === true) continue;
|
|
84
|
-
if (!/^[1-9]\d{0,8}$/.test(attemptText) || artifact.expired !== false || typeof artifact.digest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(artifact.digest) || !Number.isSafeInteger(artifact.size_in_bytes) || Number(artifact.size_in_bytes) < 1 || !
|
|
84
|
+
if (!/^[1-9]\d{0,8}$/.test(attemptText) || artifact.expired !== false || typeof artifact.digest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(artifact.digest) || !Number.isSafeInteger(artifact.size_in_bytes) || Number(artifact.size_in_bytes) < 1 || !isRecord(artifact.workflow_run) || id(artifact.workflow_run.id) !== runId || artifact.workflow_run.head_sha !== value.head_sha || artifact.workflow_run.head_branch !== "main") throw new Error("Invalid retained artifact provenance");
|
|
85
85
|
const artifactId = id(artifact.id);
|
|
86
86
|
if (seenArtifacts.has(artifactId)) throw new Error("Duplicate retained artifact");
|
|
87
87
|
seenArtifacts.add(artifactId);
|
|
88
88
|
const attempt = Number(attemptText);
|
|
89
89
|
if (runId === env.GITHUB_RUN_ID && attempt >= Number(env.GITHUB_RUN_ATTEMPT)) continue;
|
|
90
90
|
const attemptRun = await read(`${base}/actions/runs/${runId}/attempts/${attempt}`);
|
|
91
|
-
if (!
|
|
91
|
+
if (!isRecord(attemptRun) || id(attemptRun.id) !== runId || attemptRun.run_attempt !== attempt || attemptRun.head_sha !== value.head_sha || attemptRun.head_branch !== "main" || attemptRun.event !== "workflow_dispatch" || attemptRun.path !== assetsWorkflow || attemptRun.display_title !== `framework-release-assets:${tag}` || !isRecord(attemptRun.repository) || attemptRun.repository.full_name !== repository || attemptRun.status !== "completed") throw new Error("Retained attempt provenance mismatch");
|
|
92
92
|
const jobs = [];
|
|
93
93
|
for (let jobPage = 1; jobPage <= 10; jobPage++) {
|
|
94
94
|
const data = await read(`${base}/actions/runs/${runId}/attempts/${attempt}/jobs?per_page=100&page=${jobPage}`);
|
|
95
|
-
if (!
|
|
95
|
+
if (!isRecord(data) || !Array.isArray(data.jobs) || data.jobs.length > 100 || data.jobs.some((job) => !isRecord(job))) throw new Error("Invalid retained job listing");
|
|
96
96
|
jobs.push(...data.jobs);
|
|
97
97
|
if (data.jobs.length < 100) break;
|
|
98
98
|
if (jobPage === 10) throw new Error("Too many retained jobs");
|