-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(version): append commit hash on build via ldflags #342
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
let | ||
# Version inference | ||
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101"; | ||
version = "${builtins.substring 0 8 lastModifiedDate}-${self.shortRev or "dirty"}"; | ||
shortRev = "${self.shortRev or "dirty"}"; | ||
version = "${builtins.substring 0 8 lastModifiedDate}-${shortRev}"; | ||
|
||
# Helpers for producing system-specific outputs | ||
supportedSystems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ]; | ||
|
@@ -77,6 +78,7 @@ | |
# The Resonate server | ||
resonate = pkgs.buildGoApplication rec { | ||
pname = "resonate"; | ||
inherit shortRev; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this line (you don't need to inherit this value into the derivation function to use it 😄) |
||
inherit version; | ||
src = self; | ||
modules = ./gomod2nix.toml; | ||
|
@@ -88,6 +90,7 @@ | |
ldflags = [ | ||
"-s" | ||
"-w" | ||
"-X github.com/resonatehq/resonate/internal/version.commit=$(shortRev)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case you'll need to use Nix string interpolation like this: "-X github.com/resonatehq/resonate/internal/version.commit=${shortRev}" |
||
] ++ pkgs.lib.optional (pkgs.stdenv.isLinux) [ | ||
"-extldflags=-static" | ||
"-linkmode=external" | ||
|
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will solve the workflow, but I'm not aware of any other breaking change that this might introduce in the broader resonate landscape, if any. Because effectively
resonate --version
will always have a leadingv
and tailing<os>/<arch>
, if move forward with this PR.