Skip to content

Commit 67deeee

Browse files
Add check for changes before adding file to push for PR & change python to latest version
1 parent f36203f commit 67deeee

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

.github/workflows/sbom.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set up Python
3434
uses: actions/setup-python@v6
3535
with:
36-
python-version: "3.10"
36+
python-version: "3.x"
3737
- name: Generate SBOM
3838
run: |
3939
python -m venv .venv
@@ -45,15 +45,38 @@ jobs:
4545
python -m venv .venv-sbom
4646
source .venv-sbom/bin/activate
4747
pip install cyclonedx-bom==7.2.1
48-
cyclonedx-py environment --spec-version 1.5 --output-format JSON --output-file sbom.json .venv
48+
cyclonedx-py environment --spec-version 1.5 --output-format JSON --output-file sbom-new.json .venv
4949
# Add PURL for django-mongodb-backend (local package doesn't get PURL automatically)
50-
jq '(.components[] | select(.name == "django-mongodb-backend" and .purl == null)) |= (. + {purl: ("pkg:pypi/django-mongodb-backend@" + .version)})' sbom.json > sbom.tmp.json && mv sbom.tmp.json sbom.json
50+
jq '(.components[] | select(.name == "django-mongodb-backend" and .purl == null)) |= (. + {purl: ("pkg:pypi/django-mongodb-backend@" + .version)})' sbom-new.json > sbom.tmp.json && mv sbom.tmp.json sbom-new.json
5151
- name: Download CycloneDX CLI
5252
run: |
5353
curl -L -s -o /tmp/cyclonedx "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.29.1/cyclonedx-linux-x64"
5454
chmod +x /tmp/cyclonedx
5555
- name: Validate SBOM
56-
run: /tmp/cyclonedx validate --input-file sbom.json --fail-on-errors
56+
run: /tmp/cyclonedx validate --input-file sbom-new.json --fail-on-errors
57+
- name: Check for changes
58+
id: check_changes
59+
run: |
60+
if [ -f sbom.json ]; then
61+
echo "Comparing new SBOM with existing sbom.json..."
62+
# Use cyclonedx diff to check for component changes
63+
DIFF_OUTPUT=$(/tmp/cyclonedx diff sbom.json sbom-new.json --component-versions)
64+
65+
# Check if there are meaningful changes (output contains more than just "None")
66+
if echo "$DIFF_OUTPUT" | grep -q "^None$"; then
67+
echo "No component changes detected (only metadata differs)"
68+
echo "Keeping existing sbom.json"
69+
rm sbom-new.json
70+
else
71+
echo "Component changes detected:"
72+
echo "$DIFF_OUTPUT"
73+
echo "Updating sbom.json"
74+
mv sbom-new.json sbom.json
75+
fi
76+
else
77+
echo "No existing sbom.json found, creating initial version"
78+
mv sbom-new.json sbom.json
79+
fi
5780
- name: Cleanup
5881
if: always()
5982
run: rm -rf .venv .venv-sbom

0 commit comments

Comments
 (0)