From 67eee2895a40e6bd59ef59f5f3bb36877125e017 Mon Sep 17 00:00:00 2001 From: Andrew Morozko Date: Sat, 22 Jun 2024 14:08:46 +0400 Subject: [PATCH] Small fixes (#211) --- .goreleaser-dev.yaml | 19 +++++++++++++++++-- cmd/version.go | 10 +++++++--- plugin/pluginapi/v1/dataspec_decoder.go | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.goreleaser-dev.yaml b/.goreleaser-dev.yaml index 875dec9a..f6227623 100644 --- a/.goreleaser-dev.yaml +++ b/.goreleaser-dev.yaml @@ -8,7 +8,7 @@ env: - CGO_ENABLED=0 snapshot: - name_template: "{{.Tag}}-dev{{if .IsGitDirty}}+dirty{{end}}+rev.{{.FullCommit}}" + name_template: "{{ .Version }}-dev+{{if .IsGitDirty}}dirty.{{end}}rev.{{.FullCommit}}" builds: # CLI @@ -18,7 +18,7 @@ builds: ldflags: - -X github.com/blackstork-io/fabric/cmd.version={{.Version}} - -X github.com/blackstork-io/fabric/cmd.builtBy=goreleaser - + gcflags: all=-N -l no_unique_dist_dir: true # Plugins @@ -27,88 +27,103 @@ builds: main: ./internal/elastic/cmd binary: "plugins/blackstork/elastic@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: github main: ./internal/github/cmd binary: "plugins/blackstork/github@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: graphql main: ./internal/graphql/cmd binary: "plugins/blackstork/graphql@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: openai main: ./internal/openai/cmd binary: "plugins/blackstork/openai@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: opencti main: ./internal/opencti/cmd binary: "plugins/blackstork/opencti@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: nistnvd main: ./internal/nistnvd/cmd binary: "plugins/blackstork/nist_nvd@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: postgresql main: ./internal/postgresql/cmd binary: "plugins/blackstork/postgresql@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: sqlite main: ./internal/sqlite/cmd binary: "plugins/blackstork/sqlite@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: terraform main: ./internal/terraform/cmd binary: "plugins/blackstork/terraform@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: hackerone main: ./internal/hackerone/cmd binary: "plugins/blackstork/hackerone@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: virustotal main: ./internal/virustotal/cmd binary: "plugins/blackstork/virustotal@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: splunk main: ./internal/splunk/cmd binary: "plugins/blackstork/splunk@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: stixview main: ./internal/stixview/cmd binary: "plugins/blackstork/stixview@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: snyk main: ./internal/snyk/cmd binary: "plugins/blackstork/snyk@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true - id: microsoft main: ./internal/microsoft/cmd binary: "plugins/blackstork/microsoft@{{ .Version }}" ldflags: "-X main.version={{.Version}}" + gcflags: all=-N -l no_unique_dist_dir: true diff --git a/cmd/version.go b/cmd/version.go index 81e42ca6..e3e07d42 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -34,25 +34,29 @@ func versionFromBuildInfo() (result string) { return } if info.Main.Version != "(devel)" { - result = info.Main.Version + result = strings.ToLower(info.Main.Version) if !strings.HasPrefix(result, "v") { result = "v" + result } return } + var meta []string // It's a dev version not built by goreleaser, add extra info dirtyIdx := slices.IndexFunc(info.Settings, func(s debug.BuildSetting) bool { return s.Key == "vcs.modified" }) if dirtyIdx != -1 && info.Settings[dirtyIdx].Value == "true" { - result += "+dirty" + meta = append(meta, "dirty") } shaIdx := slices.IndexFunc(info.Settings, func(s debug.BuildSetting) bool { return s.Key == "vcs.revision" }) if shaIdx != -1 { - result = fmt.Sprintf("%s+rev.%s", result, info.Settings[shaIdx].Value) + meta = append(meta, "rev", info.Settings[shaIdx].Value) + } + if len(meta) != 0 { + result += "+" + strings.Join(meta, ".") } return } diff --git a/plugin/pluginapi/v1/dataspec_decoder.go b/plugin/pluginapi/v1/dataspec_decoder.go index 923f9f65..201792dd 100644 --- a/plugin/pluginapi/v1/dataspec_decoder.go +++ b/plugin/pluginapi/v1/dataspec_decoder.go @@ -10,7 +10,7 @@ import ( func decodeRootSpec(src *Spec) (dataspec.RootSpec, error) { sp, err := decodeSpec(src) - if err != nil { + if sp == nil || err != nil { return nil, err } rs, ok := sp.(dataspec.RootSpec)