Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SBOM improvements #4430

Merged
merged 3 commits into from Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/pipe/sbom/sbom.go
Expand Up @@ -72,7 +72,7 @@ func setConfigDefaults(cfg *config.SBOM) error {
}
if cfg.Cmd == "syft" {
if len(cfg.Args) == 0 {
cfg.Args = []string{"$artifact", "--file", "$document", "--output", "spdx-json"}
cfg.Args = []string{"$artifact", "--output", "spdx-json=$document"}
}
if len(cfg.Env) == 0 && (cfg.Artifacts == "source" || cfg.Artifacts == "archive") {
cfg.Env = []string{
Expand Down Expand Up @@ -131,6 +131,9 @@ func catalogTask(ctx *context.Context, cfg config.SBOM) func() error {
filters = append(filters, artifact.ByIDs(cfg.IDs...))
}
artifacts := ctx.Artifacts.Filter(artifact.And(filters...)).List()
if len(artifacts) == 0 {
log.Warn("no artifacts matching current filters")
}
return catalog(ctx, cfg, artifacts)
}
}
Expand Down Expand Up @@ -240,6 +243,10 @@ func catalogArtifact(ctx *context.Context, cfg config.SBOM, a *artifact.Artifact

}

if len(artifacts) == 0 {
return nil, fmt.Errorf("cataloging artifacts: command did not write any files, check your configuration")
}

return artifacts, nil
}

Expand Down
27 changes: 20 additions & 7 deletions internal/pipe/sbom/sbom_test.go
Expand Up @@ -24,7 +24,7 @@ func TestDescription(t *testing.T) {
}

func TestSBOMCatalogDefault(t *testing.T) {
defaultArgs := []string{"$artifact", "--file", "$document", "--output", "spdx-json"}
defaultArgs := []string{"$artifact", "--output", "spdx-json=$document"}
defaultSboms := []string{
"{{ .ArtifactName }}.sbom",
}
Expand Down Expand Up @@ -307,10 +307,8 @@ func TestSBOMCatalogArtifacts(t *testing.T) {
{
Artifacts: "any",
Args: []string{
"--file",
"$document0",
"--output",
"spdx-json",
"spdx-json=$document0",
"artifact5.tar.gz",
},
Documents: []string{
Expand Down Expand Up @@ -377,10 +375,8 @@ func TestSBOMCatalogArtifacts(t *testing.T) {
{
Artifacts: "binary",
Args: []string{
"--file",
"$document",
"--output",
"spdx-json",
"spdx-json=$document",
"$artifact",
},
Documents: []string{
Expand Down Expand Up @@ -413,6 +409,23 @@ func TestSBOMCatalogArtifacts(t *testing.T) {
}),
expectedErrMsg: "cataloging artifacts: false failed: exit status 1: ",
},
{
desc: "catalog wrong command",
ctx: testctx.NewWithCfg(config.Project{
SBOMs: []config.SBOM{
{Args: []string{"$artifact", "--file", "$sbom", "--output", "spdx-json"}},
},
}),
expectedErrMsg: "cataloging artifacts: command did not write any files, check your configuration",
},
{
desc: "no matches",
ctx: testctx.NewWithCfg(config.Project{
SBOMs: []config.SBOM{
{IDs: []string{"nopenopenope"}},
},
}),
},
}

for _, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions www/docs/customization/sbom.md
Expand Up @@ -63,9 +63,9 @@ sboms:

# Command line arguments for the command
#
# Default: ["$artifact", "--file", "$document", "--output", "spdx-json"]
# Default: ["$artifact", "--output", "spdx-json=$document"]
# Templates: allowed
args: ["$artifact", "--file", "$sbom", "--output", "spdx-json"]
args: ["$artifact", "--output", "cyclonedx-json:$document"]

# List of environment variables that will be passed to the SBOM command as
# well as the templates.
Expand Down