Skip to content
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
8 changes: 6 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ jobs:
with:
persist-credentials: false

- name: Resolve Go versions
id: go-versions
uses: carabiner-dev/actions/go/versions@32587e82f960d49b36101e8c45d1956e511965d3 # v1.2.9

- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.25'
go-version: ${{ steps.go-versions.outputs.GO_VERSION_STABLE }}
check-latest: true
cache: false

- name: Run golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
version: v2.7
version: v2.13
9 changes: 7 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ jobs:
with:
fetch-depth: 1

- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
- name: Resolve Go versions
id: go-versions
uses: carabiner-dev/actions/go/versions@32587e82f960d49b36101e8c45d1956e511965d3 # v1.2.9

- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.25'
go-version: ${{ steps.go-versions.outputs.GO_VERSION_STABLE }}
check-latest: true
cache: false

Expand Down
65 changes: 57 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ on:
permissions: {}

jobs:
go-versions:
name: resolve go versions
runs-on: ubuntu-latest

permissions:
contents: read

outputs:
stable: ${{ steps.versions.outputs.GO_MINOR_VERSION_STABLE }}
previous: ${{ steps.versions.outputs.GO_MINOR_VERSION_PREVIOUS }}

steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Determine Go versions
id: versions
uses: carabiner-dev/actions/go/versions@32587e82f960d49b36101e8c45d1956e511965d3 # v1.2.9

changes:
name: detect changes
runs-on: ubuntu-latest
Expand Down Expand Up @@ -70,10 +91,20 @@ jobs:
echo "clickhouse=${clickhouse}" >> "${GITHUB_OUTPUT}"

