@adea-ai/app-framework-release-tools 0.3.0 → 0.4.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/cli.js +578 -111
- package/dist/index.js +202 -0
- package/dist/release-tools-source.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(exports_src, {
|
|
|
40
40
|
selectRetainedStep: () => selectRetainedStep,
|
|
41
41
|
signReleaseArtifact: () => signReleaseArtifact,
|
|
42
42
|
stageBuildStep: () => stageBuildStep,
|
|
43
|
+
stageLinuxPackagePair: () => stageLinuxPackagePair,
|
|
43
44
|
stagePlatformArtifacts: () => stagePlatformArtifacts,
|
|
44
45
|
stageReleaseDescriptors: () => stageReleaseDescriptors,
|
|
45
46
|
verifyDailyReleaseMatrix: () => verifyDailyReleaseMatrix,
|
|
@@ -8128,6 +8129,206 @@ var stageBuildStep = (context, directory, artifacts) => run2(context, stageBuild
|
|
|
8128
8129
|
var inspectStagedStep = (context, directory) => run2(context, inspectStagedStepEffect(context, directory));
|
|
8129
8130
|
var qualifyStep = (context, directory) => run2(context, qualifyStepEffect(context, directory));
|
|
8130
8131
|
var qualifyUpgradeStep = (context, directory, onStage) => run2(context, qualifyUpgradeStepEffect(context, directory, onStage));
|
|
8132
|
+
// src/library/linux-package-pair.ts
|
|
8133
|
+
import { execFile as execFile3 } from "child_process";
|
|
8134
|
+
import {
|
|
8135
|
+
chmod as chmod3,
|
|
8136
|
+
link,
|
|
8137
|
+
mkdir as mkdir11,
|
|
8138
|
+
mkdtemp as mkdtemp10,
|
|
8139
|
+
open as open12,
|
|
8140
|
+
readFile as readFile10,
|
|
8141
|
+
realpath as realpath10,
|
|
8142
|
+
rm as rm10,
|
|
8143
|
+
writeFile as writeFile11
|
|
8144
|
+
} from "fs/promises";
|
|
8145
|
+
import { dirname as dirname14, join as join33, resolve as resolve16 } from "path";
|
|
8146
|
+
import { promisify as promisify2 } from "util";
|
|
8147
|
+
var shasum = /^[a-f0-9]{64}$/;
|
|
8148
|
+
var basename15 = /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/;
|
|
8149
|
+
var validTag = /^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/;
|
|
8150
|
+
var exec = promisify2(execFile3);
|
|
8151
|
+
function requireThat2(condition, message) {
|
|
8152
|
+
if (!condition)
|
|
8153
|
+
throw new Error(message);
|
|
8154
|
+
}
|
|
8155
|
+
function record2(value) {
|
|
8156
|
+
requireThat2(typeof value === "object" && value !== null && !Array.isArray(value), "Invalid producer receipt");
|
|
8157
|
+
return value;
|
|
8158
|
+
}
|
|
8159
|
+
function validIdentity(value) {
|
|
8160
|
+
const { name, size, sha256 } = record2(value);
|
|
8161
|
+
requireThat2(typeof name === "string" && basename15.test(name) && typeof size === "number" && Number.isSafeInteger(size) && size > 0 && typeof sha256 === "string" && shasum.test(sha256), "Invalid package artifact identity");
|
|
8162
|
+
return { name, size, sha256 };
|
|
8163
|
+
}
|
|
8164
|
+
var inspectWithNativeTools = async (tool, args) => {
|
|
8165
|
+
try {
|
|
8166
|
+
const { stdout } = await exec(tool, [...args], {
|
|
8167
|
+
encoding: "utf8",
|
|
8168
|
+
maxBuffer: 128 * 1024,
|
|
8169
|
+
timeout: 30000,
|
|
8170
|
+
env: { PATH: process.env.PATH, LC_ALL: "C" }
|
|
8171
|
+
});
|
|
8172
|
+
return stdout;
|
|
8173
|
+
} catch (error) {
|
|
8174
|
+
if (error.code === "ENOENT")
|
|
8175
|
+
throw new Error(`${tool} is required to inspect Linux package candidates`, { cause: error });
|
|
8176
|
+
throw new Error(`${tool} could not inspect Linux package candidate`, { cause: error });
|
|
8177
|
+
}
|
|
8178
|
+
};
|
|
8179
|
+
function parseDebianIdentity(text, packageName, version) {
|
|
8180
|
+
const fields = text.trimEnd().split(/\r?\n/);
|
|
8181
|
+
requireThat2(fields.length === 3 && new Set(fields).size === 3 && [`Package: ${packageName}`, `Version: ${version}`, "Architecture: amd64"].every((value) => fields.includes(value)), "Debian package name, version or architecture does not match the release policy");
|
|
8182
|
+
}
|
|
8183
|
+
function requireRegularDesktopEntry(listing, id) {
|
|
8184
|
+
const lines = listing.trimEnd().split(/\r?\n/);
|
|
8185
|
+
const fields = /^[d-][-rwxstST]{9} +\d+\/\d+ +\d+ +\d{4}-\d{2}-\d{2} \d{2}:\d{2} (.+)$/;
|
|
8186
|
+
requireThat2(lines.length === 2 && lines[0]?.startsWith("d") && fields.exec(lines[0])?.[1] === "squashfs-root" && lines[1]?.startsWith("-") && fields.exec(lines[1])?.[1] === `squashfs-root/${id}`, "AppImage must contain one regular root desktop entry");
|
|
8187
|
+
}
|
|
8188
|
+
function requireDesktopIdentity(text, name, version) {
|
|
8189
|
+
let inDesktop = false;
|
|
8190
|
+
let foundGroup = false;
|
|
8191
|
+
const fields = new Map;
|
|
8192
|
+
for (const line of text.split(/\r?\n/)) {
|
|
8193
|
+
if (/^\[.*\]$/.test(line)) {
|
|
8194
|
+
inDesktop = line === "[Desktop Entry]";
|
|
8195
|
+
if (inDesktop) {
|
|
8196
|
+
requireThat2(!foundGroup, "Duplicate AppImage desktop entry");
|
|
8197
|
+
foundGroup = true;
|
|
8198
|
+
}
|
|
8199
|
+
continue;
|
|
8200
|
+
}
|
|
8201
|
+
if (!inDesktop || !line || line.startsWith("#"))
|
|
8202
|
+
continue;
|
|
8203
|
+
const match = /^([^=]+)=(.*)$/.exec(line);
|
|
8204
|
+
requireThat2(match && !fields.has(match[1]), "Malformed or duplicate AppImage desktop fields");
|
|
8205
|
+
fields.set(match[1], match[2]);
|
|
8206
|
+
}
|
|
8207
|
+
requireThat2(fields.get("Type") === "Application" && fields.get("Name") === name && fields.get("X-AppImage-Version") === version, "AppImage desktop entry has wrong app identity or release version");
|
|
8208
|
+
}
|
|
8209
|
+
function digestWindow(runtime) {
|
|
8210
|
+
const sectionStart = Number(runtime.readBigUInt64LE(40));
|
|
8211
|
+
const sectionSize = runtime.readUInt16LE(58);
|
|
8212
|
+
const count = runtime.readUInt16LE(60);
|
|
8213
|
+
const namesIndex = runtime.readUInt16LE(62);
|
|
8214
|
+
requireThat2(Number.isSafeInteger(sectionStart) && sectionStart >= 64 && sectionSize === 64 && namesIndex < count && sectionStart + count * sectionSize <= runtime.length, "Invalid pinned AppImage runtime ELF section table");
|
|
8215
|
+
const namesHeader = sectionStart + sectionSize * namesIndex;
|
|
8216
|
+
const namesStart = Number(runtime.readBigUInt64LE(namesHeader + 24));
|
|
8217
|
+
const namesSize = Number(runtime.readBigUInt64LE(namesHeader + 32));
|
|
8218
|
+
requireThat2(Number.isSafeInteger(namesStart) && Number.isSafeInteger(namesSize) && namesStart >= 64 && namesStart + namesSize <= runtime.length, "Invalid pinned AppImage runtime ELF section names");
|
|
8219
|
+
const names = runtime.subarray(namesStart, namesStart + namesSize);
|
|
8220
|
+
const matches = [];
|
|
8221
|
+
for (let i = 0;i < count; i++) {
|
|
8222
|
+
const section = sectionStart + sectionSize * i;
|
|
8223
|
+
const nameAt = runtime.readUInt32LE(section);
|
|
8224
|
+
const end = names.indexOf(0, nameAt);
|
|
8225
|
+
if (end < 0 || names.toString("ascii", nameAt, end) !== ".digest_md5")
|
|
8226
|
+
continue;
|
|
8227
|
+
const dataAt = Number(runtime.readBigUInt64LE(section + 24));
|
|
8228
|
+
const dataSize = Number(runtime.readBigUInt64LE(section + 32));
|
|
8229
|
+
requireThat2(Number.isSafeInteger(dataAt) && Number.isSafeInteger(dataSize) && dataAt >= 64 && dataSize >= 16 && dataAt + dataSize <= runtime.length, "Invalid pinned AppImage runtime digest section");
|
|
8230
|
+
matches.push(dataAt);
|
|
8231
|
+
}
|
|
8232
|
+
requireThat2(matches.length === 1, "Expected one pinned AppImage runtime digest section");
|
|
8233
|
+
return matches[0];
|
|
8234
|
+
}
|
|
8235
|
+
function type2X64(bytes) {
|
|
8236
|
+
return bytes.length >= 64 && bytes.toString("hex", 0, 6) === "7f454c460201" && bytes.toString("hex", 8, 11) === "414902" && bytes.readUInt16LE(18) === 62;
|
|
8237
|
+
}
|
|
8238
|
+
async function verifyEmbeddedRuntime(path, runtime) {
|
|
8239
|
+
requireThat2(type2X64(runtime), "Expected a pinned Type 2 x86_64 AppImage runtime");
|
|
8240
|
+
const ignored = digestWindow(runtime);
|
|
8241
|
+
const fd = await open12(path, "r");
|
|
8242
|
+
try {
|
|
8243
|
+
const prefix = Buffer.alloc(runtime.length + 4);
|
|
8244
|
+
let filled = 0;
|
|
8245
|
+
while (filled < prefix.length) {
|
|
8246
|
+
const { bytesRead } = await fd.read(prefix, filled, prefix.length - filled, filled);
|
|
8247
|
+
if (!bytesRead)
|
|
8248
|
+
throw new Error("Incomplete embedded AppImage runtime or SquashFS header");
|
|
8249
|
+
filled += bytesRead;
|
|
8250
|
+
}
|
|
8251
|
+
requireThat2(type2X64(prefix), "Expected a Type 2 x86_64 AppImage");
|
|
8252
|
+
requireThat2(runtime.subarray(0, ignored).equals(prefix.subarray(0, ignored)) && runtime.subarray(ignored + 16).equals(prefix.subarray(ignored + 16, runtime.length)), "AppImage runtime differs from its trusted pin outside the tool-generated digest");
|
|
8253
|
+
requireThat2(prefix.toString("ascii", runtime.length) === "hsqs", "Missing embedded SquashFS at the pinned runtime offset");
|
|
8254
|
+
} finally {
|
|
8255
|
+
await fd.close();
|
|
8256
|
+
}
|
|
8257
|
+
}
|
|
8258
|
+
async function stageLinuxPackagePairWithInspection(options, inspect) {
|
|
8259
|
+
const { expected, sources } = options;
|
|
8260
|
+
const receipt = record2(options.producer);
|
|
8261
|
+
const archive = validIdentity(expected.archive);
|
|
8262
|
+
const runtime = validIdentity(expected.runtime);
|
|
8263
|
+
requireThat2(validTag.test(expected.tag) && /^[a-f0-9]{40}$/.test(expected.sourceSha) && basename15.test(expected.debName) && expected.debName.endsWith(".deb") && basename15.test(expected.appImageName) && expected.appImageName.endsWith(".AppImage") && archive.name.endsWith(".tar.zst") && /^[a-z0-9][a-z0-9+.-]+$/.test(expected.debPackage) && /^[A-Za-z0-9][A-Za-z0-9_.-]*\.desktop$/.test(expected.desktopId) && expected.desktopName.length > 0 && !/[\r\n]/.test(expected.desktopName) && Number.isSafeInteger(expected.runtime.size) && expected.runtime.size >= 64 && expected.runtime.size <= 64 * 1024 * 1024 && shasum.test(expected.runtime.sha256), "Invalid trusted Linux package policy");
|
|
8264
|
+
requireThat2(receipt.tag === expected.tag && receipt.sourceSha === expected.sourceSha && receipt.platform === "linux-x64" && receipt.updateArchiveSha256 === archive.sha256 && Array.isArray(receipt.artifacts) && receipt.artifacts.length === 2, "Package producer receipt names a different source, tag, platform or update archive");
|
|
8265
|
+
const names = [expected.debName, expected.appImageName];
|
|
8266
|
+
const artifacts = receipt.artifacts.map(validIdentity);
|
|
8267
|
+
const trustedArtifacts = expected.artifacts.map(validIdentity);
|
|
8268
|
+
requireThat2(trustedArtifacts.length === 2 && names.every((name) => {
|
|
8269
|
+
const fromProducer = artifacts.find((file) => file.name === name);
|
|
8270
|
+
const trusted = trustedArtifacts.find((file) => file.name === name);
|
|
8271
|
+
return fromProducer && trusted && trusted.size === fromProducer.size && trusted.sha256 === fromProducer.sha256;
|
|
8272
|
+
}), "Package producer receipt must describe exactly the protected DEB and AppImage");
|
|
8273
|
+
const destination = resolve16(options.output);
|
|
8274
|
+
const parent = await realpath10(dirname14(destination));
|
|
8275
|
+
const work = await mkdtemp10(join33(parent, ".linux-package-pair-"));
|
|
8276
|
+
try {
|
|
8277
|
+
const files = await runReleaseLibrary(provideLibraryPorts()(stageExpectedFilesEffect({
|
|
8278
|
+
directory: work,
|
|
8279
|
+
expected: [...names, archive.name, runtime.name],
|
|
8280
|
+
sources
|
|
8281
|
+
})));
|
|
8282
|
+
requireThat2([...artifacts, archive, runtime].every((asset) => files.some((file) => file.name === asset.name && file.size === asset.size && file.digest === `sha256:${asset.sha256}`)), "Staged package or update archive does not agree with its bound size and digest");
|
|
8283
|
+
const deb = join33(work, expected.debName);
|
|
8284
|
+
const image = join33(work, expected.appImageName);
|
|
8285
|
+
const version = expected.tag.slice(1);
|
|
8286
|
+
parseDebianIdentity(await inspect("dpkg-deb", ["--field", deb, "Package", "Version", "Architecture"]), expected.debPackage, version);
|
|
8287
|
+
await verifyEmbeddedRuntime(image, await readFile10(join33(work, runtime.name)));
|
|
8288
|
+
const offset = String(runtime.size);
|
|
8289
|
+
requireRegularDesktopEntry(await inspect("unsquashfs", [
|
|
8290
|
+
"-offset",
|
|
8291
|
+
offset,
|
|
8292
|
+
"-lln",
|
|
8293
|
+
"-no-wildcards",
|
|
8294
|
+
image,
|
|
8295
|
+
expected.desktopId
|
|
8296
|
+
]), expected.desktopId);
|
|
8297
|
+
requireDesktopIdentity(await inspect("unsquashfs", [
|
|
8298
|
+
"-offset",
|
|
8299
|
+
offset,
|
|
8300
|
+
"-cat",
|
|
8301
|
+
"-no-wildcards",
|
|
8302
|
+
image,
|
|
8303
|
+
expected.desktopId
|
|
8304
|
+
]), expected.desktopName, version);
|
|
8305
|
+
await chmod3(image, 493);
|
|
8306
|
+
const staged = {
|
|
8307
|
+
schema: "linux-package-pair/v1",
|
|
8308
|
+
tag: expected.tag,
|
|
8309
|
+
sourceSha: expected.sourceSha,
|
|
8310
|
+
platform: "linux-x64",
|
|
8311
|
+
updateArchiveSha256: archive.sha256,
|
|
8312
|
+
artifacts: names.map((name) => artifacts.find((file) => file.name === name))
|
|
8313
|
+
};
|
|
8314
|
+
await mkdir11(destination);
|
|
8315
|
+
try {
|
|
8316
|
+
for (const name of names)
|
|
8317
|
+
await link(join33(work, name), join33(destination, name));
|
|
8318
|
+
await writeFile11(join33(destination, "linux-package-pair.json"), JSON.stringify(staged) + `
|
|
8319
|
+
`, {
|
|
8320
|
+
flag: "wx"
|
|
8321
|
+
});
|
|
8322
|
+
} catch (error) {
|
|
8323
|
+
await rm10(destination, { recursive: true, force: true });
|
|
8324
|
+
throw error;
|
|
8325
|
+
}
|
|
8326
|
+
return staged;
|
|
8327
|
+
} finally {
|
|
8328
|
+
await rm10(work, { recursive: true, force: true });
|
|
8329
|
+
}
|
|
8330
|
+
}
|
|
8331
|
+
var stageLinuxPackagePair = (options) => stageLinuxPackagePairWithInspection(options, inspectWithNativeTools);
|
|
8131
8332
|
export {
|
|
8132
8333
|
createDailyNativeReceipt,
|
|
8133
8334
|
createGitHubPromotionProvider,
|
|
@@ -8152,6 +8353,7 @@ export {
|
|
|
8152
8353
|
selectRetainedStep,
|
|
8153
8354
|
signReleaseArtifact,
|
|
8154
8355
|
stageBuildStep,
|
|
8356
|
+
stageLinuxPackagePair,
|
|
8155
8357
|
stagePlatformArtifacts,
|
|
8156
8358
|
stageReleaseDescriptors,
|
|
8157
8359
|
verifyDailyReleaseMatrix,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.4.0","commit":"036b5b3e268cad30543e62668b82ca46287d761d"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adea-ai/app-framework-release-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Host-side release tooling for @adea-ai/app-framework apps, on Effect: the release CLIs and the framework package publish. Installing it never adds Effect to the framework itself.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|