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

fix: upgrade golang to 1.21.x and also golangci-lint #63

Merged
merged 1 commit into from
Feb 20, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.20"]
go-version: ["1.21"]
os: ["linux"]
arch: ["amd64"]
steps:
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.20"]
go-version: ["1.21"]
os: ["linux"]
arch: ["amd64"]
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install go
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.21.x
- name: Check out source code
uses: actions/checkout@v3
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.21'
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.51.2
version: v1.56.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HAS
BINDIR=bin
TOOLSDIR := $(shell pwd)/hack/tools
GOLINTER := $(TOOLSDIR)/bin/golangci-lint
GOLINTER_VERSION := v1.52.2
GOLINTER_VERSION := v1.56.2

# OCI registry
ZOT := $(TOOLSDIR)/bin/zot
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module stackerbuild.io/stacker-bom

go 1.20
go 1.21.0

toolchain go1.21.6

require (
github.com/anchore/syft v0.90.0
Expand Down
28 changes: 28 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion golangcilint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ run:

linters:
enable-all: true
disable: funlen,gocognit,exhaustivestruct,paralleltest,forbidigo,ireturn,wrapcheck,exhaustive,maintidx,exhaustruct,nosnakecase,interfacer,structcheck,varcheck,deadcode,ifshort,golint,scopelint,maligned,rowserrcheck,sqlclosecheck,tagliatelle
disable: funlen,gocognit,exhaustivestruct,paralleltest,forbidigo,ireturn,wrapcheck,exhaustive,maintidx,exhaustruct,nosnakecase,interfacer,structcheck,varcheck,deadcode,ifshort,golint,scopelint,maligned,rowserrcheck,sqlclosecheck,tagliatelle,depguard,tagalign,revive

linters-settings:
dupl:
Expand Down
5 changes: 3 additions & 2 deletions pkg/bom/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewDocument(author, organization string) *spdx.Document {
doc := spdx.NewDocument()
doc.Creator.Person = author
doc.Creator.Organization = organization
doc.Creator.Tool = []string{fmt.Sprintf("stackerbuild.io/sbom@%s", buildgen.Commit)}
doc.Creator.Tool = []string{"stackerbuild.io/sbom@" + buildgen.Commit}

return doc
}
Expand Down Expand Up @@ -55,7 +55,7 @@ func MergeDocuments(dir, namespace, name, author, organization, output string) e
sdoc.Name = name
sdoc.Creator.Person = author
sdoc.Creator.Organization = organization
sdoc.Creator.Tool = []string{fmt.Sprintf("stackerbuild.io/stacker-bom@%s", buildgen.Commit)}
sdoc.Creator.Tool = []string{"stackerbuild.io/stacker-bom@" + buildgen.Commit}

mcount := 0

Expand All @@ -79,6 +79,7 @@ func MergeDocuments(dir, namespace, name, author, organization, output string) e
sdoc.Packages = MergeMaps(sdoc.Packages, doc.Packages)

log.Info().Str("path", path).Msg("file found for merging")

mcount++

return nil
Expand Down
9 changes: 4 additions & 5 deletions pkg/distro/apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -73,7 +72,7 @@ func ParsePackage(input, output, author, organization, license string) error {
sdoc.Creator.Person = author
sdoc.Creator.Organization = organization
sdoc.Creator.Tool = []string{"stackerbuild.io/sbom"}
sdoc.Creator.Tool = []string{fmt.Sprintf("stackerbuild.io/sbom@%s", buildgen.Commit)}
sdoc.Creator.Tool = []string{"stackerbuild.io/sbom@" + buildgen.Commit}

var pkglicense string

Expand Down Expand Up @@ -158,12 +157,12 @@ func ParsePackage(input, output, author, organization, license string) error {

log.Info().Str("name", hdr.Name).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

sfile := &spdx.File{
Entity: spdx.Entity{
Name: fmt.Sprintf("/%s", hdr.Name),
Name: "/" + hdr.Name,
Checksum: map[string]string{
"SHA1": hex.EncodeToString(cksumSHA1[:]),
"SHA256": hex.EncodeToString(cksumSHA256[:]),
Expand Down Expand Up @@ -246,7 +245,7 @@ func InstalledPackage(doc *spdx.Document, pkg *IndexEntry, files []string) error

log.Info().Str("name", info.Name()).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

sfile := spdx.NewFile()
Expand Down
7 changes: 4 additions & 3 deletions pkg/distro/deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ParsePackage(input, output, author, organization, license string) error {
sdoc.Creator.Person = author
sdoc.Creator.Organization = organization
sdoc.Creator.Tool = []string{"stackerbuild.io/sbom"}
sdoc.Creator.Tool = []string{fmt.Sprintf("stackerbuild.io/sbom@%s", buildgen.Commit)}
sdoc.Creator.Tool = []string{"stackerbuild.io/sbom@" + buildgen.Commit}

spkg := &spdx.Package{
Entity: spdx.Entity{
Expand Down Expand Up @@ -96,7 +96,7 @@ func ParsePackage(input, output, author, organization, license string) error {

log.Info().Str("name", hdr.Name).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

sfile := &spdx.File{
Expand Down Expand Up @@ -221,6 +221,7 @@ func InstalledPackages(doc *spdx.Document) error {
rgxp := regexp.MustCompile(`^(?P<Key>[a-zA-Z-]+?):\s*(?P<Value>.*)$`)
params := rgxp.FindStringSubmatch(line)
key := params[rgxp.SubexpIndex("Key")]

if rgxp.SubexpIndex("Value") < 0 {
lastkey = key
} else {
Expand Down Expand Up @@ -349,7 +350,7 @@ func InstalledPackage(doc *spdx.Document, pkg Package, path string) error {

log.Info().Str("name", info.Name()).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

sfile := spdx.NewFile()
Expand Down
7 changes: 3 additions & 4 deletions pkg/distro/rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
"os"
"strings"
Expand Down Expand Up @@ -74,7 +73,7 @@ func ParsePackage(input, output, author, organization, license string) error {
sdoc.Creator.Person = author
sdoc.Creator.Organization = organization
sdoc.Creator.Tool = []string{"stackerbuild.io/sbom"}
sdoc.Creator.Tool = []string{fmt.Sprintf("stackerbuild.io/sbom@%s", buildgen.Commit)}
sdoc.Creator.Tool = []string{"stackerbuild.io/sbom@" + buildgen.Commit}

spkg := &spdx.Package{
Entity: spdx.Entity{
Expand Down Expand Up @@ -139,7 +138,7 @@ func ParsePackage(input, output, author, organization, license string) error {

log.Info().Str("name", info.Name()).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

sfile := spdx.NewFile()
Expand Down Expand Up @@ -232,7 +231,7 @@ func InstalledPackage(doc *spdx.Document, pkg *rpmdb.PackageInfo) error {

log.Info().Str("name", info.Name()).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

sfile := spdx.NewFile()
Expand Down
10 changes: 5 additions & 5 deletions pkg/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/sha1" //nolint:gosec // used only to produce the sha1 checksum field
"encoding/hex"
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -82,7 +81,7 @@ func BuildPackageFromDir(input string, kdoc *k8spdx.Document, kpkg *k8spdx.Packa

for _, tpkg := range sdoc.Packages {
p := stbom.ConvertFromSyftPackage(tpkg)
p.SetSPDXID(fmt.Sprintf("SPDXRef-%s", p.SPDXID()))
p.SetSPDXID("SPDXRef-" + p.SPDXID())
p.LicenseConcluded = license
p.LicenseDeclared = license
tpkgs[p.SPDXID()] = p
Expand Down Expand Up @@ -135,7 +134,7 @@ func BuildPackageFromDir(input string, kdoc *k8spdx.Document, kpkg *k8spdx.Packa

log.Info().Str("name", info.Name()).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

kfile := k8spdx.NewFile()
Expand All @@ -149,6 +148,7 @@ func BuildPackageFromDir(input string, kdoc *k8spdx.Document, kpkg *k8spdx.Packa
},
)
kfile.LicenseInfoInFile = license

if err := kpkg.AddFile(kfile); err != nil {
log.Error().Err(err).Msg("unable to add file to package")

Expand Down Expand Up @@ -279,7 +279,7 @@ func BuildPackageFromFile(input string, kpkg *k8spdx.Package, license string) er

log.Info().Str("name", ifo.Name()).
Int("size", bufsz).
Str("cksum", fmt.Sprintf("SHA256:%s", hex.EncodeToString(cksumSHA256[:]))).
Str("cksum", "SHA256:"+hex.EncodeToString(cksumSHA256[:])).
Msg("file entry detected")

kfile := k8spdx.NewFile()
Expand Down Expand Up @@ -309,7 +309,7 @@ func BuildPackage(name, author, organization, license,
kdoc.Name = name
kdoc.Creator.Person = author
kdoc.Creator.Organization = organization
kdoc.Creator.Tool = []string{fmt.Sprintf("stackerbuild.io/sbom@%s", buildgen.Commit)}
kdoc.Creator.Tool = []string{"stackerbuild.io/sbom@" + buildgen.Commit}

kpkg := &k8spdx.Package{
Entity: k8spdx.Entity{
Expand Down
2 changes: 2 additions & 0 deletions pkg/fs/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ func Verify(input, inventory, missing string) error {

if err := checkBOM(input, entry.Path); err != nil {
log.Error().Err(err).Str("path", entry.Path).Msg("inventory verify failed")

mcount++

sfile := spdx.NewFile()
sfile.SetEntity(
&spdx.Entity{
Expand Down
Loading