Skip to content

Commit bab76ec

Browse files
Add SBOM diff
1 parent 524931e commit bab76ec

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

.github/workflows/generate_sbom.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,32 @@ jobs:
6565
- name: Install dependencies
6666
run: uv sync --group generate_sbom
6767

68+
- name: Save existing SBOM for comparison
69+
run: |
70+
# Strip out nondeterministic SBOM fields and save to temp file
71+
jq 'del(.version, .metadata.timestamp, .metadata.tools.services[].version)' sbom.json > ${{runner.temp}}/sbom.existing.cdx.json
72+
6873
- name: generate_sbom.py
69-
run: uv run etc/sbom/generate_sbom.py --enable-github-action-token --target=branch --sbom-metadata=etc/sbom/metadata.cdx.json --save-warnings=${{runner.temp}}/warnings.txt
74+
run: |
75+
uv run etc/sbom/generate_sbom.py --enable-github-action-token --target=branch --sbom-metadata=etc/sbom/metadata.cdx.json --save-warnings=${{runner.temp}}/warnings.txt
76+
77+
- name: Check for SBOM changes
78+
id: sbom_diff
79+
run: |
80+
# Strip out nondeterministic SBOM fields and save to temp file
81+
jq 'del(.version, .metadata.timestamp, .metadata.tools.services[].version)' sbom.json > ${{runner.temp}}/sbom.generated.cdx.json
82+
RESULT=$(diff ${{runner.temp}}/sbom.existing.cdx.json ${{runner.temp}}/sbom.generated.cdx.json)
83+
# Set the output variable
84+
echo "::set-output name=result::$RESULT"
7085
71-
- name: Generate Pull Request Content
72-
run: printf "SBOM updated after commit ${{ github.sha }}.\n\nThe following warnings were output when generating the SBOM:\n" | cat - ${{runner.temp}}/warnings.txt > ${{runner.temp}}/pr_body.txt
86+
- name: Generate pull request content and notice, if SBOM has changed
87+
if: ${{ steps.sbom_diff.outputs.result }}
88+
run: |
89+
printf "SBOM updated after commit ${{ github.sha }}.\n\n" | cat - ${{runner.temp}}/warnings.txt > ${{runner.temp}}/pr_body.txt
90+
echo "::notice SBOM has changed"
7391
74-
- name: Open Pull Request
92+
- name: Open Pull Request, if SBOM has changed
93+
if: ${{ steps.sbom_diff.outputs.result }}
7594
uses: peter-evans/create-pull-request@84ae59a2cdc2258d6fa0732dd66352dddae2a412 # v7.0.9
7695
with:
7796
add-paths: sbom.json

etc/sbom/generate_sbom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,17 +830,17 @@ def main() -> None:
830830

831831
# Access the collected warnings
832832
print_banner('CONSOLIDATED WARNINGS')
833-
warnings = []
833+
warnings = ["The following warnings were output when generating the SBOM:\n"]
834834
for record in warning_handler.warnings:
835-
warnings.append(record.getMessage())
835+
warnings.append(" - " + record.getMessage())
836836

837837
print('\n'.join(warnings))
838838

839839
if save_warnings:
840840
write_list_to_text_file(warnings, save_warnings)
841841

842842
print_banner('COMPLETED')
843-
if not os.getenv('CI'):
843+
if not os.getenv('CI') and not os.getenv("GITHUB_ACTIONS"):
844844
print('Be sure to add the SBOM to your next commit if the file content has changed.')
845845

846846
# endregion Finalize SBOM

0 commit comments

Comments
 (0)