From d99f993c21ac2768d4d029edbb1d02c1e3bc11cc Mon Sep 17 00:00:00 2001 From: Jeffrey Picard Date: Fri, 24 Sep 2021 16:24:22 -0400 Subject: [PATCH] Fix versioning --- build_and_push.sh | 22 ++++++++++++++++------ server/server.go | 14 ++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/build_and_push.sh b/build_and_push.sh index d03a79c..23f9dc2 100755 --- a/build_and_push.sh +++ b/build_and_push.sh @@ -1,18 +1,28 @@ #!/bin/bash +IMPORT_PATH="github.com/lbryio/hub/app" + +function print_and_die() { + echo "$1" + exit 1 +} + # Get new tags from remote git fetch --tags # Get latest tag name -latestTag=$(git describe --tags `git rev-list --tags --max-count=1`) +LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`) # Make sure it match the format vX.XXXX.XX.XX -[[ $latestTag =~ ^v[0-9]+\.[0-9]{4}\.[0-9]{2}\.[0-9]{2}.*$ ]] || exit 1 +[[ $LATEST_TAG =~ ^v[0-9]+\.[0-9]{4}\.[0-9]{2}\.[0-9]{2}.*$ ]] || print_and_die "bad version ${LATEST_TAG}" +VERSION=$LATEST_TAG + +echo "using tag $LATEST_TAG" # Checkout latest tag -git checkout $latestTag +git checkout "$LATEST_TAG" -go build . +CGO_ENABLED=0 go build -v -ldflags "-X ${IMPORT_PATH}/meta.version=${VERSION}" docker build . -t lbry/hub:latest -docker tag lbry/hub:latest lbry/hub:$latestTag +docker tag lbry/hub:latest lbry/hub:"$LATEST_TAG" docker push lbry/hub:latest -docker push lbry/hub:$latestTag +docker push lbry/hub:"$LATEST_TAG" diff --git a/server/server.go b/server/server.go index c4c1896..dde6d4e 100644 --- a/server/server.go +++ b/server/server.go @@ -10,6 +10,7 @@ import ( "net/http" "time" + "github.com/lbryio/hub/meta" pb "github.com/lbryio/hub/protobuf/go" "github.com/olivere/elastic/v7" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -33,8 +34,6 @@ type FederatedServer struct { Ping int //? } -const majorVersion = 0 - const ( ServeCmd = iota SearchCmd = iota @@ -51,13 +50,8 @@ type Args struct { Debug bool } -func getVersion(alphaBeta string) string { - strPortion := time.Now().Format("2006.01.02") - majorVersionDate := fmt.Sprintf("v%d.%s", majorVersion, strPortion) - if len(alphaBeta) > 0 { - return fmt.Sprintf("%s-%s", majorVersionDate, alphaBeta) - } - return majorVersionDate +func getVersion() string { + return meta.Version } /* @@ -162,5 +156,5 @@ func (s *Server) Ping(context context.Context, args *pb.EmptyMessage) (*pb.Strin } func (s *Server) Version(context context.Context, args *pb.EmptyMessage) (*pb.StringValue, error) { - return &pb.StringValue{Value: getVersion("beta")}, nil + return &pb.StringValue{Value: getVersion()}, nil }