Skip to content

Commit

Permalink
feat: integrate sbom generation to goreleaser (#1850)
Browse files Browse the repository at this point in the history
Co-authored-by: hackerman <[email protected]>
  • Loading branch information
tricky42 and aeneasr authored Nov 2, 2021
1 parent 8c8815b commit 305bb28
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
33 changes: 29 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ before:
hooks:
- go mod download
- go mod tidy
- go install github.com/CycloneDX/[email protected]

builds:
-
Expand All @@ -28,8 +29,11 @@ builds:
- amd64
goos:
- darwin
hooks:
post:
- cmd: cyclonedx-gomod app -licenses -json -output "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"
- cmd: ./.releaser/rename.sh "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"
-

id: kratos-sqlite-darwin-arm
flags:
- -tags
Expand All @@ -46,7 +50,10 @@ builds:
- arm64
goos:
- darwin

hooks:
post:
- cmd: cyclonedx-gomod app -licenses -json -output "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"
- cmd: ./.releaser/rename.sh "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"
-
id: kratos-sqlite-linux
flags:
Expand All @@ -61,7 +68,10 @@ builds:
- amd64
goos:
- linux

hooks:
post:
- cmd: cyclonedx-gomod app -licenses -json -output "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"
- cmd: ./.releaser/rename.sh "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"
-
id: kratos-sqlite-linux-libmusl
flags:
Expand All @@ -77,7 +87,10 @@ builds:
- amd64
goos:
- linux

hooks:
post:
- cmd: cyclonedx-gomod app -licenses -json -output "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite-libmusl_{{ .Target }}.bom.json"
- cmd: ./.releaser/rename.sh "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite-libmusl_{{ .Target }}.bom.json"
-
id: kratos-sqlite-windows
flags:
Expand All @@ -97,6 +110,10 @@ builds:
- amd64
goos:
- windows
hooks:
post:
- cmd: cyclonedx-gomod app -licenses -json -output "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"
- cmd: ./.releaser/rename.sh "./dist/{{ .ProjectName }}_{{ .Version }}-sqlite_{{ .Target }}.bom.json"

-
id: kratos
Expand All @@ -118,6 +135,10 @@ builds:
- linux
- windows
- darwin
hooks:
post:
- cmd: cyclonedx-gomod app -licenses -json -output "./dist/{{ .ProjectName }}_{{ .Version }}_{{ .Target }}.bom.json"
- cmd: ./.releaser/rename.sh "./dist/{{ .ProjectName }}_{{ .Version }}_{{ .Target }}.bom.json"

archives:
- id: kratos-sqlite
Expand Down Expand Up @@ -215,6 +236,8 @@ scoop:

checksum:
algorithm: sha256
extra_files:
- glob: ./dist/*.bom.json

dockers:
- dockerfile: .docker/Dockerfile-sqlite
Expand Down Expand Up @@ -245,3 +268,5 @@ release:
- kratos-sqlite
- kratos-sqlite-libmusl
- kratos
extra_files:
- glob: ./dist/*.bom.json
20 changes: 20 additions & 0 deletions .releaser/rename.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# workaround script as goreleaser doesnt support 'replacements' in builds section
# needed to adjust cyclonedx-gomod sbom files to match archive file names
# https://github.com/goreleaser/goreleaser/issues/2617
filename=$1
filename_adjusted=${filename//darwin/macos}
filename_adjusted=${filename_adjusted//386/32bit}
filename_adjusted=${filename_adjusted//amd64/64bit}
filename_adjusted=${filename_adjusted//arm_5/arm32v5}
filename_adjusted=${filename_adjusted//arm_6/arm32v6}
filename_adjusted=${filename_adjusted//arm_7/arm32v7}

if [ "$filename" != "$filename_adjusted" ]; then
echo "Renaming '$filename' to '$filename_adjusted' ..."
mv "$filename" "$filename_adjusted"
else
echo "Skipping file '$filename' ..."
fi

0 comments on commit 305bb28

Please sign in to comment.