How to generate an SBOM in GitHub Actions
By SBOMBox SBOM experts · · Updated · 4 min readShort answer: add a job that runs an SBOM generator on every push or release and keeps the file. The most common choice is anchore/sbom-action, which runs Syft and writes CycloneDX or SPDX JSON. Add actions/attest to sign it, or use the SBOMBox Action to generate, score, check and store it in one step without secrets. Generate from what you ship: the built container image or package, not just the repository.
Option 1: Syft with anchore/sbom-action
The quickest start. It scans the checkout (or an image) and uploads the SBOM as a workflow artifact:
name: SBOM
on:
push:
branches: [main]
release:
types: [published]
permissions:
contents: read
jobs:
sbom:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: anchore/sbom-action@v0
with:
path: .
format: cyclonedx-json
output-file: sbom.cdx.json
artifact-name: sbom.cdx.jsonTo scan a container image instead, replace path with image: ghcr.io/your-org/your-app:${{ github.sha }} after the build step. Why that matters is covered in container image SBOMs. For other generators, see Syft vs Trivy vs cdxgen.
Option 2: GitHub's dependency graph export
If the dependency graph is enabled, GitHub can export an SPDX SBOM of the repository's declared dependencies through its REST API:
gh api /repos/OWNER/REPO/dependency-graph/sbom --jq .sbom > sbom.spdx.jsonIt is convenient for a quick inventory, but it reflects manifests and lock files in the repository, not the artifact you build. Treat it as a starting point, not release evidence.
Option 3: sign the SBOM with an attestation
An SBOM a customer cannot verify is easy to doubt. actions/attest, given an sbom-path, binds the SBOM to the artifact it describes with a signed attestation stored by GitHub. (It replaces actions/attest-sbom, which is now a deprecated wrapper around it.) The job needs id-token: write, attestations: write and artifact-metadata: write:
permissions:
contents: read
id-token: write
attestations: write
artifact-metadata: write
steps:
# ... build dist/app.tar.gz and generate sbom.spdx.json ...
- uses: actions/attest@v4
with:
subject-path: dist/app.tar.gz
sbom-path: sbom.spdx.jsonCheck each action's README for its current major version before you pin it. More on signing in SBOM signing and provenance.
Option 4: the SBOMBox Action
The SBOMBox Action generates the SBOM, scores it, checks it against compliance rulesets such as cra-readiness or cisa-2026, and uploads it with the verified repository, commit and run attached. It signs in with the workflow's own OIDC identity, so there is no secret to store:
permissions:
contents: read
id-token: write
jobs:
sbom:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: sbombox/action@v1
with:
project: your-project-id
profiles: cra-readiness,cisa-2026
fail-under: "7"Every input and output is in the GitHub Action docs.
Which option to choose
| Option | Best for | Signed | Quality check | Stored per release |
|---|---|---|---|---|
| anchore/sbom-action | Quick start, containers | No (add actions/attest) | No | As a workflow artifact (expires) |
| Dependency graph export | A fast inventory of declared dependencies | No | No | No |
| actions/attest | Proving the SBOM matches the artifact | Yes | No | As a GitHub attestation |
| sbombox/action | Compliance evidence per release | Provenance recorded on upload | Yes: score and rulesets | Yes, with history and monitoring |
Mistakes to avoid
- Generating only on pull requests. Generate on the commit or tag you release, so the SBOM matches what shipped.
- Relying on workflow artifacts as your archive. They expire; regulators and customers may ask about a release years later.
- Scanning the repository when you ship a container. The image contains OS packages the repository never mentions.
- Never checking quality. Missing versions, purls and hashes make an SBOM useless for vulnerability matching. Run it through the free SBOM checker.
Frequently asked questions
How do I generate an SBOM in GitHub Actions?
Add a job that runs an SBOM generator such as Syft (through anchore/sbom-action) on push or release, writes CycloneDX or SPDX JSON, and keeps the file as an artifact or uploads it to an SBOM platform.
Can GitHub generate an SBOM automatically?
Yes. With the dependency graph enabled, GitHub can export an SPDX SBOM of declared dependencies from the repository's Insights tab or through the REST API. It does not include components that only appear in the built artifact.
Should the SBOM be CycloneDX or SPDX?
Either meets current regulations. Pick the one your customers and tools expect; see CycloneDX vs SPDX.
How do I sign an SBOM in GitHub Actions?
Use actions/attest with the artifact as the subject and the SBOM as sbom-path. It creates a signed attestation linking the SBOM to that artifact. The job needs id-token: write, attestations: write and artifact-metadata: write permissions.