This commit is contained in:
2025-09-13 22:31:20 -05:00
parent 74e5feac32
commit fc9a79e833

View File

@@ -61,7 +61,7 @@ const getBucketFiles = async (folderName) => {
const contents = Array.isArray(data?.Contents) ? data.Contents : [];
// Normalize + sort newest first (for retention + build ordering)
// Normalize + newest-first
const ret = contents
.filter((obj) => obj.Key !== folderKey)
.map((obj) => {
@@ -88,16 +88,16 @@ const getBucketFiles = async (folderName) => {
.sort((a, b) => (a.sort > b.sort ? -1 : a.sort < b.sort ? 1 : 0));
const byKey = Object.fromEntries(ret.map((r) => [r.key, r]));
const ext = ".tar.gz";
const TAR = ".tar.gz";
// Choose base tars; retention (nightly) still per product_platform_arch
const tars = ret.filter((it) => it.name.endsWith(ext));
// Keep only tar anchors (apply nightly retention)
const tars = ret.filter((it) => it.name.endsWith(TAR));
const keepTarKeys = new Set();
const itemCount = {};
for (const t of tars) {
if (folderName === "nightly") {
const parts = t.name.split("_"); // 0=product 1=version 2=build 3=platform 4=arch
const parts = t.name.split("_"); // 0=product,1=version,2=build,3=platform,4=arch
const groupId = `${parts[0]}_${parts[3]}_${parts[4]}`;
itemCount[groupId] = itemCount[groupId] || 0;
@@ -108,17 +108,15 @@ const getBucketFiles = async (folderName) => {
if (!oldItems.includes(t.key)) {
oldItems.push(t.key, t.key + ".sha256", t.key + ".sig");
}
// mark companions old if present
// companions old
if (parts[3] === "windows") {
const setupKey =
t.key.substring(0, t.key.length - ext.length) + "_setup.exe";
const setupKey = t.key.slice(0, -TAR.length) + "_setup.exe";
if (byKey[setupKey] && !oldItems.includes(setupKey)) {
oldItems.push(setupKey, setupKey + ".sha256", setupKey + ".sig");
}
}
if (parts[3] === "darwin") {
const dmgKey =
t.key.substring(0, t.key.length - ext.length) + ".dmg";
const dmgKey = t.key.slice(0, -TAR.length) + ".dmg";
if (byKey[dmgKey] && !oldItems.includes(dmgKey)) {
oldItems.push(dmgKey, dmgKey + ".sha256", dmgKey + ".sig");
}
@@ -129,85 +127,71 @@ const getBucketFiles = async (folderName) => {
}
}
// Build -> { maxSort, byPlatArch: Map("platform|arch" -> tarItem) }
const builds = new Map();
// Build -> platform/arch -> tar
const builds = new Map(); // buildId -> { maxSort, map: Map("platform|arch" -> tarItem) }
for (const t of tars) {
if (!keepTarKeys.has(t.key)) continue;
const parts = t.name.split("_");
const buildId = `${parts[0]}|${parts[1]}|${parts[2]}`; // group by 0,1,2
const platArch = `${(parts[3] || "").toLowerCase()}|${parts[4] || ""}`; // then 3,4
const buildId = `${parts[0]}|${parts[1]}|${parts[2]}`; // parts 0..2
const platform = (parts[3] || "").toLowerCase();
const arch = (parts[4] || "").toLowerCase();
const platArch = `${platform}|${arch}`;
if (!builds.has(buildId)) {
builds.set(buildId, { maxSort: t.sort, byPlatArch: new Map() });
}
if (!builds.has(buildId))
builds.set(buildId, { maxSort: t.sort, map: new Map() });
const bucket = builds.get(buildId);
bucket.maxSort = Math.max(bucket.maxSort, t.sort);
bucket.byPlatArch.set(platArch, t); // 1 tar per plat/arch tuple
bucket.map.set(platArch, t);
}
// Order builds by newest
// Sort builds newest-first
const orderedBuilds = Array.from(builds.entries()).sort(
(a, b) => b[1].maxSort - a[1].maxSort,
);
// Inside a build, order platform/arch consistently
const platformRank = (p) =>
p === "darwin" ? 0 : p === "windows" ? 1 : p === "linux" ? 2 : 3;
const archRank = (a) =>
a === "aarch64" || a === "arm64"
? 0
: a === "x86-64" || a === "x86_64"
? 1
: 2;
// Explicit platform/arch order
const platformOrder = ["darwin", "windows", "linux"];
const archOrder = ["aarch64", "arm64", "x86-64", "x86_64"];
const out = [];
for (const [, bucket] of orderedBuilds) {
const groups = Array.from(bucket.byPlatArch.entries())
.map(([k, tar]) => {
const [platform, arch] = k.split("|");
return { platform, arch, tar };
})
.sort((a, b) => {
const pr = platformRank(a.platform) - platformRank(b.platform);
if (pr !== 0) return pr;
const ar = archRank(a.arch) - archRank(b.arch);
if (ar !== 0) return ar;
return b.tar.sort - a.tar.sort; // stable fallback
});
for (const p of platformOrder) {
for (const a of archOrder) {
const keyPA = `${p}|${a}`;
const tar = bucket.map.get(keyPA);
if (!tar) continue;
// Emit each platform/arch group in order: dmg -> setup -> tar (each with sidecars)
for (const { platform, tar } of groups) {
const base = tar.key.substring(0, tar.key.length - ext.length);
const base = tar.key.slice(0, -TAR.length);
// 1) DMG (darwin only)
if (platform === "darwin") {
const dmgKey = base + ".dmg";
const dmg = byKey[dmgKey];
if (dmg) {
out.push(dmg);
if (byKey[dmgKey + ".sha256"]) out.push(byKey[dmgKey + ".sha256"]);
if (byKey[dmgKey + ".sig"]) out.push(byKey[dmgKey + ".sig"]);
// 1) DMG group (darwin only)
if (p === "darwin") {
const dmgKey = base + ".dmg";
const dmg = byKey[dmgKey];
if (dmg) {
out.push(dmg);
if (byKey[dmgKey + ".sha256"])
out.push(byKey[dmgKey + ".sha256"]);
if (byKey[dmgKey + ".sig"]) out.push(byKey[dmgKey + ".sig"]);
}
}
}
// 2) SETUP (windows only)
if (platform === "windows") {
const setupKey = base + "_setup.exe";
const setup = byKey[setupKey];
if (setup) {
out.push(setup);
if (byKey[setupKey + ".sha256"])
out.push(byKey[setupKey + ".sha256"]);
if (byKey[setupKey + ".sig"]) out.push(byKey[setupKey + ".sig"]);
// 2) SETUP group (windows only)
if (p === "windows") {
const setupKey = base + "_setup.exe";
const setup = byKey[setupKey];
if (setup) {
out.push(setup);
if (byKey[setupKey + ".sha256"])
out.push(byKey[setupKey + ".sha256"]);
if (byKey[setupKey + ".sig"]) out.push(byKey[setupKey + ".sig"]);
}
}
}
// 3) TAR (always)
out.push(tar);
if (byKey[tar.key + ".sha256"]) out.push(byKey[tar.key + ".sha256"]);
if (byKey[tar.key + ".sig"]) out.push(byKey[tar.key + ".sig"]);
// 3) TAR group (always)
out.push(tar);
if (byKey[tar.key + ".sha256"]) out.push(byKey[tar.key + ".sha256"]);
if (byKey[tar.key + ".sig"]) out.push(byKey[tar.key + ".sig"]);
}
}
}