Skip to content

Commit

Permalink
update harmony and bootnode version (#4834)
Browse files Browse the repository at this point in the history
* update harmony and bootnode version
* add support for commitAt
  • Loading branch information
sophoah authored Jan 22, 2025
1 parent 8245c99 commit a63980b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
19 changes: 13 additions & 6 deletions cmd/bootnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ func NewConnLogger(l log.Logger) *ConnLogger {
}

var (
version string
builtBy string
builtAt string
commit string
version string
builtBy string
builtAt string
commit string
commitAt string
)

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

func main() {
Expand Down Expand Up @@ -180,7 +187,7 @@ func main() {

nt := nodeConfigs.NetworkType(*networkType)
nodeConfigs.SetNetworkType(nt)
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, path.Base(os.Args[0]), version, commit, builtBy, builtAt)
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, path.Base(os.Args[0]), version, commit, commitAt, builtBy, builtAt)
nodeConfigs.SetVersion(harmonyConfigs.GetHarmonyVersion())
nodeConfigs.SetPeerID(host.GetID())
hc := harmonyConfigs.GetDefaultConfigCopy()
Expand Down
23 changes: 18 additions & 5 deletions cmd/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package config
import (
"fmt"
"os"
"path"
"time"

"github.com/harmony-one/harmony/internal/cli"
"github.com/spf13/cobra"
)

const (
versionFormat = "Harmony (C) 2023. %v, version %v-%v (%v %v)"
)

var VersionMetaData []interface{}

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

func GetHarmonyVersion() string {
return fmt.Sprintf(versionFormat, VersionMetaData[:5]...) // "harmony", version, commit, builtBy, builtAt
var version, commit, builtBy, builtAt, commitAt string
version = VersionMetaData[1].(string)
commit = VersionMetaData[2].(string)
commitAt = VersionMetaData[3].(string)
builtBy = VersionMetaData[4].(string)
builtAt = VersionMetaData[5].(string)

//Harmony (C) 2025. harmony, version v8507-v2024.3.1-85-g735e68a31-dirty (soph@ 2025-01-21T14:07:44+0700)
commitYear, err := time.Parse("2006-01-02T15:04:05-0700", commitAt)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing commit date: %v\n", err)
os.Exit(1)
}
var currentYear = commitYear.Year()
versionFormat := fmt.Sprintf("Harmony (C) %d. %%v, version %%v-%%v (%%v %%v)", currentYear)
return fmt.Sprintf(versionFormat, path.Base(os.Args[0]), version, commit, builtBy, builtAt)
}

func PrintVersion() {
Expand Down
11 changes: 6 additions & 5 deletions cmd/harmony/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ import (

// Version string variables
var (
version string
builtBy string
builtAt string
commit string
version string
builtBy string
builtAt string
commit string
commitAt string
)

// Host
Expand Down Expand Up @@ -98,7 +99,7 @@ Examples usage:
}

func init() {
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, "harmony", version, commit, builtBy, builtAt)
harmonyConfigs.VersionMetaData = append(harmonyConfigs.VersionMetaData, "harmony", version, commit, commitAt, builtBy, builtAt)
harmonyConfigs.Init(rootCmd)
}

Expand Down
7 changes: 4 additions & 3 deletions scripts/go_executable_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function build_only

VERSION=$(git rev-list --count HEAD)
COMMIT=$(git describe --always --long --dirty)
COMMITAT=$(git show -s --format=%cd --date=format:%Y-%m-%dT%H:%M:%S%z HEAD)
BUILTAT=$(date +%FT%T%z)
BUILTBY=${USER}@
local build=$1
Expand All @@ -117,12 +118,12 @@ function build_only
rm -f $BINDIR/$bin
echo "building ${SRC[$bin]}"
if [ "$DEBUG" == "true" ]; then
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]}
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]}
else
if [ "$STATIC" == "true" ]; then
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]}
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]}
else
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]}
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]}
fi
fi
if [ "$(uname -s)" == "Linux" ]; then
Expand Down

0 comments on commit a63980b

Please sign in to comment.