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
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ builds:
mod_timestamp: "{{ .CommitTimestamp }}"
ldflags:
- -s -w
- -X main.Version={{.Version}}

archives:
- formats: tar.gz
Expand Down
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"runtime"
"runtime/debug"
"runtime/pprof"
"slices"
"sort"
Expand Down Expand Up @@ -42,6 +43,17 @@ const (
zeroOIDSHA256 = "0000000000000000000000000000000000000000000000000000000000000000"
)

var Version = "dev"

func init() {
if Version != "dev" {
return
}
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Version != "" && bi.Main.Version != "(devel)" {
Version = bi.Main.Version
}
}

var (
cpuProfile = newOption("")
memProfile = newOption("")
Expand Down Expand Up @@ -69,6 +81,7 @@ func newRootCommand() *cobra.Command {
root := &cobra.Command{
Use: "git-spdx",
Short: "Find license changes across Git history",
Version: Version,
SilenceErrors: true,
SilenceUsage: true,
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
Expand Down
7 changes: 7 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ func cli(t *testing.T, args ...string) string {
return string(out)
}

func TestCLIVersion(t *testing.T) {
out := cli(t, "--version")
if !strings.HasPrefix(out, "git-spdx version ") {
t.Fatalf("--version output = %q", out)
}
}

func TestCLI(t *testing.T) {
repo := repository(t)
commitFile(t, repo, "source.go", "// SPDX-License-Identifier: MIT\npackage example\n", "Add source")
Expand Down