setup grouping
This commit is contained in:
98
src/api.js
98
src/api.js
@@ -48,21 +48,7 @@ const byNewest = (a, b) => b.sort - a.sort;
|
||||
|
||||
const sidecarsFor = (key) => [key + ".sha256", key + ".sig"];
|
||||
|
||||
// parts[0]=product, parts[1]=version (e.g., 2.1.0-rc), parts[2]=build (e.g., 8465201),
|
||||
// parts[3]=platform (windows|darwin|linux), parts[4]=arch (x86-64|aarch64)
|
||||
const parseName = (fname) => {
|
||||
const parts = fname.split("_");
|
||||
const product = parts[0] ?? "";
|
||||
const version = parts[1] ?? "";
|
||||
const build = parts[2] ?? "";
|
||||
const platform = (parts[3] ?? "").toLowerCase();
|
||||
const arch = parts[4] ?? "";
|
||||
const groupId = `${product}_${platform}_${arch}`; // retention groups
|
||||
const releaseId = `${product}_${build}`; // emit grouping
|
||||
return { parts, product, version, build, platform, arch, groupId, releaseId };
|
||||
};
|
||||
|
||||
// Remove sidecar suffixes first, then packaging suffix
|
||||
// --- base/packaging helpers
|
||||
const stripSidecar = (name) => {
|
||||
if (name.endsWith(".sha256")) return name.slice(0, -".sha256".length);
|
||||
if (name.endsWith(".sig")) return name.slice(0, -".sig".length);
|
||||
@@ -70,7 +56,7 @@ const stripSidecar = (name) => {
|
||||
};
|
||||
|
||||
const stripPackaging = (name) => {
|
||||
if (name.endsWith(TAR_EXT)) return name.slice(0, -TAR_EXT.length); // correct length
|
||||
if (name.endsWith(TAR_EXT)) return name.slice(0, -TAR_EXT.length);
|
||||
if (name.endsWith("_setup.exe")) return name.slice(0, -"_setup.exe".length);
|
||||
if (name.endsWith(".dmg")) return name.slice(0, -".dmg".length);
|
||||
return name;
|
||||
@@ -82,7 +68,35 @@ const isTar = (name) => name.endsWith(TAR_EXT);
|
||||
const isDmg = (name) => name.endsWith(".dmg");
|
||||
const isSetup = (name) => name.endsWith("_setup.exe");
|
||||
|
||||
// platform/arch sort preference inside a build
|
||||
// --- normalization + parsing (operate on baseStem!)
|
||||
const normalize_platform = (p) => {
|
||||
const v = (p || "").toLowerCase();
|
||||
if (v === "macos") return "darwin";
|
||||
return v;
|
||||
};
|
||||
|
||||
const normalize_arch = (a) => {
|
||||
const v = (a || "").toLowerCase();
|
||||
if (v === "arm64" || v === "aarch64") return "aarch64";
|
||||
if (v === "x86_64" || v === "x86-64") return "x86-64";
|
||||
return v;
|
||||
};
|
||||
|
||||
// parts[0]=product, parts[1]=version, parts[2]=build, parts[3]=platform, parts[4]=arch
|
||||
const parseName = (fname) => {
|
||||
const stem = baseStem(fname);
|
||||
const parts = stem.split("_");
|
||||
const product = parts[0] ?? "";
|
||||
const version = parts[1] ?? "";
|
||||
const build = parts[2] ?? "";
|
||||
const platform = normalize_platform(parts[3] ?? "");
|
||||
const arch = normalize_arch(parts[4] ?? "");
|
||||
const groupId = `${product}_${platform}_${arch}`; // retention groups
|
||||
const releaseId = `${product}_${build}`; // build grouping (emit)
|
||||
return { parts, product, version, build, platform, arch, groupId, releaseId };
|
||||
};
|
||||
|
||||
// platform/arch sort preference within a build
|
||||
const platformRank = (platform) =>
|
||||
platform === "darwin"
|
||||
? 0
|
||||
@@ -92,16 +106,7 @@ const platformRank = (platform) =>
|
||||
? 2
|
||||
: 3;
|
||||
|
||||
const archRank = (arch) =>
|
||||
arch === "aarch64"
|
||||
? 0
|
||||
: arch === "arm64"
|
||||
? 0 // normalize if needed later
|
||||
: arch === "x86-64"
|
||||
? 1
|
||||
: arch === "x86_64"
|
||||
? 1
|
||||
: 2;
|
||||
const archRank = (arch) => (arch === "aarch64" ? 0 : arch === "x86-64" ? 1 : 2);
|
||||
|
||||
/* ---------------- public API ---------------- */
|
||||
|
||||
@@ -148,14 +153,14 @@ const getBucketFiles = async (folderName) => {
|
||||
const contents = (data.Contents ?? []).filter((it) => it.Key !== folderKey);
|
||||
const listed = contents.map(toListed(folderKey)).sort(byNewest);
|
||||
|
||||
// Indexes
|
||||
// Index by base stem; aggregate tar/dmg/setup under the same platform+arch for a build
|
||||
const byKey = Object.fromEntries(listed.map((i) => [i.key, i]));
|
||||
const byBase = new Map(); // base -> { rep, tar, dmg, setup, sidecars:Set<string>, platform, arch, releaseId }
|
||||
|
||||
for (const it of listed) {
|
||||
const base = baseStem(it.name);
|
||||
let g = byBase.get(base);
|
||||
if (!g) {
|
||||
// We’ll fill platform/arch/releaseId from the *first* non-sidecar file we see
|
||||
g = {
|
||||
rep: null,
|
||||
tar: null,
|
||||
@@ -168,35 +173,30 @@ const getBucketFiles = async (folderName) => {
|
||||
};
|
||||
byBase.set(base, g);
|
||||
}
|
||||
|
||||
const meta = parseName(it.name); // <-- now from baseStem(), so arch/platform are clean
|
||||
if (isTar(it.name)) {
|
||||
g.tar = it;
|
||||
g.rep = g.rep ?? it;
|
||||
const meta = parseName(it.name);
|
||||
g.platform = meta.platform;
|
||||
g.arch = meta.arch;
|
||||
g.releaseId = meta.releaseId;
|
||||
} else if (isDmg(it.name)) {
|
||||
g.dmg = it;
|
||||
g.rep = g.rep ?? it;
|
||||
const meta = parseName(it.name);
|
||||
if (!g.platform) g.platform = meta.platform;
|
||||
if (!g.arch) g.arch = meta.arch;
|
||||
if (!g.releaseId) g.releaseId = meta.releaseId;
|
||||
} else if (isSetup(it.name)) {
|
||||
g.setup = it;
|
||||
g.rep = g.rep ?? it;
|
||||
const meta = parseName(it.name);
|
||||
if (!g.platform) g.platform = meta.platform;
|
||||
if (!g.arch) g.arch = meta.arch;
|
||||
if (!g.releaseId) g.releaseId = meta.releaseId;
|
||||
} else if (it.name.endsWith(".sha256") || it.name.endsWith(".sig")) {
|
||||
g.sidecars.add(it.key);
|
||||
}
|
||||
|
||||
// ensure metadata captured (first non-sidecar wins, but we can fill missing)
|
||||
if (!g.platform && meta.platform) g.platform = meta.platform;
|
||||
if (!g.arch && meta.arch) g.arch = meta.arch;
|
||||
if (!g.releaseId && meta.releaseId) g.releaseId = meta.releaseId;
|
||||
}
|
||||
|
||||
const groups = Array.from(byBase.values()).filter((g) => g.rep);
|
||||
|
||||
// ---------- Retention (unchanged logic): newest 3 per product+platform+arch ----------
|
||||
// ---------- Retention: newest 3 per product+platform+arch (nightly) ----------
|
||||
const keepBaseSet = new Set();
|
||||
if (folder === "nightly") {
|
||||
const buckets = new Map(); // groupId -> [groups]
|
||||
@@ -213,7 +213,6 @@ const getBucketFiles = async (folderName) => {
|
||||
if (idx < 3) {
|
||||
keepBaseSet.add(base);
|
||||
} else {
|
||||
// mark all artifacts in this base as old
|
||||
if (g.tar)
|
||||
[g.tar.key, ...sidecarsFor(g.tar.key)].forEach((k) =>
|
||||
oldKeys.add(k),
|
||||
@@ -235,9 +234,10 @@ const getBucketFiles = async (folderName) => {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Emit order: group KEPT bases by releaseId (build), newest-first by representative timestamp ----------
|
||||
// ---------- Emit: group by release (build) -> platform -> arch ----------
|
||||
const kept = groups.filter((g) => keepBaseSet.has(baseStem(g.rep.name)));
|
||||
const releases = new Map(); // releaseId -> { repSort:number, items: [g...] }
|
||||
|
||||
const releases = new Map(); // releaseId -> { repSort:number, items:[g...] }
|
||||
for (const g of kept) {
|
||||
const rid = g.releaseId || parseName(g.rep.name).releaseId;
|
||||
if (!releases.has(rid)) {
|
||||
@@ -248,21 +248,19 @@ const getBucketFiles = async (folderName) => {
|
||||
bucket.items.push(g);
|
||||
}
|
||||
|
||||
// sort releases newest-first
|
||||
const releaseList = Array.from(releases.entries()).sort(
|
||||
(a, b) => b[1].repSort - a[1].repSort,
|
||||
);
|
||||
|
||||
// Inside each release, sort platforms/arches by preference
|
||||
const out = [];
|
||||
for (const [, bucket] of releaseList) {
|
||||
// group windows _setup together with the same platform block by sorting on platform+arch
|
||||
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;
|
||||
// fallback: newest-first
|
||||
return (b.rep?.sort ?? 0) - (a.rep?.sort ?? 0);
|
||||
return (b.rep?.sort ?? 0) - (a.rep?.sort ?? 0); // tie-breaker: newest first
|
||||
});
|
||||
|
||||
for (const g of bucket.items) {
|
||||
@@ -282,7 +280,7 @@ const getBucketFiles = async (folderName) => {
|
||||
if (it) out.push(it);
|
||||
}
|
||||
}
|
||||
// setup + sidecars
|
||||
// setup + sidecars (now guaranteed to live in the same platform block)
|
||||
if (g.setup) {
|
||||
out.push(g.setup);
|
||||
for (const sk of sidecarsFor(g.setup.key)) {
|
||||
|
Reference in New Issue
Block a user