Files
cve-differential/lib/platforms.js
T
Philipp 77357f0c3f
CI Tests / JS Unit Tests (pull_request) Successful in 46s
Philipp/Global-Workflows: Pre-commit Lint (Scoped) / pre-commit (pull_request) Successful in 1m54s
CI Tests / cross-check-mixed-sbom (sbom=false) (pull_request) Failing after 3m22s
CI Tests / cross-check-mixed-sbom (sbom=true) (pull_request) Failing after 2m38s
CI Tests / with-inbuild-sbom (sbom=false) (pull_request) Failing after 4m21s
CI Tests / without-inbuild-sbom (sbom=true) (pull_request) Failing after 5m36s
CI Tests / without-inbuild-sbom (sbom=false) (pull_request) Failing after 6m47s
CI Tests / with-inbuild-sbom (sbom=true) (pull_request) Failing after 2m59s
refactor(action): replace bash blocks with zero-dependency Node.js modules
Extract ~450 lines of complex bash from action.yaml into modular,
unit-tested Node.js scripts in lib/. All logic is covered by 26 native
node:test unit tests (node --test, no external dependencies).

Modules added:
- lib/platforms.js   - platform parsing and OCI manifest auto-discovery
- lib/distro.js      - SPDX PURL distro detection (os_name/os_version)
- lib/verifier.js    - Trivy arch mapping and SHA256 verification
- lib/diagnostics.js - CI terminal diagnostic formatters
- lib/install-trivy.js  - Trivy install/verify entrypoint (replaces bash step)
- lib/extract-sboms.js  - SBOM extraction entrypoint (replaces bash step)
- lib/scan-sboms.js     - SBOM scan + diff entrypoint (replaces bash step)

Tests added (all pass, auto-discovered by
ode --test):
- test/platforms.test.js
- test/distro.test.js
- test/verifier.test.js
- test/diagnostics.test.js
- test/orchestration.test.js

action.yaml shrinks from 554 to 107 lines. Inputs are bridged to Node
scripts via INPUT_* env vars so modules are fully decoupled from the
Actions runner and testable in isolation.
2026-09-15 00:39:13 +02:00

55 lines
1.5 KiB
JavaScript

/**
* 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,
};