|
| 1 | +name: Generate SBOM with OSV-Scanner and load into ScanCode.io |
| 2 | + |
| 3 | +# This workflow: |
| 4 | +# 1. Generates a CycloneDX SBOM for a container image using OSV-Scanner. |
| 5 | +# 2. Uploads the SBOM as a GitHub artifact for future inspection. |
| 6 | +# 3. Loads the SBOM into ScanCode.io for further analysis. |
| 7 | +# 4. Runs assertions to verify that the SBOM was properly processed in ScanCode.io. |
| 8 | +# |
| 9 | +# It runs on demand, and once a week (scheduled). |
| 10 | + |
| 11 | +on: |
| 12 | + workflow_dispatch: |
| 13 | + schedule: |
| 14 | + # Run once a week (every 7 days) at 00:00 UTC on Sunday |
| 15 | + - cron: "0 0 * * 0" |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +env: |
| 21 | + IMAGE_REFERENCE: "python:3.13.0-slim" |
| 22 | + |
| 23 | +jobs: |
| 24 | + generate-and-load-sbom: |
| 25 | + runs-on: ubuntu-24.04 |
| 26 | + steps: |
| 27 | + - name: Install OSV-Scanner |
| 28 | + run: | |
| 29 | + curl -sLO https://github.com/google/osv-scanner/releases/latest/download/osv-scanner_linux_amd64 |
| 30 | + chmod +x osv-scanner_linux_amd64 |
| 31 | + sudo mv osv-scanner_linux_amd64 /usr/local/bin/osv-scanner |
| 32 | +
|
| 33 | + - name: Run OSV Scanner |
| 34 | + # Using `|| true` as OSV-Scanner exits with code 1 when vulnerabilities are found. |
| 35 | + run: | |
| 36 | + osv-scanner scan image ${{ env.IMAGE_REFERENCE }} \ |
| 37 | + --all-packages \ |
| 38 | + --format spdx-2-3 \ |
| 39 | + --output osv-sbom.spdx.json \ |
| 40 | + || true |
| 41 | +
|
| 42 | + - name: Upload SBOM as GitHub Artifact |
| 43 | + uses: actions/upload-artifact@v4 |
| 44 | + with: |
| 45 | + name: osv-scanner-sbom-report |
| 46 | + path: osv-sbom.spdx.json |
| 47 | + retention-days: 20 |
| 48 | + |
| 49 | + - name: Import SBOM into ScanCode.io |
| 50 | + uses: aboutcode-org/scancode-action@main |
| 51 | + with: |
| 52 | + pipelines: "load_sbom" |
| 53 | + inputs-path: "osv-sbom.spdx.json" |
| 54 | + scancodeio-repo-branch: "main" |
| 55 | + |
| 56 | + - name: Verify SBOM Analysis Results in ScanCode.io |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + scanpipe shell --command "from scanpipe.models import DiscoveredPackage, DiscoveredDependency; package_manager = DiscoveredPackage.objects; assert package_manager.count() >= 100; assert package_manager.vulnerable().count() == 0; assert DiscoveredDependency.objects.count() >= 100" |
0 commit comments