Public Access
generated from Philipp/template-git
refactor(action): replace bash blocks with zero-dependency Node.js modules
Philipp/Global-Workflows: Pre-commit Lint (Scoped) / pre-commit (pull_request) Successful in 1m53s
Philipp/Global-Workflows: Pre-commit Lint (Scoped) / pre-commit (pull_request) Successful in 1m53s
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.
This commit is contained in:
13 files changed
+1145
-347
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Distribution detection from SPDX SBOM package PURLs.
|
||||
*/
|
||||
|
||||
function detectDistro(spdxInput) {
|
||||
if (!spdxInput) return null;
|
||||
|
||||
let data = spdxInput;
|
||||
if (typeof spdxInput === 'string' || Buffer.isBuffer(spdxInput)) {
|
||||
try {
|
||||
data = JSON.parse(spdxInput.toString('utf8'));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data || typeof data !== 'object' || !Array.isArray(data.packages)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (const pkg of data.packages) {
|
||||
if (!pkg || !Array.isArray(pkg.externalRefs)) continue;
|
||||
for (const ref of pkg.externalRefs) {
|
||||
if (ref && ref.referenceType === 'purl' && typeof ref.referenceLocator === 'string') {
|
||||
const purl = ref.referenceLocator;
|
||||
const nameMatch = purl.match(/[?&]os_name=([^&]+)/);
|
||||
const verMatch = purl.match(/[?&]os_version=([^&]+)/);
|
||||
if (nameMatch && verMatch) {
|
||||
const osName = decodeURIComponent(nameMatch[1]);
|
||||
const osVer = decodeURIComponent(verMatch[1]);
|
||||
return `${osName}/${osVer}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
detectDistro,
|
||||
};
|
||||
Reference in new issue
Block a user