From 9d0b8ac6f4350a3fe490fac55fb8badf1f73571d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 8 Dec 2018 10:51:31 +0000 Subject: [PATCH 1/3] Strip v from version during imprint --- build | 2 +- contrib/semver/version.sh | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build b/build index a62c92d..8dd23ef 100755 --- a/build +++ b/build @@ -10,7 +10,7 @@ done echo "Downloading..." for CMD in `ls cmd/` ; do echo "Building: $CMD" - IMPRINT="-X github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.buildName=$(sh contrib/semver/name.sh) -X github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.buildVersion=$(sh contrib/semver/version.sh)" + IMPRINT="-X github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.buildName=$(sh contrib/semver/name.sh) -X github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil.buildVersion=$(sh contrib/semver/version.sh --bare)" if [ $DEBUG ]; then go build -ldflags="$IMPRINT" -tags debug -v ./cmd/$CMD else diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 143bd90..480c4dd 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -12,6 +12,13 @@ MERGE=$(git rev-list $TAG..master --grep "from $DEVELOPBRANCH" 2>/dev/null | hea # Get the number of merges since the last merge to master PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH" 2>/dev/null) +# Decide whether we should prepend the version with "v" - the default is that +# we do because we use it in git tags, but we might not always need it +PREPEND="v" +if [ "$1" == "--bare" ]; then + PREPEND="" +fi + # If it fails then there's no last tag - go from the first commit if [ $? != 0 ]; then PATCH=$(git rev-list HEAD --count 2>/dev/null) @@ -22,7 +29,7 @@ if [ $? != 0 ]; then exit 1 fi - printf 'v0.0.%d' "$PATCH" + printf '%s0.0.%d' "$PREPEND" "$PATCH" exit 1 fi @@ -39,12 +46,12 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD) # Output in the desired format if [ $PATCH = 0 ]; then if [ ! -z $FULL ]; then - printf 'v%d.%d.0' "$MAJOR" "$MINOR" + printf '%s%d.%d.0' "$PREPEND" "$MAJOR" "$MINOR" else - printf 'v%d.%d' "$MAJOR" "$MINOR" + printf '%s%d.%d' "$PREPEND" "$MAJOR" "$MINOR" fi else - printf 'v%d.%d.%d' "$MAJOR" "$MINOR" "$PATCH" + printf '%s%d.%d.%d' "$PREPEND" "$MAJOR" "$MINOR" "$PATCH" fi # Add the build tag on non-master branches From f2d01aa54db864282a2813883937d77aaec0cd68 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 8 Dec 2018 10:54:47 +0000 Subject: [PATCH 2/3] Use bare version in deb/macos packages instead of cut --- contrib/deb/generate.sh | 2 +- contrib/macos/create-pkg.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/deb/generate.sh b/contrib/deb/generate.sh index f99d834..5af31d5 100644 --- a/contrib/deb/generate.sh +++ b/contrib/deb/generate.sh @@ -12,7 +12,7 @@ fi PKGBRANCH=$(basename `git name-rev --name-only HEAD`) PKGNAME=$(sh contrib/semver/name.sh) -PKGVERSION=$(sh contrib/semver/version.sh | cut -c 2-) +PKGVERSION=$(sh contrib/semver/version.sh --bare) PKGARCH=${PKGARCH-amd64} PKGFILE=$PKGNAME-$PKGVERSION-$PKGARCH.deb PKGREPLACES=yggdrasil diff --git a/contrib/macos/create-pkg.sh b/contrib/macos/create-pkg.sh index 167184e..cc9a74f 100755 --- a/contrib/macos/create-pkg.sh +++ b/contrib/macos/create-pkg.sh @@ -72,7 +72,7 @@ chmod +x pkgbuild/root/usr/local/bin/yggdrasilctl # Work out metadata for the package info PKGNAME=$(sh contrib/semver/name.sh) -PKGVERSION=$(sh contrib/semver/version.sh | cut -c 2-) +PKGVERSION=$(sh contrib/semver/version.sh --bare) PKGARCH=${PKGARCH-amd64} PAYLOADSIZE=$(( $(wc -c pkgbuild/flat/base.pkg/Payload | awk '{ print $1 }') / 1024 )) From 02f98a2592290ad4eb17a7bee14cb77400316f3c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 8 Dec 2018 11:01:05 +0000 Subject: [PATCH 3/3] Only show build name and version if it is known --- cmd/yggdrasilctl/main.go | 4 ++-- src/yggdrasil/admin.go | 9 +++++++-- src/yggdrasil/core.go | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index ca3078b..dcbde87 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -183,10 +183,10 @@ func main() { } case "getself": for k, v := range res["self"].(map[string]interface{}) { - if buildname, ok := v.(map[string]interface{})["build_name"].(string); ok { + if buildname, ok := v.(map[string]interface{})["build_name"].(string); ok && buildname != "unknown" { fmt.Println("Build name:", buildname) } - if buildversion, ok := v.(map[string]interface{})["build_version"].(string); ok { + if buildversion, ok := v.(map[string]interface{})["build_version"].(string); ok && buildversion != "unknown" { fmt.Println("Build version:", buildversion) } fmt.Println("IPv6 address:", k) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 7d82b13..2c65b6a 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -556,13 +556,18 @@ func (a *admin) getData_getSelf() *admin_nodeInfo { table := a.core.switchTable.table.Load().(lookupTable) coords := table.self.getCoords() self := admin_nodeInfo{ - {"build_name", GetBuildName()}, - {"build_version", GetBuildVersion()}, {"box_pub_key", hex.EncodeToString(a.core.boxPub[:])}, {"ip", a.core.GetAddress().String()}, {"subnet", a.core.GetSubnet().String()}, {"coords", fmt.Sprint(coords)}, } + if name := GetBuildName(); name != "unknown" { + self = append(self, admin_pair{"build_name", name}) + } + if version := GetBuildVersion(); version != "unknown" { + self = append(self, admin_pair{"build_version", version}) + } + return &self } diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 682d815..5ab91a7 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -87,11 +87,11 @@ func GetBuildVersion() string { func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { c.log = log - if buildName != "" { - c.log.Println("Build name:", buildName) + if name := GetBuildName(); name != "unknown" { + c.log.Println("Build name:", name) } - if buildVersion != "" { - c.log.Println("Build version:", buildVersion) + if version := GetBuildVersion(); version != "unknown" { + c.log.Println("Build version:", version) } c.log.Println("Starting up...")