Skip to content

Commit

Permalink
Trying out improved test.yml approach for checking SBOM contents
Browse files Browse the repository at this point in the history
  • Loading branch information
rudsberg committed Dec 3, 2024
1 parent 2bdeaa9 commit da3d5c4
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 109 deletions.
22 changes: 2 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,31 +436,13 @@ jobs:
run: |
cd __tests__/sbom/main-test-app
mvn -Pnative package
cd target
echo "Checking for 'pkg:maven/org.json/json@20211205'"
grep -q 'pkg:maven/org.json/json@20211205' sbom.sbom.json || exit 1
echo "Checking for 'main-test-app'"
grep -q '"main-test-app"' sbom.sbom.json || exit 1
echo "Checking for 'svm'"
grep -q '"svm"' sbom.sbom.json || exit 1
echo "Checking for 'nativeimage'"
grep -q '"nativeimage"' sbom.sbom.json || exit 1
echo "SBOM was successfully generated and contained the expected contents"
sh verify-sbom.sh
shell: bash
if: runner.os != 'Windows'
- name: Build Maven project and verify SBOM was generated (Windows)
run: |
cd __tests__\sbom\main-test-app
mvn -Pnative package
cd target
echo "Checking for 'pkg:maven/org.json/json@20211205'"
findstr /c:"pkg:maven/org.json/json@20211205" sbom.sbom.json || exit /b 1
echo "Checking for 'main-test-app'"
findstr /c:"\"main-test-app\"" sbom.sbom.json || exit /b 1
echo "Checking for 'svm'"
findstr /c:"\"svm\"" sbom.sbom.json || exit /b 1
echo "Checking for 'nativeimage'"
findstr /c:"\"nativeimage\"" sbom.sbom.json || exit /b 1
echo "SBOM was successfully generated and contained the expected contents"
cmd /c verify-sbom.cmd
shell: cmd
if: runner.os == 'Windows'
10 changes: 6 additions & 4 deletions __tests__/sbom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('sbom feature', () => {

mockFindSBOM([])

await expect(processSBOM()).rejects.toBeInstanceOf(Error);
await expect(processSBOM()).rejects.toBeInstanceOf(Error)
})

it('should throw when JSON contains an invalid SBOM', async () => {
Expand Down Expand Up @@ -282,9 +282,11 @@ describe('sbom feature', () => {
})

it('should handle GitHub API submission errors gracefully', async () => {
mockGithubAPIReturnValue(new Error('API submission failed'))

await expect(setUpAndProcessSBOM(sampleSBOM)).rejects.toBeInstanceOf(Error);
mockGithubAPIReturnValue(new Error('API submission failed'))

await expect(setUpAndProcessSBOM(sampleSBOM)).rejects.toBeInstanceOf(
Error
)
})
})
})
14 changes: 14 additions & 0 deletions __tests__/sbom/main-test-app/verify-sbom.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@echo off
cd target

for %%p in (
"\"pkg:maven/org.json/json@20211205\""
"\"main-test-app\""
"\"svm\""
"\"nativeimage\""
) do (
echo Checking for %%p
findstr /c:%%p sbom.sbom.json || exit /b 1
)

echo SBOM was successfully generated and contained the expected contents
19 changes: 19 additions & 0 deletions __tests__/sbom/main-test-app/verify-sbom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
cd target

required_patterns=(
'"pkg:maven/org.json/json@20211205"'
'"main-test-app"'
'"svm"'
'"nativeimage"'
)

for pattern in "${required_patterns[@]}"; do
echo "Checking for $pattern"
if ! grep -q "$pattern" sbom.sbom.json; then
echo "Pattern not found: $pattern"
exit 1
fi
done

echo "SBOM was successfully generated and contained the expected contents"
71 changes: 30 additions & 41 deletions dist/cleanup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit da3d5c4

Please sign in to comment.