This commit is contained in:
2025-09-13 22:23:10 -05:00
parent 73d39c110a
commit 1fb68ba318

View File

@@ -89,14 +89,13 @@ const getBucketFiles = async (folderName) => {
const itemCount = {};
const ext = ".tar.gz";
// pick tars to keep (apply nightly policy)
// choose base tars
const tars = ret.filter((it) => it.name.endsWith(ext));
const keepTarKeys = new Set();
for (const t of tars) {
if (folderName === "nightly") {
const parts = t.name.split("_");
// parts[0]=product, parts[3]=platform, parts[4]=arch
const parts = t.name.split("_"); // 0=product,1=ver,2=build,3=platform,4=arch
const groupId = `${parts[0]}_${parts[3]}_${parts[4]}`;
itemCount[groupId] = itemCount[groupId] || 0;
@@ -107,23 +106,25 @@ const getBucketFiles = async (folderName) => {
if (!oldItems.includes(t.key)) {
oldItems.push(t.key, t.key + ".sha256", t.key + ".sig");
}
// windows companion (_setup.exe) + sidecars
// windows companion
if (parts[3] === "windows") {
const setupKey =
t.key.substring(0, t.key.length - ext.length) + "_setup.exe";
const setupItem = ret.find((x) => x.key === setupKey);
if (setupItem && !oldItems.includes(setupKey)) {
if (
ret.find((x) => x.key === setupKey) &&
!oldItems.includes(setupKey)
) {
oldItems.push(setupKey, setupKey + ".sha256", setupKey + ".sig");
}
}
// darwin companion (.dmg) + sidecars
// darwin companion
if (parts[3] === "darwin") {
const dmgKey =
t.key.substring(0, t.key.length - ext.length) + ".dmg";
const dmgItem = ret.find((x) => x.key === dmgKey);
if (dmgItem && !oldItems.includes(dmgKey)) {
if (
ret.find((x) => x.key === dmgKey) &&
!oldItems.includes(dmgKey)
) {
oldItems.push(dmgKey, dmgKey + ".sha256", dmgKey + ".sig");
}
}
@@ -133,48 +134,83 @@ const getBucketFiles = async (folderName) => {
}
}
// fast lookup
const byKey = Object.fromEntries(ret.map((r) => [r.key, r]));
// build final list by pushing (no in-place splicing)
const out = [];
// ---- NEW: group kept tars by build, sort builds by newest, and sort within each build by platform/arch
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;
// map buildId -> {maxSort, items:[tar]}
const builds = new Map();
for (const t of tars) {
if (!keepTarKeys.has(t.key)) continue;
const parts = t.name.split("_");
const platform = parts[3];
const buildId = parts[2] || "";
const platform = (parts[3] || "").toLowerCase();
const arch = parts[4] || "";
// 1) tar + sidecars
out.push(t);
const tarSha = byKey[t.key + ".sha256"];
if (tarSha) out.push(tarSha);
const tarSig = byKey[t.key + ".sig"];
if (tarSig) out.push(tarSig);
if (!builds.has(buildId))
builds.set(buildId, { maxSort: t.sort, items: [] });
const b = builds.get(buildId);
b.maxSort = Math.max(b.maxSort, t.sort);
b.items.push({ t, platform, arch });
}
// 2) windows setup + sidecars
if (platform === "windows") {
const setupKey =
t.key.substring(0, t.key.length - ext.length) + "_setup.exe";
const setup = byKey[setupKey];
if (setup) {
out.push(setup);
const setupSha = byKey[setupKey + ".sha256"];
if (setupSha) out.push(setupSha);
const setupSig = byKey[setupKey + ".sig"];
if (setupSig) out.push(setupSig);
const buildList = Array.from(builds.entries()).sort(
(a, b) => b[1].maxSort - a[1].maxSort,
);
const out = [];
for (const [, bucket] of buildList) {
// stable within-build order: platform → arch, then by tar time desc
bucket.items.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.t.sort - a.t.sort;
});
for (const { t, platform } of bucket.items) {
// 1) tar + sidecars
out.push(t);
const tarSha = byKey[t.key + ".sha256"];
if (tarSha) out.push(tarSha);
const tarSig = byKey[t.key + ".sig"];
if (tarSig) out.push(tarSig);
// 2) windows setup + sidecars
if (platform === "windows") {
const setupKey =
t.key.substring(0, t.key.length - ext.length) + "_setup.exe";
const setup = byKey[setupKey];
if (setup) {
out.push(setup);
const setupSha = byKey[setupKey + ".sha256"];
if (setupSha) out.push(setupSha);
const setupSig = byKey[setupKey + ".sig"];
if (setupSig) out.push(setupSig);
}
}
}
// 3) darwin dmg + sidecars
if (platform === "darwin") {
const dmgKey = t.key.substring(0, t.key.length - ext.length) + ".dmg";
const dmg = byKey[dmgKey];
if (dmg) {
out.push(dmg);
const dmgSha = byKey[dmgKey + ".sha256"];
if (dmgSha) out.push(dmgSha);
const dmgSig = byKey[dmgKey + ".sig"];
if (dmgSig) out.push(dmgSig);
// 3) darwin dmg + sidecars
if (platform === "darwin") {
const dmgKey = t.key.substring(0, t.key.length - ext.length) + ".dmg";
const dmg = byKey[dmgKey];
if (dmg) {
out.push(dmg);
const dmgSha = byKey[dmgKey + ".sha256"];
if (dmgSha) out.push(dmgSha);
const dmgSig = byKey[dmgKey + ".sig"];
if (dmgSig) out.push(dmgSig);
}
}
}
}