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

Add SBOM format flag to publish-release #3020

Merged
merged 2 commits into from
May 31, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/publish-release/cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type githubPageCmdLineOptions struct {
noupdate bool
draft bool
sbom bool
sbomFormat string
name string
repo string
template string
Expand Down Expand Up @@ -150,14 +151,18 @@ func init() {
true,
"Generate an SPDX bill of materials and attach it to the release",
)

githubPageCmd.PersistentFlags().StringVar(
&ghPageOpts.sbomFormat,
"sbom-format",
string(announce.FormatJSON),
"format to use for the SBOM [json|tag-value]",
)
githubPageCmd.PersistentFlags().StringVar(
&ghPageOpts.repoPath,
"repo-path",
".",
"Path to the source code repository",
)

githubPageCmd.PersistentFlags().StringVar(
&ghPageOpts.ReleaseNotesFile,
"release-notes-file",
Expand Down Expand Up @@ -278,6 +283,7 @@ func runGithubPage(opts *githubPageCmdLineOptions) (err error) {
RepoDirectory: opts.repoPath,
Assets: assets,
Tag: commandLineOpts.tag,
Format: announce.SBOMFormat(opts.sbomFormat),
})
if err != nil {
return fmt.Errorf("generating sbom: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions compile-release-tools
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ RELEASE_TOOLS=(
krel
kubepkg
schedule-builder
publish-release
release-notes
)

setup_env() {
Expand Down
28 changes: 26 additions & 2 deletions pkg/announce/github_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/sirupsen/logrus"

"sigs.k8s.io/bom/pkg/serialize"
"sigs.k8s.io/bom/pkg/spdx"
"sigs.k8s.io/release-sdk/git"
"sigs.k8s.io/release-sdk/github"
Expand Down Expand Up @@ -104,11 +105,19 @@ type GitHubPageOptions struct {
Substitutions map[string]string
}

type SBOMFormat string

const (
FormatJSON SBOMFormat = "json"
FormatTagValue SBOMFormat = "tag-value"
)

type SBOMOptions struct {
ReleaseName string
Repo string
RepoDirectory string
Tag string // Version Tag
Tag string // Version Tag
Format SBOMFormat // "tag-value" | "json"
Assets []Asset
}

Expand Down Expand Up @@ -169,7 +178,22 @@ func GenerateReleaseSBOM(opts *SBOMOptions) (string, error) {
}
}

if err := doc.Write(sbomFile); err != nil {
var renderer serialize.Serializer
switch opts.Format {
case FormatJSON:
renderer = &serialize.JSON{}
case FormatTagValue:
renderer = &serialize.TagValue{}
default:
return "", fmt.Errorf("invalid SBOM format, must be one of %s, %s", FormatJSON, FormatTagValue)
}

markup, err := renderer.Serialize(doc)
if err != nil {
return "", fmt.Errorf("serializing sbom: %w", err)
}

if err := os.WriteFile(sbomFile, []byte(markup), 0o600); err != nil {
return "", fmt.Errorf("writing sbom to disk: %w", err)
}

Expand Down