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 itemCount = {};
const ext = ".tar.gz"; const ext = ".tar.gz";
// pick tars to keep (apply nightly policy) // choose base tars
const tars = ret.filter((it) => it.name.endsWith(ext)); const tars = ret.filter((it) => it.name.endsWith(ext));
const keepTarKeys = new Set(); const keepTarKeys = new Set();
for (const t of tars) { for (const t of tars) {
if (folderName === "nightly") { if (folderName === "nightly") {
const parts = t.name.split("_"); const parts = t.name.split("_"); // 0=product,1=ver,2=build,3=platform,4=arch
// parts[0]=product, parts[3]=platform, parts[4]=arch
const groupId = `${parts[0]}_${parts[3]}_${parts[4]}`; const groupId = `${parts[0]}_${parts[3]}_${parts[4]}`;
itemCount[groupId] = itemCount[groupId] || 0; itemCount[groupId] = itemCount[groupId] || 0;
@@ -107,23 +106,25 @@ const getBucketFiles = async (folderName) => {
if (!oldItems.includes(t.key)) { if (!oldItems.includes(t.key)) {
oldItems.push(t.key, t.key + ".sha256", t.key + ".sig"); oldItems.push(t.key, t.key + ".sha256", t.key + ".sig");
} }
// windows companion
// windows companion (_setup.exe) + sidecars
if (parts[3] === "windows") { if (parts[3] === "windows") {
const setupKey = const setupKey =
t.key.substring(0, t.key.length - ext.length) + "_setup.exe"; t.key.substring(0, t.key.length - ext.length) + "_setup.exe";
const setupItem = ret.find((x) => x.key === setupKey); if (
if (setupItem && !oldItems.includes(setupKey)) { ret.find((x) => x.key === setupKey) &&
!oldItems.includes(setupKey)
) {
oldItems.push(setupKey, setupKey + ".sha256", setupKey + ".sig"); oldItems.push(setupKey, setupKey + ".sha256", setupKey + ".sig");
} }
} }
// darwin companion
// darwin companion (.dmg) + sidecars
if (parts[3] === "darwin") { if (parts[3] === "darwin") {
const dmgKey = const dmgKey =
t.key.substring(0, t.key.length - ext.length) + ".dmg"; t.key.substring(0, t.key.length - ext.length) + ".dmg";
const dmgItem = ret.find((x) => x.key === dmgKey); if (
if (dmgItem && !oldItems.includes(dmgKey)) { ret.find((x) => x.key === dmgKey) &&
!oldItems.includes(dmgKey)
) {
oldItems.push(dmgKey, dmgKey + ".sha256", dmgKey + ".sig"); oldItems.push(dmgKey, dmgKey + ".sha256", dmgKey + ".sig");
} }
} }
@@ -133,17 +134,51 @@ const getBucketFiles = async (folderName) => {
} }
} }
// fast lookup
const byKey = Object.fromEntries(ret.map((r) => [r.key, r])); const byKey = Object.fromEntries(ret.map((r) => [r.key, r]));
// build final list by pushing (no in-place splicing) // ---- NEW: group kept tars by build, sort builds by newest, and sort within each build by platform/arch
const out = []; 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) { for (const t of tars) {
if (!keepTarKeys.has(t.key)) continue; if (!keepTarKeys.has(t.key)) continue;
const parts = t.name.split("_"); const parts = t.name.split("_");
const platform = parts[3]; const buildId = parts[2] || "";
const platform = (parts[3] || "").toLowerCase();
const arch = parts[4] || "";
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 });
}
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 // 1) tar + sidecars
out.push(t); out.push(t);
const tarSha = byKey[t.key + ".sha256"]; const tarSha = byKey[t.key + ".sha256"];
@@ -178,6 +213,7 @@ const getBucketFiles = async (folderName) => {
} }
} }
} }
}
return out; return out;
} catch (err) { } catch (err) {