Add version to binary

This commit is contained in:
David Dworken 2022-04-09 14:37:21 -07:00
parent caf7889c06
commit 2bb06b568a
4 changed files with 10 additions and 7 deletions

View File

@ -3,9 +3,9 @@ test:
release: release:
expr `cat VERSION` + 1 > VERSION expr `cat VERSION` + 1 > VERSION
git tag v0.`cat VERSION`
git add VERSION git add VERSION
git commit -m "Bump hishtory version" git commit -m "Bump hishtory version"
git tag v0.`cat VERSION`
git push git push
git push --tags git push --tags

View File

@ -188,7 +188,7 @@ func testIntegration(t *testing.T) string {
out := RunInteractiveBashCommands(t, ` out := RunInteractiveBashCommands(t, `
hishtory status hishtory status
`) `)
if out != fmt.Sprintf("Hishtory: e2e sync\nEnabled: true\nSecret Key: %s\nCommit Hash: Unknown\n", userSecret) { if out != fmt.Sprintf("Hishtory: v0.Unknown\nEnabled: true\nSecret Key: %s\nCommit Hash: Unknown\n", userSecret) {
t.Fatalf("status command has unexpected output: %#v", out) t.Fatalf("status command has unexpected output: %#v", out)
} }
@ -363,7 +363,7 @@ func TestUpdate(t *testing.T) {
// Check the status command // Check the status command
out := RunInteractiveBashCommands(t, `hishtory status`) out := RunInteractiveBashCommands(t, `hishtory status`)
if out != fmt.Sprintf("Hishtory: e2e sync\nEnabled: true\nSecret Key: %s\nCommit Hash: Unknown\n", userSecret) { if out != fmt.Sprintf("Hishtory: v0.Unknown\nEnabled: true\nSecret Key: %s\nCommit Hash: Unknown\n", userSecret) {
t.Fatalf("status command has unexpected output: %#v", out) t.Fatalf("status command has unexpected output: %#v", out)
} }
@ -372,7 +372,7 @@ func TestUpdate(t *testing.T) {
// Then check the status command again to confirm the update worked // Then check the status command again to confirm the update worked
out = RunInteractiveBashCommands(t, `hishtory status`) out = RunInteractiveBashCommands(t, `hishtory status`)
if !strings.HasPrefix(out, fmt.Sprintf("Hishtory: e2e sync\nEnabled: true\nSecret Key: %s\nCommit Hash: ", userSecret)) { if !strings.HasPrefix(out, fmt.Sprintf("Hishtory: v0.Unknown\nEnabled: true\nSecret Key: %s\nCommit Hash: ", userSecret)) {
t.Fatalf("status command has unexpected output: %#v", out) t.Fatalf("status command has unexpected output: %#v", out)
} }
if strings.Contains(out, "\nCommit Hash: Unknown\n") { if strings.Contains(out, "\nCommit Hash: Unknown\n") {

View File

@ -16,7 +16,10 @@ import (
"github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared"
) )
var GitCommit string = "Unknown" var (
GitCommit string = "Unknown"
Version string = "Unknown"
)
func main() { func main() {
if len(os.Args) == 1 { if len(os.Args) == 1 {
@ -41,7 +44,7 @@ func main() {
case "status": case "status":
config, err := lib.GetConfig() config, err := lib.GetConfig()
lib.CheckFatalError(err) lib.CheckFatalError(err)
fmt.Print("Hishtory: e2e sync\nEnabled: ") fmt.Print("Hishtory: v0." + Version + "\nEnabled: ")
fmt.Print(config.IsEnabled) fmt.Print(config.IsEnabled)
fmt.Print("\nSecret Key: ") fmt.Print("\nSecret Key: ")
fmt.Print(config.UserSecret) fmt.Print(config.UserSecret)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
GIT_HASH=$(git rev-parse HEAD) GIT_HASH=$(git rev-parse HEAD)
echo "-X main.GitCommit=$GIT_HASH -w -extldflags \"-static\"" echo "-X main.GitCommit=$GIT_HASH -X main.Version=`cat VERSION` -w -extldflags \"-static\""