refactor(action): replace bash blocks with zero-dependency Node.js modules #17

Merged
Philipp merged 2 commits from feat-bash-to-js-refactor into main 2026-09-15 00:51:18 +02:00
Owner

Summary

Replaces ~450 lines of complex bash scripting in action.yaml with modular, zero-dependency Node.js modules, covered by 26 native unit tests.

Why?

  • Testability: Bash logic was untestable. Each module is now independently unit-tested with node:test.
  • Maintainability: Single-responsibility modules are far easier to reason about and modify.
  • Zero dependencies: All modules use only Node.js built-ins (fs, path, crypto, child_process, os). No node_modules, no npm install.
  • Composite action preserved: actions/cache stays in action.yaml as a native step.

Modules Added (lib/)

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

Tests Added (test/)

26/26 tests pass via node --test (auto-discovered, same command as CI).

action.yaml Change

554 lines -> 107 lines. Inputs bridged via INPUT_* env vars.

## Summary Replaces ~450 lines of complex bash scripting in `action.yaml` with modular, zero-dependency Node.js modules, covered by 26 native unit tests. ### Why? - **Testability**: Bash logic was untestable. Each module is now independently unit-tested with `node:test`. - **Maintainability**: Single-responsibility modules are far easier to reason about and modify. - **Zero dependencies**: All modules use only Node.js built-ins (`fs`, `path`, `crypto`, `child_process`, `os`). No `node_modules`, no `npm install`. - **Composite action preserved**: `actions/cache` stays in `action.yaml` as a native step. ### Modules Added (`lib/`) | Module | Responsibility | |---|---| | `platforms.js` | Platform parsing and OCI manifest auto-discovery | | `distro.js` | SPDX PURL distro detection (`os_name`/`os_version`) | | `verifier.js` | Trivy arch mapping and SHA256 verification | | `diagnostics.js` | CI terminal diagnostic formatters | | `install-trivy.js` | Trivy install/verify entrypoint (replaces bash step) | | `extract-sboms.js` | SBOM extraction entrypoint (replaces bash step) | | `scan-sboms.js` | SBOM scan + diff entrypoint (replaces bash step) | ### Tests Added (`test/`) 26/26 tests pass via `node --test` (auto-discovered, same command as CI). ### `action.yaml` Change 554 lines -> 107 lines. Inputs bridged via `INPUT_*` env vars.
Philipp added 1 commit 2026-09-15 00:40:10 +02:00
refactor(action): replace bash blocks with zero-dependency Node.js modules
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
77357f0c3f
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.
Philipp force-pushed feat-bash-to-js-refactor from 599b74ef49 to 77357f0c3f 2026-09-15 00:40:10 +02:00 Compare
Philipp requested review from AutoReview 2026-09-15 00:40:22 +02:00
AutoReview approved these changes 2026-09-15 00:40:26 +02:00
Dismissed
AutoReview left a comment
Collaborator

Summary

  • Critical: None.
  • Testing: The PR includes a comprehensive suite of unit tests in the /test/ directory, which covers the new Node.js logic well.
  • Improvement: The refactor significantly improves maintainability and testability by replacing complex Bash scripts with modular Node.js files. The use of node:child_process and node:fs keeps the action zero-dependency, which is excellent.
  • Nitpick: Ensure that the lib/ directory contents are considered when managing future updates to the action, as this adds complexity compared to a single action.yaml script block.

Overall, the refactoring is high-quality and correctly implements the transition from shell to Node.js.

**Summary** * **Critical:** None. * **Testing:** The PR includes a comprehensive suite of unit tests in the `/test/` directory, which covers the new Node.js logic well. * **Improvement:** The refactor significantly improves maintainability and testability by replacing complex Bash scripts with modular Node.js files. The use of `node:child_process` and `node:fs` keeps the action zero-dependency, which is excellent. * **Nitpick:** Ensure that the `lib/` directory contents are considered when managing future updates to the action, as this adds complexity compared to a single `action.yaml` script block. Overall, the refactoring is high-quality and correctly implements the transition from shell to Node.js.
Philipp added 1 commit 2026-09-15 00:49:02 +02:00
Merge branch 'main' into feat-bash-to-js-refactor
Philipp/Global-Workflows: Pre-commit Lint (Scoped) / pre-commit (pull_request) Successful in 1m43s
CI Tests / JS Unit Tests (pull_request) Successful in 16s
CI Tests / cross-check-mixed-sbom (sbom=false) (pull_request) Failing after 2m48s
CI Tests / without-inbuild-sbom (sbom=false) (pull_request) Failing after 3m13s
CI Tests / without-inbuild-sbom (sbom=true) (pull_request) Failing after 3m13s
CI Tests / cross-check-mixed-sbom (sbom=true) (pull_request) Failing after 3m15s
CI Tests / with-inbuild-sbom (sbom=false) (pull_request) Failing after 4m38s
CI Tests / with-inbuild-sbom (sbom=true) (pull_request) Failing after 4m39s
493d119b3c
AutoReview approved these changes 2026-09-15 00:49:05 +02:00
AutoReview left a comment
Collaborator

Summary

  • Critical: None.
  • Testing: The PR includes a comprehensive suite of unit tests in the /test/ directory, which covers the new Node.js logic well.
  • Improvement: The refactor significantly improves maintainability and testability by replacing complex Bash scripts with modular Node.js files. The use of node:child_process and node:fs keeps the action zero-dependency, which is excellent.
  • Nitpick: Ensure that the lib/ directory contents are considered when managing future updates to the action, as this adds complexity compared to a single action.yaml script block.

The refactor is high-quality and correctly implements the transition from shell to Node.js, maintaining zero-dependency status while significantly improving testability and robustness. I am approving this PR.

**Summary** * **Critical:** None. * **Testing:** The PR includes a comprehensive suite of unit tests in the `/test/` directory, which covers the new Node.js logic well. * **Improvement:** The refactor significantly improves maintainability and testability by replacing complex Bash scripts with modular Node.js files. The use of `node:child_process` and `node:fs` keeps the action zero-dependency, which is excellent. * **Nitpick:** Ensure that the `lib/` directory contents are considered when managing future updates to the action, as this adds complexity compared to a single `action.yaml` script block. The refactor is high-quality and correctly implements the transition from shell to Node.js, maintaining zero-dependency status while significantly improving testability and robustness. I am approving this PR.
Philipp scheduled this pull request to auto merge when all checks succeed 2026-09-15 00:49:14 +02:00
Philipp merged commit 17e5dab1b2 into main 2026-09-15 00:51:18 +02:00
Philipp deleted branch feat-bash-to-js-refactor 2026-09-15 00:51:18 +02:00
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Philipp/cve-differential#17