/** * Platform and architecture resolution utilities. */ function parsePlatforms(input) { if (!input || typeof input !== 'string') return []; const parts = input.split(','); const platforms = []; for (const part of parts) { const clean = part.trim(); if (!clean) continue; if (!clean.includes('/')) { platforms.push(`linux/${clean}`); } else { platforms.push(clean); } } return platforms; } function discoverPlatforms(headRawJson, targetRawJson) { const set = new Set(); for (const raw of [headRawJson, targetRawJson]) { if (!raw) continue; try { const data = JSON.parse(raw); const manifests = data.manifests || []; for (const m of manifests) { if (m.platform && m.platform.architecture && m.platform.architecture !== 'unknown') { const os = m.platform.os || 'linux'; const variant = m.platform.variant ? `/${m.platform.variant}` : ''; set.add(`${os}/${m.platform.architecture}${variant}`); } } } catch { // Ignore JSON parse errors from invalid manifests } } return Array.from(set).sort(); } function toArchTag(platform) { if (!platform) return 'default'; // Strip optional leading os/ (e.g. linux/) const withoutOs = platform.replace(/^[a-zA-Z0-9_-]+\//, ''); // Replace slashes with dashes (e.g. arm/v7 -> arm-v7) return withoutOs.replace(/\//g, '-'); } module.exports = { parsePlatforms, discoverPlatforms, toArchTag, };