test:
needs: changes
name: unit (go ${{ matrix.go-version }})
needs:
- changes
- go-versions
if: ${{ needs.changes.outputs.ent == 'true' }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
go-version:
- ${{ needs.go-versions.outputs.previous }}
- ${{ needs.go-versions.outputs.stable }}

permissions:
contents: read

Expand All @@ -86,19 +117,28 @@ jobs:
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.25'
go-version: ${{ matrix.go-version }}
check-latest: true
cache: false

- name: Run tests
run: make test-unit

gcs:
name: gcs integration
needs: changes
name: gcs integration (go ${{ matrix.go-version }})
needs:
- changes
- go-versions
if: ${{ needs.changes.outputs.gcs == 'true' }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
go-version:
- ${{ needs.go-versions.outputs.previous }}
- ${{ needs.go-versions.outputs.stable }}

permissions:
contents: read

Expand All @@ -111,7 +151,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.25'
go-version: ${{ matrix.go-version }}
check-latest: true
cache: false

Expand All @@ -134,11 +174,20 @@ jobs:
run: make test-gcs

clickhouse:
name: clickhouse integration
needs: changes
name: clickhouse integration (go ${{ matrix.go-version }})
needs:
- changes
- go-versions
if: ${{ needs.changes.outputs.clickhouse == 'true' }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
go-version:
- ${{ needs.go-versions.outputs.previous }}
- ${{ needs.go-versions.outputs.stable }}

permissions:
contents: read

Expand All @@ -165,7 +214,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.25'
go-version: ${{ matrix.go-version }}
check-latest: true
cache: false

Expand Down
8 changes: 6 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ linters:
- godox
- goheader
- gomoddirectives
- gomodguard
- gomodguard_v2
- goprintffuncname
- gosec
- govet
Expand Down Expand Up @@ -63,7 +63,7 @@ linters:
- wastedassign
- whitespace
- wrapcheck
- wsl
- wsl_v5
settings:
errcheck:
check-type-assertions: true
Expand Down Expand Up @@ -161,6 +161,10 @@ linters:
- fn
- id
- tx
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
exclusions:
generated: lax
presets:
Expand Down
11 changes: 9 additions & 2 deletions backends/clickhouse/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"os"

"github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
Expand Down Expand Up @@ -53,7 +55,7 @@ func (backend *Backend) Conn() driver.Conn {
// clickhouseOptions builds the driver options for a connection to the given
// database using the backend's configured address, credentials and settings.
func (backend *Backend) clickhouseOptions(database string) *clickhouse.Options {
return &clickhouse.Options{
opts := &clickhouse.Options{
Addr: backend.Options.Addr,
Auth: clickhouse.Auth{
Database: database,
Expand All @@ -62,8 +64,13 @@ func (backend *Backend) clickhouseOptions(database string) *clickhouse.Options {
},
TLS: backend.Options.TLS,
Settings: clickhouse.Settings(backend.Options.Settings),
Debug: backend.Options.Debug,
}

if backend.Options.Debug {
opts.Logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
}

return opts
}

// InitClient connects to ClickHouse, ensures the target database exists and
Expand Down
24 changes: 13 additions & 11 deletions backends/ent/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (as *annotationsSuite) TestBackend_AddNodeAnnotations() {

func (as *annotationsSuite) TestBackend_AddAnnotationToDocuments() {
annotationName := "add_annotation_to_documents_test"
documentIDs := []string{}
documentIDs := make([]string, 0, len(as.documents))

for _, document := range as.documents {
documentIDs = append(documentIDs, document.GetMetadata().GetId())
Expand All @@ -127,8 +127,8 @@ func (as *annotationsSuite) TestBackend_AddAnnotationToDocuments() {

func (as *annotationsSuite) TestBackend_AddAnnotationToNodes() {
annotationName := "add_annotation_to_documents_test"
nodeIDs := []string{}
nodeUUIDs := []uuid.UUID{}
nodeIDs := make([]string, 0, len(as.documents))
nodeUUIDs := make([]uuid.UUID, 0, len(as.documents))

for _, document := range as.documents {
uniqueID, err := ent.GenerateUUID(document.GetNodeList().GetNodes()[0])
Expand All @@ -152,7 +152,7 @@ func (as *annotationsSuite) TestBackend_AddAnnotationToNodes() {

func (as *annotationsSuite) TestBackend_ClearDocumentAnnotations() {
annotationName := "clear_document_annotations_test"
documentIDs := []string{}
documentIDs := make([]string, 0, len(as.documents))

as.Require().NoError(as.AddAnnotationToDocuments(annotationName, "test-value", documentIDs...))

Expand All @@ -169,7 +169,7 @@ func (as *annotationsSuite) TestBackend_ClearDocumentAnnotations() {

func (as *annotationsSuite) TestBackend_ClearNodeAnnotations() {
annotationName := "clear_node_annotations_test"
nodeIDs := []string{}
nodeIDs := make([]string, 0, len(as.nodes))

as.Require().NoError(as.AddAnnotationToNodes(annotationName, "test-node-value", nodeIDs...))

Expand Down Expand Up @@ -429,9 +429,10 @@ func (as *annotationsSuite) TestBackend_RemoveDocumentAnnotations() {

as.Require().NoError(as.RemoveDocumentAnnotations(documentID, annotationName, subtest.values...))

values := []string{}
annotations := as.getTestResult(annotationName)
values := make([]string, 0, len(annotations))

for _, annotation := range as.getTestResult(annotationName) {
for _, annotation := range annotations {
values = append(values, annotation.Value)
}

Expand Down Expand Up @@ -482,9 +483,10 @@ func (as *annotationsSuite) TestBackend_RemoveNodeAnnotations() {

as.Require().NoError(as.RemoveNodeAnnotations(as.nodes[0].GetId(), annotationName, subtest.values...))

values := []string{}
annotations := as.getTestResult(annotationName)
values := make([]string, 0, len(annotations))

for _, annotation := range as.getTestResult(annotationName) {
for _, annotation := range annotations {
values = append(values, annotation.Value)
}

Expand All @@ -501,7 +503,7 @@ func (as *annotationsSuite) TestBackend_SetDocumentAnnotations() {

validateResults := func(name string, expected []string) {
annotations := as.getTestResult(name)
values := []string{}
values := make([]string, 0, len(annotations))

for _, annotation := range annotations {
values = append(values, annotation.Value)
Expand Down Expand Up @@ -534,7 +536,7 @@ func (as *annotationsSuite) TestBackend_SetNodeAnnotations() {

validateResults := func(name string, expected []string) {
annotations := as.getTestResult(name)
values := []string{}
values := make([]string, 0, len(annotations))

for _, annotation := range annotations {
values = append(values, annotation.Value)
Expand Down
16 changes: 8 additions & 8 deletions backends/ent/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (backend *Backend) Store(doc *sbom.Document, opts *storage.StoreOptions) er

func (backend *Backend) saveAnnotations(annotations ...*ent.Annotation) TxFunc {
return func(tx *ent.Tx) error {
builders := []*ent.AnnotationCreate{}
builders := make([]*ent.AnnotationCreate, 0, len(annotations))

for idx := range annotations {
builder := tx.Annotation.Create().
Expand Down Expand Up @@ -121,8 +121,8 @@ func (backend *Backend) saveDocumentTypes(docTypes []*sbom.DocumentType, opts ..
newDocType := tx.DocumentType.Create().
SetProtoMessage(docType).
SetNillableType(&typeName).
SetNillableName(docType.Name). //nolint:protogetter
SetNillableDescription(docType.Description) //nolint:protogetter
SetNillableName(docType.Name).
SetNillableDescription(docType.Description)

for _, fn := range opts {
fn(newDocType)
Expand Down Expand Up @@ -219,7 +219,7 @@ func (backend *Backend) saveExternalReferences(refs []*sbom.ExternalReference, o

func (backend *Backend) saveHashes(hashes map[int32]string, opts ...func(*ent.HashesEntryCreate)) TxFunc {
return func(tx *ent.Tx) error {
builders := []*ent.HashesEntryCreate{}
builders := make([]*ent.HashesEntryCreate, 0, len(hashes))

for key, value := range hashes {
alg := sbom.HashAlgorithm(key)
Expand Down Expand Up @@ -248,7 +248,7 @@ func (backend *Backend) saveHashes(hashes map[int32]string, opts ...func(*ent.Ha

func (backend *Backend) saveIdentifiers(idents map[int32]string, opts ...func(*ent.IdentifiersEntryCreate)) TxFunc {
return func(tx *ent.Tx) error {
builders := []*ent.IdentifiersEntryCreate{}
builders := make([]*ent.IdentifiersEntryCreate, 0, len(idents))

for key, value := range idents {
identType := sbom.SoftwareIdentifierType(key)
Expand Down Expand Up @@ -499,7 +499,7 @@ func (backend *Backend) savePersons(persons []*sbom.Person, opts ...func(*ent.Pe

func (backend *Backend) saveProperties(properties []*sbom.Property, opts ...func(*ent.PropertyCreate)) TxFunc {
return func(tx *ent.Tx) error {
builders := []*ent.PropertyCreate{}
builders := make([]*ent.PropertyCreate, 0, len(properties))

for _, prop := range properties {
newProp := tx.Property.Create().
Expand Down Expand Up @@ -528,7 +528,7 @@ func (backend *Backend) saveProperties(properties []*sbom.Property, opts ...func

func (backend *Backend) savePurposes(purposes []sbom.Purpose, opts ...func(*ent.PurposeCreate)) TxFunc {
return func(tx *ent.Tx) error {
builders := []*ent.PurposeCreate{}
builders := make([]*ent.PurposeCreate, 0, len(purposes))

for idx := range purposes {
newPurpose := tx.Purpose.Create().
Expand Down Expand Up @@ -581,7 +581,7 @@ func (backend *Backend) saveSourceData(sourceData *sbom.SourceData, opts ...func

func (backend *Backend) saveTools(tools []*sbom.Tool, opts ...func(*ent.ToolCreate)) TxFunc {
return func(tx *ent.Tx) error {
builders := []*ent.ToolCreate{}
builders := make([]*ent.ToolCreate, 0, len(tools))

for _, tool := range tools {
newTool := tx.Tool.Create().
Expand Down
2 changes: 1 addition & 1 deletion backends/ent/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (ss *storeSuite) AfterTest(_suiteName, _testName string) {
}

func (ss *storeSuite) TestBackend_Store() {
messages := [][]byte{}
messages := make([][]byte, 0, len(ss.documents))

for _, document := range ss.documents {
msg, err := proto.MarshalOptions{Deterministic: true}.Marshal(document)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/protobom/storage

go 1.25.11
go 1.26.0

require (
cloud.google.com/go/storage v1.67.0
Expand All @@ -10,7 +10,7 @@ require (
github.com/google/uuid v1.6.0
github.com/protobom/protobom v0.6.0
github.com/stretchr/testify v1.12.1
google.golang.org/api v0.295.0
google.golang.org/api v0.297.0
google.golang.org/protobuf v1.36.12
)

Expand Down
Loading