Skip to content

Commit a63980b

Browse files
authored
update harmony and bootnode version (#4834)
* update harmony and bootnode version * add support for commitAt
1 parent 8245c99 commit a63980b

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

Diff for: cmd/bootnode/main.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,21 @@ func NewConnLogger(l log.Logger) *ConnLogger {
8484
}
8585

8686
var (
87-
version string
88-
builtBy string
89-
builtAt string
90-
commit string
87+
version string
88+
builtBy string
89+
builtAt string
90+
commit string
91+
commitAt string
9192
)
9293

9394
func printVersion(me string) {
94-
fmt.Fprintf(os.Stderr, "Harmony (C) 2024. %v, version %v-%v (%v %v)\n", path.Base(me), version, commit, builtBy, builtAt)
95+
commitYear, err := time.Parse("2006-01-02T15:04:05-0700", commitAt)
96+
if err != nil {
97+
fmt.Fprintf(os.Stderr, "Error parsing commit date: %v\n", err)
98+
os.Exit(1)
99+
}
100+
var currentYear = commitYear.Year()
101+
fmt.Fprintf(os.Stderr, "Harmony (C) %d. %v, version %v-%v (%v %v)\n", currentYear, path.Base(me), version, commit, builtBy, builtAt)
95102
}
96103

97104
func main() {
@@ -180,7 +187,7 @@ func main() {
180187

181188
nt := nodeConfigs.NetworkType(*networkType)
182189
nodeConfigs.SetNetworkType(nt)
183-
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, path.Base(os.Args[0]), version, commit, builtBy, builtAt)
190+
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, path.Base(os.Args[0]), version, commit, commitAt, builtBy, builtAt)
184191
nodeConfigs.SetVersion(harmonyConfigs.GetHarmonyVersion())
185192
nodeConfigs.SetPeerID(host.GetID())
186193
hc := harmonyConfigs.GetDefaultConfigCopy()

Diff for: cmd/config/version.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package config
33
import (
44
"fmt"
55
"os"
6+
"path"
7+
"time"
68

79
"github.com/harmony-one/harmony/internal/cli"
810
"github.com/spf13/cobra"
911
)
1012

11-
const (
12-
versionFormat = "Harmony (C) 2023. %v, version %v-%v (%v %v)"
13-
)
14-
1513
var VersionMetaData []interface{}
1614

1715
var versionFlag = cli.BoolFlag{
@@ -36,7 +34,22 @@ func VersionFlag() cli.BoolFlag {
3634
}
3735

3836
func GetHarmonyVersion() string {
39-
return fmt.Sprintf(versionFormat, VersionMetaData[:5]...) // "harmony", version, commit, builtBy, builtAt
37+
var version, commit, builtBy, builtAt, commitAt string
38+
version = VersionMetaData[1].(string)
39+
commit = VersionMetaData[2].(string)
40+
commitAt = VersionMetaData[3].(string)
41+
builtBy = VersionMetaData[4].(string)
42+
builtAt = VersionMetaData[5].(string)
43+
44+
//Harmony (C) 2025. harmony, version v8507-v2024.3.1-85-g735e68a31-dirty (soph@ 2025-01-21T14:07:44+0700)
45+
commitYear, err := time.Parse("2006-01-02T15:04:05-0700", commitAt)
46+
if err != nil {
47+
fmt.Fprintf(os.Stderr, "Error parsing commit date: %v\n", err)
48+
os.Exit(1)
49+
}
50+
var currentYear = commitYear.Year()
51+
versionFormat := fmt.Sprintf("Harmony (C) %d. %%v, version %%v-%%v (%%v %%v)", currentYear)
52+
return fmt.Sprintf(versionFormat, path.Base(os.Args[0]), version, commit, builtBy, builtAt)
4053
}
4154

4255
func PrintVersion() {

Diff for: cmd/harmony/main.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ import (
6060

6161
// Version string variables
6262
var (
63-
version string
64-
builtBy string
65-
builtAt string
66-
commit string
63+
version string
64+
builtBy string
65+
builtAt string
66+
commit string
67+
commitAt string
6768
)
6869

6970
// Host
@@ -98,7 +99,7 @@ Examples usage:
9899
}
99100

100101
func init() {
101-
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, "harmony", version, commit, builtBy, builtAt)
102+
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, "harmony", version, commit, commitAt, builtBy, builtAt)
102103
harmonyConfigs.Init(rootCmd)
103104
}
104105

Diff for: scripts/go_executable_build.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function build_only
105105

106106
VERSION=$(git rev-list --count HEAD)
107107
COMMIT=$(git describe --always --long --dirty)
108+
COMMITAT=$(git show -s --format=%cd --date=format:%Y-%m-%dT%H:%M:%S%z HEAD)
108109
BUILTAT=$(date +%FT%T%z)
109110
BUILTBY=${USER}@
110111
local build=$1
@@ -117,12 +118,12 @@ function build_only
117118
rm -f $BINDIR/$bin
118119
echo "building ${SRC[$bin]}"
119120
if [ "$DEBUG" == "true" ]; then
120-
env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]}
121+
env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.commitAt=${COMMITAT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]}
121122
else
122123
if [ "$STATIC" == "true" ]; then
123-
env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY} -w -extldflags \"-static -lm\"" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]}
124+
env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.commitAt=${COMMITAT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY} -w -extldflags \"-static -lm\"" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]}
124125
else
125-
env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]}
126+
env GOOS=$GOOS GOARCH=$GOARCH go build $VERBOSE -gcflags="${GO_GCFLAGS}" -ldflags="-X main.version=v${VERSION} -X main.commit=${COMMIT} -X main.commitAt=${COMMITAT} -X main.builtAt=${BUILTAT} -X main.builtBy=${BUILTBY}" -o $BINDIR/$bin $RACE $TRACEPTR ${SRC[$bin]}
126127
fi
127128
fi
128129
if [ "$(uname -s)" == "Linux" ]; then

0 commit comments

Comments
 (0)