Skip to content

Commit

Permalink
use version supplied by goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
pnsafonov committed Apr 27, 2024
1 parent e624e43 commit b077443
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ builds:
flags:
- -trimpath
ldflags:
# omit symbol table and debug information
- -s -w
# -w turns off DWARF debugging information
# -s turns off generation of the Go symbol table
- -X main.commit={{.Commit}}
- -X main.date={{.CommitDate}}
- -X main.builtBy=goreleaser
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func doMain(args []string) {

}

version0, gitHash := GetVersion1()
version0, gitHash := GetVersion0()
ctx := pkg.NewContext(version0, gitHash)
ctx.Service = service0
ctx.ConfigPath = configPath
Expand Down Expand Up @@ -116,7 +116,7 @@ pin programs to CPU (affinity)
}

func printVersion() {
version0, gitHash := GetVersion1()
version0, gitHash := GetVersion0()
fmt.Printf("pind version %s %s\n", version0, gitHash)
os.Exit(0)
}
Expand Down
38 changes: 15 additions & 23 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,33 @@ package main

import (
_ "embed"
"encoding/json"
"runtime/debug"
)

//go:embed version.json
var VersionBytes []byte
var (
version = "dev"
commit = commitNone
date = "unknown"
builtBy = "manual"
)

type Version struct {
Version string `json:"version"`
}
const commitNone = "none"

func GetVersion1() (string, string) {
version, _ := GetVersion()
func GetVersion0() (string, string) {
version0 := GetVersion()
gitHash := GetGitHash()
return version, gitHash
return version0, gitHash
}

func GetVersion0() (*Version, error) {
version := &Version{}
err := json.Unmarshal(VersionBytes, version)
if err != nil {
return nil, err
}
return version, nil
func GetVersion() string {
return version
}

func GetVersion() (string, error) {
version, err := GetVersion0()
if err != nil {
return "", err
func GetGitHash() string {
if commit != commitNone {
return commit
}
return version.Version, nil
}

func GetGitHash() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
Expand Down
3 changes: 0 additions & 3 deletions version.json

This file was deleted.

0 comments on commit b077443

Please sign in to comment.