|
| 1 | +name: Generate SBOM |
| 2 | + |
| 3 | +# This workflow uses cargo-cyclonedx and publishes an sbom.json artifact. |
| 4 | +# It runs on manual trigger or when Cargo files change on main branch, |
| 5 | +# and creates a PR with the updated SBOM. |
| 6 | +# Internal documentation: go/sbom-scope |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: {} |
| 10 | + push: |
| 11 | + branches: ['main'] |
| 12 | + paths: |
| 13 | + - 'Cargo.toml' |
| 14 | + - 'Cargo.lock' |
| 15 | + - 'driver/Cargo.toml' |
| 16 | + - 'macros/Cargo.toml' |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + sbom: |
| 24 | + name: Generate SBOM and Create PR |
| 25 | + runs-on: ubuntu-latest |
| 26 | + concurrency: |
| 27 | + group: sbom-${{ github.ref }} |
| 28 | + cancel-in-progress: false |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + persist-credentials: false |
| 35 | + |
| 36 | + - name: Set up Rust |
| 37 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 38 | + with: |
| 39 | + toolchain: stable |
| 40 | + |
| 41 | + - name: Install cargo-cyclonedx |
| 42 | + run: cargo install cargo-cyclonedx |
| 43 | + |
| 44 | + - name: Generate SBOM |
| 45 | + run: | |
| 46 | + cargo cyclonedx --manifest-path driver/Cargo.toml --spec-version 1.5 -vv --format json --override-filename sbom |
| 47 | + cp driver/sbom.json sbom.json |
| 48 | + # Clean up workspace member SBOMs - we only want the driver SBOM |
| 49 | + rm -f driver/sbom.json macros/sbom.json benchmarks/sbom.json etc/update_version/sbom.json |
| 50 | +
|
| 51 | + - name: Download CycloneDX CLI |
| 52 | + run: | |
| 53 | + curl -L -s -o /tmp/cyclonedx "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v0.29.1/cyclonedx-linux-x64" |
| 54 | + chmod +x /tmp/cyclonedx |
| 55 | +
|
| 56 | + - name: Validate SBOM |
| 57 | + run: /tmp/cyclonedx validate --input-file sbom.json --fail-on-errors |
| 58 | + |
| 59 | + - name: Upload SBOM artifact |
| 60 | + uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: sbom |
| 63 | + path: sbom.json |
| 64 | + if-no-files-found: error |
| 65 | + |
| 66 | + - name: Create Pull Request |
| 67 | + uses: peter-evans/create-pull-request@b4733b9419fd47bbfa1807b15627e17cd70b5b22 |
| 68 | + with: |
| 69 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + commit-message: 'chore: Update SBOM after dependency changes' |
| 71 | + branch: auto-update-sbom-${{ github.run_id }} |
| 72 | + delete-branch: true |
| 73 | + title: 'chore: Update SBOM' |
| 74 | + body: | |
| 75 | + ## Automated SBOM Update |
| 76 | +
|
| 77 | + This PR was automatically generated because dependency manifest files changed. |
| 78 | +
|
| 79 | + ### Changes |
| 80 | + - Updated `sbom.json` to reflect current dependencies |
| 81 | +
|
| 82 | + ### Verification |
| 83 | + The SBOM was generated using cargo-cyclonedx with the current Rust workspace. |
| 84 | +
|
| 85 | + ### Triggered by |
| 86 | + - Commit: ${{ github.sha }} |
| 87 | + - Workflow run: ${{ github.run_id }} |
| 88 | +
|
| 89 | + --- |
| 90 | + _This PR was created automatically by the [SBOM workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})_ |
| 91 | + labels: | |
| 92 | + sbom |
| 93 | + automated |
| 94 | + dependencies |
| 95 | +
|
0 commit comments