Skip to content

Commit 583276c

Browse files
chore(workflows): add standalone SBOM diffing script for local testing
related to camunda/camunda-bpm-platform#2781
1 parent 0bc9a6d commit 583276c

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

common/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbom-workspace

common/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ git push ...
1313
```
1414

1515
Make sure to commit and push the changes to the `dist` directory to the repository.
16+
17+
# How to test
18+
19+
Run `npm run test` to run the unit tests
20+
21+
# How to try SBOM diffing
22+
23+
1. Generate two SBOMs that you want to compare
24+
1. For example, use `mvn org.cyclonedx:cyclonedx-maven-plugin:2.7.9:makeAggregateBom` to generate an SBOM for a maven (multi-module) project
25+
1. Run `npm run diff-sboms <path to base SBOM> <path to comparing SBOM> <output file path>` to generate an SBOM diff
26+
1. Hint: The `sbom-workspace` subdirectory is in `.gitignore`, so you can put files there
27+
1. In Visual Studio Code, you can run the script from the Javascript Debugger Console to attach a debugger and put breakpoints in the business logic

common/diff-sboms-standalone.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const diffSBOMs = require('./src/sbom-diff/differ.js');
2+
const formatTemplate = require('./src/sbom-diff/format-handlebars-template.js');
3+
const fs = require('fs');
4+
5+
const readFile = function(path) {
6+
return fs.readFileSync(path, 'utf8')
7+
}
8+
9+
const writeFile = function(path, content) {
10+
fs.writeFileSync(path, content); // default encoding is utf8
11+
}
12+
13+
var args = process.argv.slice(2); // first two arguments are the executable and the JS file
14+
15+
if (args.length != 3) {
16+
throw new Error('Requires three arguments: <path to base SBOM> <path to comparing SBOM> <path to output file>');
17+
}
18+
19+
const baseSbomPath = args[0];
20+
const headSbomPath = args[1];
21+
const outPath = args[2];
22+
23+
const baseSbom = readFile(baseSbomPath);
24+
const headSbom = readFile(headSbomPath);
25+
26+
const licenseList = readFile('../java-dependency-check/licenses.json');
27+
28+
const commentTemplate = readFile('../java-dependency-check/diff.hbs');
29+
30+
const partialPaths = [
31+
'componentDetails:../java-dependency-check/component-details.hbs',
32+
'componentDiff:../java-dependency-check/component-diff.hbs',
33+
'componentTree:../java-dependency-check/component-tree.hbs',
34+
'componentVersion:../java-dependency-check/component-version.hbs'
35+
];
36+
37+
const partials = partialPaths.reduce(
38+
(result, input) => {
39+
[ partialId, partialPath ] = input.split(':');
40+
result[partialId.trim()] = readFile(partialPath.trim());
41+
return result;
42+
},
43+
{}
44+
);
45+
46+
diffSBOMs(baseSbom, headSbom, '^org\\.camunda', licenseList)
47+
.then(rootComponentDiff => formatTemplate(rootComponentDiff, commentTemplate, partials)
48+
.then(diff => writeFile(outPath, diff.fullDiff)));
49+
50+

0 commit comments

Comments
 (0)