-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add SBOM-based dependency diff workflow #14
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a6e35d3
feat(workflows): add SBOM parsing and diffing logic
ThorbenLindhauer 3a28741
feat(workflows): add rendering of SBOM diffs to Markdown/HTML
ThorbenLindhauer dd97e0a
feat(workflows): add reusable github workflow for SBOM diffing
ThorbenLindhauer 30c077d
chore(project): add github workflow as CI of Javascript sources
ThorbenLindhauer 3dfe8c2
chore(workflows): add standalone SBOM diffing script for local testing
ThorbenLindhauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Continuous integration (node-js code) | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.x' | ||
- run: npm ci | ||
working-directory: common | ||
- run: npm run build | ||
working-directory: common | ||
- run: npm test | ||
working-directory: common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Compare the dependencies of a pull request to a Maven multi-module project with the base branch. Check according to our Stop & Go list. | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
ref: | ||
description: 'The reference of the github commit of the reusable workflow. Must match the specified branch/tag/commit where the workflow is called. Workaround to https://github.com/actions/runner/issues/2417. Should never be untrusted content.' | ||
default: 'main' | ||
type: string | ||
secrets: | ||
VAULT_ADDR: | ||
required: true | ||
VAULT_ROLE_ID: | ||
required: true | ||
VAULT_SECRET_ID: | ||
required: true | ||
|
||
jobs: | ||
java-dependency-check: | ||
runs-on: ubuntu-latest | ||
name: Java Dependency Check | ||
# todo: filter by label if diff should be performed | ||
steps: | ||
- name: Import Secrets | ||
id: secrets | ||
uses: hashicorp/[email protected] | ||
with: | ||
url: ${{ secrets.VAULT_ADDR }} | ||
method: approle | ||
roleId: ${{ secrets.VAULT_ROLE_ID }} | ||
secretId: ${{ secrets.VAULT_SECRET_ID }} | ||
secrets: | | ||
secret/data/github.com/organizations/camunda NEXUS_USR; | ||
secret/data/github.com/organizations/camunda NEXUS_PSW; | ||
- uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '17' | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
path: repo-to-check | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
- name: Checkout reusable workflow dir | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: camunda/automation-platform-github-actions | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
path: automation-platform-github-actions | ||
ref: ${{ inputs.ref }} # github.job_workflow_sha seems to be the documented parameter to resolve this, but doesn't work in practice | ||
- name: Generate SBOMs | ||
id: generate-sboms | ||
run: bash ${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/generate-sboms.sh ${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/maven-settings.xml | ||
working-directory: ${{ github.workspace }}/repo-to-check | ||
- name: Diff SBOMs | ||
id: diff-sboms | ||
uses: ./automation-platform-github-actions/java-dependency-check | ||
with: | ||
base-sbom: ${{ github.workspace }}/repo-to-check/target/diff/base.json | ||
head-sbom: ${{ github.workspace }}/repo-to-check/target/diff/head.json | ||
primary-party-group-matcher: "^org\\.camunda" | ||
license-list: ${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/licenses.json | ||
github-comment-template: ${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/diff.hbs | ||
partials: | | ||
componentDetails:${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/component-details.hbs | ||
componentDiff:${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/component-diff.hbs | ||
componentTree:${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/component-tree.hbs | ||
componentVersion:${{ github.workspace }}/automation-platform-github-actions/java-dependency-check/component-version.hbs | ||
output-path: ${{ github.workspace }}/dependency-diff.html | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Upload full diff as workflow artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: artifacts.zip | ||
path: | | ||
${{ github.workspace }}/dependency-diff.html | ||
${{ github.workspace }}/repo-to-check/target/diff/base.json | ||
${{ github.workspace }}/repo-to-check/target/diff/head.json | ||
retention-days: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbom-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const diffSBOMs = require('./src/sbom-diff/differ.js'); | ||
const formatTemplate = require('./src/sbom-diff/format-handlebars-template.js'); | ||
const fs = require('fs'); | ||
|
||
const readFile = function(path) { | ||
return fs.readFileSync(path, 'utf8') | ||
} | ||
|
||
const writeFile = function(path, content) { | ||
fs.writeFileSync(path, content); // default encoding is utf8 | ||
} | ||
|
||
var args = process.argv.slice(2); // first two arguments are the executable and the JS file | ||
|
||
if (args.length !== 3) { | ||
throw new Error('Requires three arguments: <path to base SBOM> <path to comparing SBOM> <path to output file>'); | ||
} | ||
|
||
const baseSbomPath = args[0]; | ||
const headSbomPath = args[1]; | ||
const outPath = args[2]; | ||
|
||
const baseSbom = readFile(baseSbomPath); | ||
const headSbom = readFile(headSbomPath); | ||
|
||
const licenseList = readFile('../java-dependency-check/licenses.json'); | ||
|
||
const commentTemplate = readFile('../java-dependency-check/diff.hbs'); | ||
|
||
const partialPaths = [ | ||
'componentDetails:../java-dependency-check/component-details.hbs', | ||
'componentDiff:../java-dependency-check/component-diff.hbs', | ||
'componentTree:../java-dependency-check/component-tree.hbs', | ||
'componentVersion:../java-dependency-check/component-version.hbs' | ||
]; | ||
|
||
const partials = partialPaths.reduce( | ||
(result, input) => { | ||
[ partialId, partialPath ] = input.split(':'); | ||
result[partialId.trim()] = readFile(partialPath.trim()); | ||
return result; | ||
}, | ||
{} | ||
); | ||
|
||
diffSBOMs(baseSbom, headSbom, '^org\\.camunda', licenseList) | ||
.then(rootComponentDiff => formatTemplate(rootComponentDiff, commentTemplate, partials) | ||
.then(diff => writeFile(outPath, diff.fullDiff))); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Interesting way of doing this :) But it does the job.
I guess it's because it uses the (almost) same format as the workflow parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if there's a more elegant way to convert these parameters into a map. I have rather basic Javascript standard library knowledge (and google skills).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's okay!
I later realized that it uses the same format as the workflow input parameter (which is just a string not a JSON object or map), so it makes sense. 👍