From 55cb29f4c6c3a473f98b498e41fc21ca424a6497 Mon Sep 17 00:00:00 2001 From: jchappelow <140431406+jchappelow@users.noreply.github.com> Date: Thu, 28 Sep 2023 18:27:26 -0500 Subject: [PATCH] update version string to 0.6.0 (#325) * update version string to 0.6.0 Also: - Set the full version string to 0.6.0-rc.1, specifying prerelease. The release should have the format 0.6.0+release. - Add logic to the init function in the internal/pkg/version package so that it will use any compile-time set KwilVersion without decorating it with VCS info to prevent it from looking like kwild version 0.6.0-rc.1+d74a0af8d.dirty. This is desirable for local and/or dev builds, but we want the binaries we ship to just say kwild version 0.6.0+release or kwil-cli version 0.6.0-rc.1 etc. * kwil-cli: update to use internal/pkg/version This updates kwil-cli to use the new internal/pkg/version, which uses the version controls system info available in the runtime/debug standard library package. * build all three binaries * 0.6.0-beta --- .goreleaser.yaml | 73 +++++++++++++++++++++-------- cmd/kwil-cli/cmds/system/version.go | 13 ++--- internal/pkg/build/build.go | 9 ---- internal/pkg/version/version.go | 47 ++++++++++++++----- 4 files changed, 94 insertions(+), 48 deletions(-) delete mode 100644 internal/pkg/build/build.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f7fc1e33a..669a27e5f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,7 +1,4 @@ -project_name: kwil-cli -before: - hooks: - - go mod tidy +project_name: kwil-db changelog: skip: true @@ -15,10 +12,9 @@ changelog: builds: - id: kwil-cli binary: kwil-cli - main: ./cmd/kwil-cli/main.go + main: ./cmd/kwil-cli goos: - linux - - windows - darwin goarch: - amd64 @@ -27,23 +23,58 @@ builds: - 6 - 7 ignore: - - goos: windows - goarch: arm64 ldflags: - -s -w - - -X 'kwil/internal/pkg/build.Version={{.Version}}' - - -X 'kwil/internal/pkg/build.GitCommit={{.Commit}}' - - -X 'kwil/internal/pkg/build.BuildTime={{.Date}}' + - -X 'github.com/kwilteam/kwil-db/internal/pkg/version.KwilVersion={{ index .Env "KWIL_VERSION" }}' + tags: + - osusergo + - netgo + env: + - CGO_ENABLED=0 + + - id: kwild + binary: kwild + main: ./cmd/kwild + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + goarm: + - 6 + - 7 + ignore: + ldflags: + - -s -w + - -X 'github.com/kwilteam/kwil-db/internal/pkg/version.KwilVersion={{ index .Env "KWIL_VERSION" }}' + tags: + - osusergo + - netgo + env: + - CGO_ENABLED=0 + + - id: kwil-admin + binary: kwil-admin + main: ./cmd/kwil-admin + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + goarm: + - 6 + - 7 + ignore: + ldflags: + - -s -w + - -X 'github.com/kwilteam/kwil-db/internal/pkg/version.KwilVersion={{ index .Env "KWIL_VERSION" }}' + tags: + - osusergo + - netgo env: - CGO_ENABLED=0 - - CC_darwin_amd64=o64-clang - - CCX_darwin_amd64=o64-clang+ - - CC_darwin_arm64=aarch64-apple-darwin20.2-clang - - CCX_darwin_arm64=aarch64-apple-darwin20.2-clang++ - - CC_windows_amd64=x86_64-w64-mingw32-gc - - CCX_windows_amd64=x86_64-w64-mingw32-g++ - - 'CC={{ index .Env (print "CC_" .Os "_" .Arch) }}' - - 'CCX={{ index .Env (print "CCX_" .Os "_" .Arch) }}' checksum: name_template: 'checksums.txt' @@ -56,6 +87,8 @@ release: replace_existing_draft: true ids: - kwil-cli + - kwild + - kwil-admin universal_binaries: - - replace: true \ No newline at end of file + - replace: true diff --git a/cmd/kwil-cli/cmds/system/version.go b/cmd/kwil-cli/cmds/system/version.go index 3c988c168..5269f0c6e 100644 --- a/cmd/kwil-cli/cmds/system/version.go +++ b/cmd/kwil-cli/cmds/system/version.go @@ -4,13 +4,14 @@ import ( "bytes" "encoding/json" "fmt" - "html/template" "io" "runtime" + "text/template" + "time" "github.com/kwilteam/kwil-db/cmd/internal/display" "github.com/kwilteam/kwil-db/cmd/kwil-cli/config" - "github.com/kwilteam/kwil-db/internal/pkg/build" + "github.com/kwilteam/kwil-db/internal/pkg/version" "github.com/spf13/cobra" "github.com/tonistiigi/go-rosetta" ) @@ -18,7 +19,7 @@ import ( var versionTemplate = ` Version: {{.Version}} Git commit: {{.GitCommit}} - Built: {{.BuildTime}} + Built: {{.BuildTime}} API version: {{.APIVersion}} Go version: {{.GoVersion}} OS/Arch: {{.Os}}/{{.Arch}}` @@ -74,13 +75,13 @@ func NewVersionCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { resp := &respVersionInfo{ Info: &versionInfo{ - Version: build.Version, + Version: version.KwilVersion, APIVersion: "", - GitCommit: build.GitCommit, + GitCommit: version.Build.Revision, GoVersion: runtime.Version(), Os: runtime.GOOS, Arch: arch(), - BuildTime: build.BuildTime, + BuildTime: version.Build.RevTime.Format(time.RFC3339), }, } diff --git a/internal/pkg/build/build.go b/internal/pkg/build/build.go deleted file mode 100644 index 65d203410..000000000 --- a/internal/pkg/build/build.go +++ /dev/null @@ -1,9 +0,0 @@ -package build - -// Default build-time variable. -// These values are overridden via ldflags -var ( - Version = "unknown-system" - GitCommit = "unknown-commit" - BuildTime = "unknown-buildtime" -) diff --git a/internal/pkg/version/version.go b/internal/pkg/version/version.go index 5ca2ce899..6dcc25b28 100644 --- a/internal/pkg/version/version.go +++ b/internal/pkg/version/version.go @@ -3,28 +3,51 @@ package version import ( "fmt" "runtime/debug" + "strings" "time" ) +// The kwilVersion should adhere to the semantic versioning (SemVer) spec 2.0.0. +// The general format is MAJOR.MINOR.PATCH-PRERELEASE+BUILD_META where both the +// prerelease label and build metadata are optional. For example: +// +// - 0.6.0-rc.1 +// - 0.6.0+release +// - 0.6.1 +// - 0.6.2-alpha0+go1.21.nocgo +const kwilVersion = "0.6.0-beta" // precursor to 0.6.0+release + +// KwildVersion may be set at compile time by: +// +// go build -ldflags "-s -w -X github.com/kwilteam/kwil-db/internal/pkg/version.KwilVersion=0.6.0+release" var ( - KwilVersion = "0.5.1-pre" // precursor to 0.5.1+release + KwilVersion string Build = vcsInfo() ) func init() { - if Build != nil { - KwilVersion += "+" + Build.Revision - if Build.Dirty { - KwilVersion += ".dirty" + if KwilVersion == "" { // not set via ldflags + KwilVersion = kwilVersion + if Build != nil { + // Append VCS revision and workspace dirty flag. + sep := "+" // start build metadata + if strings.Contains(KwilVersion, "+") { + sep = "." // append to existing build metadata + } + KwilVersion += sep + Build.RevisionShort + if Build.Dirty { + KwilVersion += ".dirty" + } } } } type BuildInfo struct { - GoVersion string - Revision string - RevTime time.Time - Dirty bool + GoVersion string + Revision string + RevisionShort string + RevTime time.Time + Dirty bool } func vcsInfo() *BuildInfo { @@ -32,7 +55,7 @@ func vcsInfo() *BuildInfo { if !ok { return nil } - buildInfo := new(BuildInfo) + buildInfo := &BuildInfo{GoVersion: bi.GoVersion} for _, bs := range bi.Settings { switch bs.Key { case "vcs.revision": @@ -49,8 +72,6 @@ func vcsInfo() *BuildInfo { } } const revLen = 9 - if len(buildInfo.Revision) > revLen { - buildInfo.Revision = buildInfo.Revision[:revLen] - } + buildInfo.RevisionShort = buildInfo.Revision[:min(revLen, len(buildInfo.Revision))] return buildInfo }