From 74e5feac3240ac7f04df293259fbb4c40843c3e4 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 13 Sep 2025 22:29:34 -0500 Subject: [PATCH] update --- src/api.js | 110 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 81 insertions(+), 29 deletions(-) diff --git a/src/api.js b/src/api.js index 17243da..544db40 100644 --- a/src/api.js +++ b/src/api.js @@ -61,6 +61,7 @@ const getBucketFiles = async (folderName) => { const contents = Array.isArray(data?.Contents) ? data.Contents : []; + // Normalize + sort newest first (for retention + build ordering) const ret = contents .filter((obj) => obj.Key !== folderKey) .map((obj) => { @@ -84,20 +85,19 @@ const getBucketFiles = async (folderName) => { key: obj.Key || "", }; }) - // sort just to have deterministic selection for nightly, output order will be manual .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 tars = ret.filter((it) => it.name.endsWith(ext)); - // Nightly retention: keep newest 3 per (product_platform_arch) + // Choose base tars; retention (nightly) still per product_platform_arch + const tars = ret.filter((it) => it.name.endsWith(ext)); 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,7 +108,7 @@ const getBucketFiles = async (folderName) => { if (!oldItems.includes(t.key)) { oldItems.push(t.key, t.key + ".sha256", t.key + ".sig"); } - // mark companions old (if they exist) + // mark companions old if present if (parts[3] === "windows") { const setupKey = t.key.substring(0, t.key.length - ext.length) + "_setup.exe"; @@ -129,35 +129,86 @@ const getBucketFiles = async (folderName) => { } } - // Build output strictly in order: DMG group -> SETUP group -> TAR group per (0..4) tuple - const out = []; + // Build -> { maxSort, byPlatArch: Map("platform|arch" -> tarItem) } + const builds = new Map(); + 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 base = t.key.substring(0, t.key.length - ext.length); - const dmgKey = base + ".dmg"; - const setupKey = base + "_setup.exe"; - - // 1) dmg + sidecars - 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"]); + if (!builds.has(buildId)) { + builds.set(buildId, { maxSort: t.sort, byPlatArch: 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 + } - // 2) setup + sidecars - 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"]); + // Order builds by newest + 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; + + 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 + }); + + // 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); + + // 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"]); + } + } + + // 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"]); + } + } + + // 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.gz + sidecars - out.push(t); - if (byKey[t.key + ".sha256"]) out.push(byKey[t.key + ".sha256"]); - if (byKey[t.key + ".sig"]) out.push(byKey[t.key + ".sig"]); } return out; @@ -166,4 +217,5 @@ const getBucketFiles = async (folderName) => { return []; } }; + export { cleanOldItems, createDownloadLink, getBucketFiles };