Skip to content

Commit

Permalink
set release version (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazegusuri authored Mar 7, 2023
1 parent b4a77e3 commit d04d088
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/bin/*

dist/
34 changes: 34 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
ldflags:
- -s -w -X github.com/cloudspannerecosystem/wrench/cmd.version={{.Version}}
ignore:
- goos: darwin
goarch: 386

archives:
- format: tar.gz
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
2 changes: 1 addition & 1 deletion cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Error struct {
}

func (e *Error) Error() string {
return fmt.Sprintf("Error command: %s, version: %s", e.cmd.Name(), Version)
return fmt.Sprintf("Error command: %s, version: %s", e.cmd.Name(), versionInfo())
}

func (e *Error) Unwrap() error {
Expand Down
18 changes: 16 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ package cmd
import (
"context"
"os"
"runtime/debug"
"time"

"github.com/spf13/cobra"
)

var (
Version = "unknown"
version = ""
versionTemplate = `{{.Version}}
`
)
Expand Down Expand Up @@ -74,7 +75,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&credentialsFile, flagCredentialsFile, "", "Specify Credentials File")
rootCmd.PersistentFlags().DurationVar(&timeout, flagTimeout, time.Hour, "Context timeout")

rootCmd.Version = Version
rootCmd.Version = versionInfo()
rootCmd.SetVersionTemplate(versionTemplate)
}

Expand All @@ -93,3 +94,16 @@ func spannerInstanceID() string {
func spannerDatabaseID() string {
return os.Getenv("SPANNER_DATABASE_ID")
}

func versionInfo() string {
if version != "" {
return version
}

// For those who "go install" yo
info, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
return info.Main.Version
}

0 comments on commit d04d088

Please sign in to comment.