@adea-ai/app-framework-release-tools 0.3.0 → 0.5.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 +879 -148
- package/dist/index.js +467 -0
- package/dist/release-tools-source.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var __export = (target, all) => {
|
|
|
17
17
|
// src/index.ts
|
|
18
18
|
var exports_src = {};
|
|
19
19
|
__export(exports_src, {
|
|
20
|
+
buildLinuxFormats: () => buildLinuxFormats,
|
|
20
21
|
createDailyNativeReceipt: () => createDailyNativeReceipt,
|
|
21
22
|
createGitHubPromotionProvider: () => createGitHubPromotionProvider,
|
|
22
23
|
createGitHubReleasePublisher: () => createGitHubReleasePublisher,
|
|
@@ -40,6 +41,7 @@ __export(exports_src, {
|
|
|
40
41
|
selectRetainedStep: () => selectRetainedStep,
|
|
41
42
|
signReleaseArtifact: () => signReleaseArtifact,
|
|
42
43
|
stageBuildStep: () => stageBuildStep,
|
|
44
|
+
stageLinuxPackagePair: () => stageLinuxPackagePair,
|
|
43
45
|
stagePlatformArtifacts: () => stagePlatformArtifacts,
|
|
44
46
|
stageReleaseDescriptors: () => stageReleaseDescriptors,
|
|
45
47
|
verifyDailyReleaseMatrix: () => verifyDailyReleaseMatrix,
|
|
@@ -8128,7 +8130,471 @@ var stageBuildStep = (context, directory, artifacts) => run2(context, stageBuild
|
|
|
8128
8130
|
var inspectStagedStep = (context, directory) => run2(context, inspectStagedStepEffect(context, directory));
|
|
8129
8131
|
var qualifyStep = (context, directory) => run2(context, qualifyStepEffect(context, directory));
|
|
8130
8132
|
var qualifyUpgradeStep = (context, directory, onStage) => run2(context, qualifyUpgradeStepEffect(context, directory, onStage));
|
|
8133
|
+
// src/library/linux-package-pair.ts
|
|
8134
|
+
import { execFile as execFile3 } from "child_process";
|
|
8135
|
+
import {
|
|
8136
|
+
chmod as chmod3,
|
|
8137
|
+
link,
|
|
8138
|
+
mkdir as mkdir11,
|
|
8139
|
+
mkdtemp as mkdtemp10,
|
|
8140
|
+
open as open12,
|
|
8141
|
+
readFile as readFile10,
|
|
8142
|
+
realpath as realpath10,
|
|
8143
|
+
rm as rm10,
|
|
8144
|
+
writeFile as writeFile11
|
|
8145
|
+
} from "fs/promises";
|
|
8146
|
+
import { dirname as dirname14, join as join33, resolve as resolve16 } from "path";
|
|
8147
|
+
import { promisify as promisify2 } from "util";
|
|
8148
|
+
var shasum = /^[a-f0-9]{64}$/;
|
|
8149
|
+
var basename15 = /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/;
|
|
8150
|
+
var validTag = /^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/;
|
|
8151
|
+
var exec = promisify2(execFile3);
|
|
8152
|
+
function requireThat2(condition, message) {
|
|
8153
|
+
if (!condition)
|
|
8154
|
+
throw new Error(message);
|
|
8155
|
+
}
|
|
8156
|
+
function record2(value) {
|
|
8157
|
+
requireThat2(typeof value === "object" && value !== null && !Array.isArray(value), "Invalid producer receipt");
|
|
8158
|
+
return value;
|
|
8159
|
+
}
|
|
8160
|
+
function validIdentity(value) {
|
|
8161
|
+
const { name, size, sha256 } = record2(value);
|
|
8162
|
+
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");
|
|
8163
|
+
return { name, size, sha256 };
|
|
8164
|
+
}
|
|
8165
|
+
var inspectWithNativeTools = async (tool, args) => {
|
|
8166
|
+
try {
|
|
8167
|
+
const { stdout } = await exec(tool, [...args], {
|
|
8168
|
+
encoding: "utf8",
|
|
8169
|
+
maxBuffer: 128 * 1024,
|
|
8170
|
+
timeout: 30000,
|
|
8171
|
+
env: { PATH: process.env.PATH, LC_ALL: "C" }
|
|
8172
|
+
});
|
|
8173
|
+
return stdout;
|
|
8174
|
+
} catch (error) {
|
|
8175
|
+
if (error.code === "ENOENT")
|
|
8176
|
+
throw new Error(`${tool} is required to inspect Linux package candidates`, { cause: error });
|
|
8177
|
+
throw new Error(`${tool} could not inspect Linux package candidate`, { cause: error });
|
|
8178
|
+
}
|
|
8179
|
+
};
|
|
8180
|
+
function parseDebianIdentity(text, packageName, version) {
|
|
8181
|
+
const fields = text.trimEnd().split(/\r?\n/);
|
|
8182
|
+
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");
|
|
8183
|
+
}
|
|
8184
|
+
function requireRegularDesktopEntry(listing, id) {
|
|
8185
|
+
const lines = listing.trimEnd().split(/\r?\n/);
|
|
8186
|
+
const fields = /^[d-][-rwxstST]{9} +\d+\/\d+ +\d+ +\d{4}-\d{2}-\d{2} \d{2}:\d{2} (.+)$/;
|
|
8187
|
+
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");
|
|
8188
|
+
}
|
|
8189
|
+
function requireDesktopIdentity(text, name, version) {
|
|
8190
|
+
let inDesktop = false;
|
|
8191
|
+
let foundGroup = false;
|
|
8192
|
+
const fields = new Map;
|
|
8193
|
+
for (const line of text.split(/\r?\n/)) {
|
|
8194
|
+
if (/^\[.*\]$/.test(line)) {
|
|
8195
|
+
inDesktop = line === "[Desktop Entry]";
|
|
8196
|
+
if (inDesktop) {
|
|
8197
|
+
requireThat2(!foundGroup, "Duplicate AppImage desktop entry");
|
|
8198
|
+
foundGroup = true;
|
|
8199
|
+
}
|
|
8200
|
+
continue;
|
|
8201
|
+
}
|
|
8202
|
+
if (!inDesktop || !line || line.startsWith("#"))
|
|
8203
|
+
continue;
|
|
8204
|
+
const match = /^([^=]+)=(.*)$/.exec(line);
|
|
8205
|
+
requireThat2(match && !fields.has(match[1]), "Malformed or duplicate AppImage desktop fields");
|
|
8206
|
+
fields.set(match[1], match[2]);
|
|
8207
|
+
}
|
|
8208
|
+
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");
|
|
8209
|
+
}
|
|
8210
|
+
function digestWindow(runtime) {
|
|
8211
|
+
const sectionStart = Number(runtime.readBigUInt64LE(40));
|
|
8212
|
+
const sectionSize = runtime.readUInt16LE(58);
|
|
8213
|
+
const count = runtime.readUInt16LE(60);
|
|
8214
|
+
const namesIndex = runtime.readUInt16LE(62);
|
|
8215
|
+
requireThat2(Number.isSafeInteger(sectionStart) && sectionStart >= 64 && sectionSize === 64 && namesIndex < count && sectionStart + count * sectionSize <= runtime.length, "Invalid pinned AppImage runtime ELF section table");
|
|
8216
|
+
const namesHeader = sectionStart + sectionSize * namesIndex;
|
|
8217
|
+
const namesStart = Number(runtime.readBigUInt64LE(namesHeader + 24));
|
|
8218
|
+
const namesSize = Number(runtime.readBigUInt64LE(namesHeader + 32));
|
|
8219
|
+
requireThat2(Number.isSafeInteger(namesStart) && Number.isSafeInteger(namesSize) && namesStart >= 64 && namesStart + namesSize <= runtime.length, "Invalid pinned AppImage runtime ELF section names");
|
|
8220
|
+
const names = runtime.subarray(namesStart, namesStart + namesSize);
|
|
8221
|
+
const matches = [];
|
|
8222
|
+
for (let i = 0;i < count; i++) {
|
|
8223
|
+
const section = sectionStart + sectionSize * i;
|
|
8224
|
+
const nameAt = runtime.readUInt32LE(section);
|
|
8225
|
+
const end = names.indexOf(0, nameAt);
|
|
8226
|
+
if (end < 0 || names.toString("ascii", nameAt, end) !== ".digest_md5")
|
|
8227
|
+
continue;
|
|
8228
|
+
const dataAt = Number(runtime.readBigUInt64LE(section + 24));
|
|
8229
|
+
const dataSize = Number(runtime.readBigUInt64LE(section + 32));
|
|
8230
|
+
requireThat2(Number.isSafeInteger(dataAt) && Number.isSafeInteger(dataSize) && dataAt >= 64 && dataSize >= 16 && dataAt + dataSize <= runtime.length, "Invalid pinned AppImage runtime digest section");
|
|
8231
|
+
matches.push(dataAt);
|
|
8232
|
+
}
|
|
8233
|
+
requireThat2(matches.length === 1, "Expected one pinned AppImage runtime digest section");
|
|
8234
|
+
return matches[0];
|
|
8235
|
+
}
|
|
8236
|
+
function type2X64(bytes) {
|
|
8237
|
+
return bytes.length >= 64 && bytes.toString("hex", 0, 6) === "7f454c460201" && bytes.toString("hex", 8, 11) === "414902" && bytes.readUInt16LE(18) === 62;
|
|
8238
|
+
}
|
|
8239
|
+
async function verifyEmbeddedRuntime(path, runtime) {
|
|
8240
|
+
requireThat2(type2X64(runtime), "Expected a pinned Type 2 x86_64 AppImage runtime");
|
|
8241
|
+
const ignored = digestWindow(runtime);
|
|
8242
|
+
const fd = await open12(path, "r");
|
|
8243
|
+
try {
|
|
8244
|
+
const prefix = Buffer.alloc(runtime.length + 4);
|
|
8245
|
+
let filled = 0;
|
|
8246
|
+
while (filled < prefix.length) {
|
|
8247
|
+
const { bytesRead } = await fd.read(prefix, filled, prefix.length - filled, filled);
|
|
8248
|
+
if (!bytesRead)
|
|
8249
|
+
throw new Error("Incomplete embedded AppImage runtime or SquashFS header");
|
|
8250
|
+
filled += bytesRead;
|
|
8251
|
+
}
|
|
8252
|
+
requireThat2(type2X64(prefix), "Expected a Type 2 x86_64 AppImage");
|
|
8253
|
+
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");
|
|
8254
|
+
requireThat2(prefix.toString("ascii", runtime.length) === "hsqs", "Missing embedded SquashFS at the pinned runtime offset");
|
|
8255
|
+
} finally {
|
|
8256
|
+
await fd.close();
|
|
8257
|
+
}
|
|
8258
|
+
}
|
|
8259
|
+
async function stageLinuxPackagePairWithInspection(options, inspect) {
|
|
8260
|
+
const { expected, sources } = options;
|
|
8261
|
+
const receipt = record2(options.producer);
|
|
8262
|
+
const archive = validIdentity(expected.archive);
|
|
8263
|
+
const runtime = validIdentity(expected.runtime);
|
|
8264
|
+
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");
|
|
8265
|
+
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");
|
|
8266
|
+
const names = [expected.debName, expected.appImageName];
|
|
8267
|
+
const artifacts = receipt.artifacts.map(validIdentity);
|
|
8268
|
+
const trustedArtifacts = expected.artifacts.map(validIdentity);
|
|
8269
|
+
requireThat2(trustedArtifacts.length === 2 && names.every((name) => {
|
|
8270
|
+
const fromProducer = artifacts.find((file) => file.name === name);
|
|
8271
|
+
const trusted = trustedArtifacts.find((file) => file.name === name);
|
|
8272
|
+
return fromProducer && trusted && trusted.size === fromProducer.size && trusted.sha256 === fromProducer.sha256;
|
|
8273
|
+
}), "Package producer receipt must describe exactly the protected DEB and AppImage");
|
|
8274
|
+
const destination = resolve16(options.output);
|
|
8275
|
+
const parent = await realpath10(dirname14(destination));
|
|
8276
|
+
const work = await mkdtemp10(join33(parent, ".linux-package-pair-"));
|
|
8277
|
+
try {
|
|
8278
|
+
const files = await runReleaseLibrary(provideLibraryPorts()(stageExpectedFilesEffect({
|
|
8279
|
+
directory: work,
|
|
8280
|
+
expected: [...names, archive.name, runtime.name],
|
|
8281
|
+
sources
|
|
8282
|
+
})));
|
|
8283
|
+
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");
|
|
8284
|
+
const deb = join33(work, expected.debName);
|
|
8285
|
+
const image = join33(work, expected.appImageName);
|
|
8286
|
+
const version = expected.tag.slice(1);
|
|
8287
|
+
parseDebianIdentity(await inspect("dpkg-deb", ["--field", deb, "Package", "Version", "Architecture"]), expected.debPackage, version);
|
|
8288
|
+
await verifyEmbeddedRuntime(image, await readFile10(join33(work, runtime.name)));
|
|
8289
|
+
const offset = String(runtime.size);
|
|
8290
|
+
requireRegularDesktopEntry(await inspect("unsquashfs", [
|
|
8291
|
+
"-offset",
|
|
8292
|
+
offset,
|
|
8293
|
+
"-lln",
|
|
8294
|
+
"-no-wildcards",
|
|
8295
|
+
image,
|
|
8296
|
+
expected.desktopId
|
|
8297
|
+
]), expected.desktopId);
|
|
8298
|
+
requireDesktopIdentity(await inspect("unsquashfs", [
|
|
8299
|
+
"-offset",
|
|
8300
|
+
offset,
|
|
8301
|
+
"-cat",
|
|
8302
|
+
"-no-wildcards",
|
|
8303
|
+
image,
|
|
8304
|
+
expected.desktopId
|
|
8305
|
+
]), expected.desktopName, version);
|
|
8306
|
+
await chmod3(image, 493);
|
|
8307
|
+
const staged = {
|
|
8308
|
+
schema: "linux-package-pair/v1",
|
|
8309
|
+
tag: expected.tag,
|
|
8310
|
+
sourceSha: expected.sourceSha,
|
|
8311
|
+
platform: "linux-x64",
|
|
8312
|
+
updateArchiveSha256: archive.sha256,
|
|
8313
|
+
artifacts: names.map((name) => artifacts.find((file) => file.name === name))
|
|
8314
|
+
};
|
|
8315
|
+
await mkdir11(destination);
|
|
8316
|
+
try {
|
|
8317
|
+
for (const name of names)
|
|
8318
|
+
await link(join33(work, name), join33(destination, name));
|
|
8319
|
+
await writeFile11(join33(destination, "linux-package-pair.json"), JSON.stringify(staged) + `
|
|
8320
|
+
`, {
|
|
8321
|
+
flag: "wx"
|
|
8322
|
+
});
|
|
8323
|
+
} catch (error) {
|
|
8324
|
+
await rm10(destination, { recursive: true, force: true });
|
|
8325
|
+
throw error;
|
|
8326
|
+
}
|
|
8327
|
+
return staged;
|
|
8328
|
+
} finally {
|
|
8329
|
+
await rm10(work, { recursive: true, force: true });
|
|
8330
|
+
}
|
|
8331
|
+
}
|
|
8332
|
+
var stageLinuxPackagePair = (options) => stageLinuxPackagePairWithInspection(options, inspectWithNativeTools);
|
|
8333
|
+
// src/library/linux-format-producer.ts
|
|
8334
|
+
import { createHash as createHash16 } from "crypto";
|
|
8335
|
+
import { createReadStream, createWriteStream } from "fs";
|
|
8336
|
+
import {
|
|
8337
|
+
chmod as chmod4,
|
|
8338
|
+
cp,
|
|
8339
|
+
lstat as lstat20,
|
|
8340
|
+
lutimes,
|
|
8341
|
+
mkdir as mkdir12,
|
|
8342
|
+
mkdtemp as mkdtemp11,
|
|
8343
|
+
open as open13,
|
|
8344
|
+
readdir as readdir11,
|
|
8345
|
+
readlink as readlink3,
|
|
8346
|
+
realpath as realpath11,
|
|
8347
|
+
rm as rm11,
|
|
8348
|
+
utimes,
|
|
8349
|
+
writeFile as writeFile12
|
|
8350
|
+
} from "fs/promises";
|
|
8351
|
+
import { basename as basename16, dirname as dirname15, isAbsolute as isAbsolute6, join as join34, relative as relative5, resolve as resolve17 } from "path";
|
|
8352
|
+
import { pipeline as pipeline2 } from "stream/promises";
|
|
8353
|
+
var component = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
8354
|
+
var sha256 = /^[a-f0-9]{64}$/;
|
|
8355
|
+
var sum = async (path) => {
|
|
8356
|
+
const hash = createHash16("sha256");
|
|
8357
|
+
for await (const chunk of createReadStream(path))
|
|
8358
|
+
hash.update(chunk);
|
|
8359
|
+
return hash.digest("hex");
|
|
8360
|
+
};
|
|
8361
|
+
var relativeFiles = (value) => value.split("/").every((part) => component.test(part));
|
|
8362
|
+
var text2 = (v) => v.length > 0 && v.length <= 250 && !/[\r\n]/.test(v);
|
|
8363
|
+
function check(ok, message) {
|
|
8364
|
+
if (!ok)
|
|
8365
|
+
throw new Error(message);
|
|
8366
|
+
}
|
|
8367
|
+
async function exactCopy(pin, to) {
|
|
8368
|
+
check(sha256.test(pin.sha256), "Missing protected input digest");
|
|
8369
|
+
const before = await lstat20(pin.path);
|
|
8370
|
+
check(before.isFile() && !before.isSymbolicLink() && before.size > 0, "Expected a regular pinned input");
|
|
8371
|
+
const input = await open13(pin.path, "r");
|
|
8372
|
+
try {
|
|
8373
|
+
const after = await input.stat();
|
|
8374
|
+
check(after.dev === before.dev && after.ino === before.ino && after.size === before.size, "Pinned input changed");
|
|
8375
|
+
await pipeline2(input.createReadStream({ autoClose: false, start: 0, end: before.size - 1 }), createWriteStream(to, { flags: "wx", mode: 384 }));
|
|
8376
|
+
} finally {
|
|
8377
|
+
await input.close();
|
|
8378
|
+
}
|
|
8379
|
+
check((await lstat20(to)).size === before.size && await sum(to) === pin.sha256, "Pinned input digest mismatch");
|
|
8380
|
+
}
|
|
8381
|
+
async function regular(root, path) {
|
|
8382
|
+
const file = join34(root, path);
|
|
8383
|
+
check((await lstat20(file)).isFile() && await realpath11(file) === file, "Required bundle member is not a regular file");
|
|
8384
|
+
return file;
|
|
8385
|
+
}
|
|
8386
|
+
async function elf(path, appImage = false) {
|
|
8387
|
+
const input = await open13(path, "r");
|
|
8388
|
+
try {
|
|
8389
|
+
const h = Buffer.alloc(20);
|
|
8390
|
+
const { bytesRead } = await input.read(h, 0, h.length, 0);
|
|
8391
|
+
check(bytesRead === 20 && h.toString("hex", 0, 6) === "7f454c460201" && h.readUInt16LE(18) === 62 && (!appImage || h.toString("hex", 8, 11) === "414902"), "Expected native Linux x64 executable");
|
|
8392
|
+
} finally {
|
|
8393
|
+
await input.close();
|
|
8394
|
+
}
|
|
8395
|
+
}
|
|
8396
|
+
async function normalizeTree(root, dir = root) {
|
|
8397
|
+
for (const name of await readdir11(dir)) {
|
|
8398
|
+
const file = join34(dir, name);
|
|
8399
|
+
const st = await lstat20(file);
|
|
8400
|
+
if (st.isSymbolicLink()) {
|
|
8401
|
+
check(!isAbsolute6(await readlink3(file)), "Absolute bundle symlink");
|
|
8402
|
+
const target = relative5(root, await realpath11(file));
|
|
8403
|
+
check(target !== ".." && !target.startsWith("../") && !isAbsolute6(target), "Escaping bundle symlink");
|
|
8404
|
+
} else if (st.isDirectory()) {
|
|
8405
|
+
await chmod4(file, 493);
|
|
8406
|
+
await normalizeTree(root, file);
|
|
8407
|
+
} else {
|
|
8408
|
+
check(st.isFile(), "Unsupported bundle entry");
|
|
8409
|
+
await chmod4(file, st.mode & 73 ? 493 : 420);
|
|
8410
|
+
}
|
|
8411
|
+
}
|
|
8412
|
+
}
|
|
8413
|
+
async function normalizeBuildTimes(directory, epoch) {
|
|
8414
|
+
for (const name of (await readdir11(directory)).toSorted()) {
|
|
8415
|
+
const path = join34(directory, name);
|
|
8416
|
+
const info = await lstat20(path);
|
|
8417
|
+
if (info.isSymbolicLink()) {
|
|
8418
|
+
await lutimes(path, epoch, epoch);
|
|
8419
|
+
} else if (info.isDirectory()) {
|
|
8420
|
+
await normalizeBuildTimes(path, epoch);
|
|
8421
|
+
} else {
|
|
8422
|
+
check(info.isFile(), "Unsupported packaging entry");
|
|
8423
|
+
await utimes(path, epoch, epoch);
|
|
8424
|
+
}
|
|
8425
|
+
}
|
|
8426
|
+
await chmod4(directory, 493);
|
|
8427
|
+
await utimes(directory, epoch, epoch);
|
|
8428
|
+
}
|
|
8429
|
+
async function write(root, path, value, mode = 420) {
|
|
8430
|
+
const target = join34(root, path);
|
|
8431
|
+
await mkdir12(dirname15(target), { recursive: true });
|
|
8432
|
+
await writeFile12(target, value, { flag: "wx", mode });
|
|
8433
|
+
await chmod4(target, mode);
|
|
8434
|
+
}
|
|
8435
|
+
function validatePolicy(policy) {
|
|
8436
|
+
check([policy.bundleRoot, policy.artifactStem, policy.desktopId].every((n) => component.test(n)) && /^[a-z0-9][a-z0-9+.-]+$/.test(policy.packageName) && [policy.launcher, policy.icon, ...policy.debSetuid.map((item) => item.path)].every(relativeFiles) && policy.debSetuid.every((item) => sha256.test(item.sha256)) && new Set(policy.debSetuid.map((item) => item.path)).size === policy.debSetuid.length && /^[A-Z][A-Z0-9_]*_LINUX_PACKAGE_FORMAT$/.test(policy.formatEnvironment) && policy.mimeTypes.every((x) => /^x-scheme-handler\/[a-z][a-z0-9+.-]*$/.test(x)) && [policy.name, policy.description, policy.maintainer, policy.homepage].every(text2) && policy.categories.every((x) => /^[A-Za-z0-9]+$/.test(x)) && policy.dependencies.every((x) => /^[a-z0-9][a-z0-9+.-]*(?: \| [a-z0-9][a-z0-9+.-]*)*$/.test(x)), "Invalid app Linux packaging policy");
|
|
8437
|
+
check(new URL(policy.homepage).protocol === "https:", "Expected HTTPS homepage");
|
|
8438
|
+
}
|
|
8439
|
+
async function buildLinuxFormats(input, host) {
|
|
8440
|
+
const { tag, sourceSha, expectedSourceSha, sourceDateEpoch, policy } = input;
|
|
8441
|
+
check(host.os === "linux" && host.arch === "x64", "Requires native Linux x64");
|
|
8442
|
+
check(/^v(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(tag) && /^[a-f0-9]{40}$/.test(sourceSha) && sourceSha === expectedSourceSha, "Wrong protected build source or tag");
|
|
8443
|
+
check(Number.isSafeInteger(sourceDateEpoch) && sourceDateEpoch > 0 && sourceDateEpoch <= 4294967295, "Expected valid protected SOURCE_DATE_EPOCH");
|
|
8444
|
+
const env = { SOURCE_DATE_EPOCH: String(sourceDateEpoch), LC_ALL: "C", TZ: "UTC" };
|
|
8445
|
+
validatePolicy(policy);
|
|
8446
|
+
const requested = resolve17(input.output);
|
|
8447
|
+
const parent = await realpath11(dirname15(requested));
|
|
8448
|
+
const output = join34(parent, basename16(requested));
|
|
8449
|
+
const work = await mkdtemp11(join34(parent, ".linux-formats-"));
|
|
8450
|
+
try {
|
|
8451
|
+
const archive = join34(work, "payload.tar.zst");
|
|
8452
|
+
const tool = join34(work, "appimagetool");
|
|
8453
|
+
const runtime = join34(work, "runtime");
|
|
8454
|
+
for (const [pin, dest] of [
|
|
8455
|
+
[input.archive, archive],
|
|
8456
|
+
[input.tool, tool],
|
|
8457
|
+
[input.runtime, runtime]
|
|
8458
|
+
])
|
|
8459
|
+
await exactCopy(pin, dest);
|
|
8460
|
+
await elf(tool, true);
|
|
8461
|
+
await elf(runtime, true);
|
|
8462
|
+
await host.inspectAppArchive(archive);
|
|
8463
|
+
check((await lstat20(archive)).isFile() && await sum(archive) === input.archive.sha256, "Payload changed during app inspection");
|
|
8464
|
+
await chmod4(tool, 448);
|
|
8465
|
+
const extracted = join34(work, "extract");
|
|
8466
|
+
await mkdir12(extracted);
|
|
8467
|
+
await host.run("tar", [
|
|
8468
|
+
"--zstd",
|
|
8469
|
+
"--extract",
|
|
8470
|
+
"--file",
|
|
8471
|
+
archive,
|
|
8472
|
+
"--directory",
|
|
8473
|
+
extracted,
|
|
8474
|
+
"--no-same-owner",
|
|
8475
|
+
"--no-same-permissions"
|
|
8476
|
+
], { env });
|
|
8477
|
+
const source = join34(extracted, policy.bundleRoot);
|
|
8478
|
+
check((await lstat20(source)).isDirectory() && await realpath11(source) === source, "Wrong extracted app root");
|
|
8479
|
+
await chmod4(source, 493);
|
|
8480
|
+
await normalizeTree(source);
|
|
8481
|
+
await elf(await regular(source, policy.launcher));
|
|
8482
|
+
for (const pin of policy.debSetuid) {
|
|
8483
|
+
const file = await regular(source, pin.path);
|
|
8484
|
+
await elf(file);
|
|
8485
|
+
check(await sum(file) === pin.sha256, "DEB setuid helper differs from trusted pin");
|
|
8486
|
+
}
|
|
8487
|
+
const icon = await regular(source, policy.icon);
|
|
8488
|
+
check(policy.icon.endsWith(".svg"), "Expected an SVG application icon");
|
|
8489
|
+
const stem = `${policy.artifactStem}-${tag}-linux-x64`;
|
|
8490
|
+
const debName = `${stem}.deb`;
|
|
8491
|
+
const imageName = `${stem}.AppImage`;
|
|
8492
|
+
const dest = join34(work, "result");
|
|
8493
|
+
await mkdir12(dest);
|
|
8494
|
+
const version = tag.slice(1);
|
|
8495
|
+
const installed = `usr/lib/${policy.packageName}`;
|
|
8496
|
+
const desktopFile = `${policy.desktopId}.desktop`;
|
|
8497
|
+
const desktop = [
|
|
8498
|
+
"[Desktop Entry]",
|
|
8499
|
+
"Type=Application",
|
|
8500
|
+
`Name=${policy.name}`,
|
|
8501
|
+
`Comment=${policy.description}`,
|
|
8502
|
+
`Exec=${policy.packageName} %U`,
|
|
8503
|
+
`Icon=${policy.desktopId}`,
|
|
8504
|
+
`Categories=${policy.categories.join(";")};`,
|
|
8505
|
+
...policy.mimeTypes.length ? [`MimeType=${policy.mimeTypes.join(";")};`] : [],
|
|
8506
|
+
"Terminal=false",
|
|
8507
|
+
""
|
|
8508
|
+
].join(`
|
|
8509
|
+
`);
|
|
8510
|
+
for (const format of ["deb", "appimage"]) {
|
|
8511
|
+
const tree = join34(work, format);
|
|
8512
|
+
await mkdir12(join34(tree, "usr", "lib"), { recursive: true });
|
|
8513
|
+
const bundle = join34(tree, installed);
|
|
8514
|
+
await cp(source, bundle, { recursive: true, verbatimSymlinks: true });
|
|
8515
|
+
await normalizeTree(bundle);
|
|
8516
|
+
await write(tree, `usr/share/applications/${desktopFile}`, desktop);
|
|
8517
|
+
const iconDest = join34(tree, `usr/share/icons/hicolor/scalable/apps/${policy.desktopId}.svg`);
|
|
8518
|
+
await mkdir12(dirname15(iconDest), { recursive: true });
|
|
8519
|
+
await cp(icon, iconDest, { force: false, errorOnExist: true });
|
|
8520
|
+
await chmod4(iconDest, 420);
|
|
8521
|
+
if (format === "deb") {
|
|
8522
|
+
for (const pin of policy.debSetuid)
|
|
8523
|
+
await chmod4(await regular(bundle, pin.path), 2541);
|
|
8524
|
+
await write(tree, `usr/bin/${policy.packageName}`, `#!/bin/sh
|
|
8525
|
+
export ${policy.formatEnvironment}=deb
|
|
8526
|
+
exec '/${installed}/${policy.launcher}' "$@"
|
|
8527
|
+
`, 493);
|
|
8528
|
+
await write(tree, "DEBIAN/control", [
|
|
8529
|
+
`Package: ${policy.packageName}`,
|
|
8530
|
+
`Version: ${version}`,
|
|
8531
|
+
"Architecture: amd64",
|
|
8532
|
+
`Maintainer: ${policy.maintainer}`,
|
|
8533
|
+
`Description: ${policy.description}`,
|
|
8534
|
+
`Homepage: ${policy.homepage}`,
|
|
8535
|
+
...policy.dependencies.length ? [`Depends: ${policy.dependencies.join(", ")}`] : [],
|
|
8536
|
+
""
|
|
8537
|
+
].join(`
|
|
8538
|
+
`));
|
|
8539
|
+
await normalizeBuildTimes(tree, sourceDateEpoch);
|
|
8540
|
+
await host.run("dpkg-deb", ["--root-owner-group", "--threads-max=1", "-Zxz", "--build", tree, join34(dest, debName)], { env });
|
|
8541
|
+
} else {
|
|
8542
|
+
const rootIcon = join34(tree, `${policy.desktopId}.svg`);
|
|
8543
|
+
await cp(icon, rootIcon, { force: false, errorOnExist: true });
|
|
8544
|
+
await chmod4(rootIcon, 420);
|
|
8545
|
+
await write(tree, desktopFile, desktop);
|
|
8546
|
+
await write(tree, "AppRun", [
|
|
8547
|
+
"#!/bin/sh",
|
|
8548
|
+
"set -eu",
|
|
8549
|
+
'root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)',
|
|
8550
|
+
`export ${policy.formatEnvironment}=appimage`,
|
|
8551
|
+
`exec "$root/${installed}/${policy.launcher}" "$@"`,
|
|
8552
|
+
""
|
|
8553
|
+
].join(`
|
|
8554
|
+
`), 493);
|
|
8555
|
+
await normalizeBuildTimes(tree, sourceDateEpoch);
|
|
8556
|
+
await host.run("appimagetool", ["--no-appstream", "--runtime-file", runtime, tree, join34(dest, imageName)], {
|
|
8557
|
+
executable: tool,
|
|
8558
|
+
env: { ...env, ARCH: "x86_64", VERSION: version, APPIMAGE_EXTRACT_AND_RUN: "1" }
|
|
8559
|
+
});
|
|
8560
|
+
}
|
|
8561
|
+
}
|
|
8562
|
+
const artifacts = [];
|
|
8563
|
+
for (const name of [debName, imageName]) {
|
|
8564
|
+
const path = await regular(dest, name);
|
|
8565
|
+
const size = (await lstat20(path)).size;
|
|
8566
|
+
check(size > 0, "Empty produced artifact");
|
|
8567
|
+
artifacts.push({ name, size, sha256: await sum(path) });
|
|
8568
|
+
}
|
|
8569
|
+
const receipt = {
|
|
8570
|
+
schema: "linux-package-formats/v1",
|
|
8571
|
+
tag,
|
|
8572
|
+
sourceSha,
|
|
8573
|
+
sourceDateEpoch,
|
|
8574
|
+
platform: "linux-x64",
|
|
8575
|
+
updateArchiveSha256: input.archive.sha256,
|
|
8576
|
+
artifacts
|
|
8577
|
+
};
|
|
8578
|
+
await mkdir12(output);
|
|
8579
|
+
try {
|
|
8580
|
+
for (const item of artifacts)
|
|
8581
|
+
await cp(join34(dest, item.name), join34(output, basename16(item.name)), {
|
|
8582
|
+
force: false,
|
|
8583
|
+
errorOnExist: true
|
|
8584
|
+
});
|
|
8585
|
+
await write(output, "linux-format-build.json", JSON.stringify(receipt) + `
|
|
8586
|
+
`);
|
|
8587
|
+
} catch (error) {
|
|
8588
|
+
await rm11(output, { recursive: true, force: true });
|
|
8589
|
+
throw error;
|
|
8590
|
+
}
|
|
8591
|
+
return receipt;
|
|
8592
|
+
} finally {
|
|
8593
|
+
await rm11(work, { recursive: true, force: true });
|
|
8594
|
+
}
|
|
8595
|
+
}
|
|
8131
8596
|
export {
|
|
8597
|
+
buildLinuxFormats,
|
|
8132
8598
|
createDailyNativeReceipt,
|
|
8133
8599
|
createGitHubPromotionProvider,
|
|
8134
8600
|
createGitHubReleasePublisher,
|
|
@@ -8152,6 +8618,7 @@ export {
|
|
|
8152
8618
|
selectRetainedStep,
|
|
8153
8619
|
signReleaseArtifact,
|
|
8154
8620
|
stageBuildStep,
|
|
8621
|
+
stageLinuxPackagePair,
|
|
8155
8622
|
stagePlatformArtifacts,
|
|
8156
8623
|
stageReleaseDescriptors,
|
|
8157
8624
|
verifyDailyReleaseMatrix,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.5.0","commit":"4fd311cbc06e856436d905add755438537fb53dd"}
|
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.5.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": {
|