-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(version): append commit hash on build via ldflags
It standardize resonate binary version to: resonate version v<VERSION>[-<PRE_RELEASE>-<TIMESTAMP>][ COMMIT_HASH] <GOOS>/<GOARCH> where: - `VERSION`: the release version - `PRE_RELEASE`: can be any arbitrary string, e.g. `alpha`, `beta`, `rc.1`, etc - `TIMESTAMP`: the yyyymmdd of build IF this is not a GA release - `COMMIT_HASH`: short revision IF this is a GA release - `GOOS`: underlying OS this binary built on - `GOARCH`: underlying Architecture this binary built on This also adds a new `version` subcommand for convenience and to not give an error on `resonate version` for folks with muscle memory for it. Signed-off-by: Khosrow Moossavi <[email protected]>
- Loading branch information
Showing
7 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/resonatehq/resonate/internal/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
Use: "version", | ||
Short: "Print the version for resonate", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Printf("resonate version %s\n", version.Full()) | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"time" | ||
) | ||
|
||
// current version | ||
const ( | ||
coreVersion = "0.5.7" | ||
prerelease = "alpha" | ||
) | ||
|
||
// Provisioned by ldflags | ||
var commit string | ||
|
||
// Core return the core version. | ||
func Core() string { | ||
return coreVersion | ||
} | ||
|
||
// Short return the version with pre-release, if available. | ||
func Short() string { | ||
if prerelease != "" { | ||
return fmt.Sprintf("%s-%s-%s", coreVersion, prerelease, time.Now().Format("20060102")) | ||
} | ||
|
||
return coreVersion | ||
} | ||
|
||
// Full return the full version including pre-release, commit hash, runtime os and arch. | ||
func Full() string { | ||
if commit != "" && commit[:1] != " " { | ||
commit = " " + commit | ||
} | ||
|
||
return fmt.Sprintf("v%s%s %s/%s", Short(), commit, runtime.GOOS, runtime.GOARCH) | ||
} |