mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Pass commit date and hash to -ldflags separately.
This commit is contained in:
committed by
Dan Christian Bogos
parent
368c046805
commit
915733e04e
34
build.sh
34
build.sh
@@ -1,24 +1,38 @@
|
||||
#! /usr/bin/env sh
|
||||
echo "Building CGRateS ..."
|
||||
|
||||
GIT_LAST_LOG=$(git log -1 | tr -d "'")
|
||||
GIT_COMMIT="HEAD"
|
||||
|
||||
GIT_TAG_LOG=$(git tag -l --points-at HEAD)
|
||||
GIT_COMMIT_DATE="$(git log -n1 --format=format:%cI "${GIT_COMMIT}")"
|
||||
GIT_COMMIT_HASH="$(git log -n1 --format=format:%H "${GIT_COMMIT}")"
|
||||
|
||||
if [ ! -z "$GIT_TAG_LOG" ]
|
||||
then
|
||||
GIT_LAST_LOG=""
|
||||
GIT_TAG_LOG="$(git tag -l --points-at "${GIT_COMMIT}")"
|
||||
|
||||
if [ -n "${GIT_TAG_LOG}" ]; then
|
||||
GIT_COMMIT_DATE=""
|
||||
GIT_COMMIT_HASH=""
|
||||
fi
|
||||
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-engine
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-engine
|
||||
cr=$?
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-loader
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-loader
|
||||
cl=$?
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-console
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-console
|
||||
cc=$?
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-migrator
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-migrator
|
||||
cm=$?
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-tester
|
||||
go install -ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-tester
|
||||
ct=$?
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
exit $cr || $cl || $cc || $cm || $ct
|
||||
|
||||
@@ -93,11 +93,12 @@ func TestCoreServiceStatus(t *testing.T) {
|
||||
if !reflect.DeepEqual(expected[utils.NodeID], reply[utils.NodeID]) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expected[utils.NodeID]), utils.ToJSON(reply[utils.NodeID]))
|
||||
}
|
||||
utils.GitLastLog = `Date: wrong format
|
||||
`
|
||||
if err := cores.V1Status(nil, nil, &reply); err != nil {
|
||||
utils.GitCommitDate = "wrong format"
|
||||
utils.GitCommitHash = "73014DAA0C1D7EDCB532D5FE600B8A20D588CDF8"
|
||||
if err := cores.V1Status(context.Background(), args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
utils.GitLastLog = ""
|
||||
utils.GitCommitDate = ""
|
||||
utils.GitCommitHash = ""
|
||||
}
|
||||
|
||||
@@ -1,24 +1,53 @@
|
||||
#! /usr/bin/env sh
|
||||
echo "Static building CGRateS..."
|
||||
|
||||
GIT_LAST_LOG=$(git log -1 | tr -d "'")
|
||||
GIT_COMMIT="HEAD"
|
||||
|
||||
GIT_TAG_LOG=$(git tag -l --points-at HEAD)
|
||||
GIT_COMMIT_DATE="$(git log -n1 --format=format:%cI "${GIT_COMMIT}")"
|
||||
GIT_COMMIT_HASH="$(git log -n1 --format=format:%H "${GIT_COMMIT}")"
|
||||
|
||||
if [ ! -z "$GIT_TAG_LOG" ]
|
||||
then
|
||||
GIT_LAST_LOG=""
|
||||
GIT_TAG_LOG="$(git tag -l --points-at "${GIT_COMMIT}")"
|
||||
|
||||
if [ -n "${GIT_TAG_LOG}" ]; then
|
||||
GIT_COMMIT_DATE=""
|
||||
GIT_COMMIT_HASH=""
|
||||
fi
|
||||
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-engine -a -ldflags '-extldflags "-f no-PIC -static"' -tags 'osusergo netgo static_build' -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-engine
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-engine -a \
|
||||
-ldflags '-extldflags "-f no-PIC -static"' \
|
||||
-tags 'osusergo netgo static_build' \
|
||||
-ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-engine
|
||||
cr=$?
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-loader -a -ldflags '-extldflags "-f no-PIC -static"' -tags 'osusergo netgo static_build' -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-loader
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-loader -a \
|
||||
-ldflags '-extldflags "-f no-PIC -static"' \
|
||||
-tags 'osusergo netgo static_build' \
|
||||
-ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-loader
|
||||
cl=$?
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-console -a -ldflags '-extldflags "-f no-PIC -static"' -tags 'osusergo netgo static_build' -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-console
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-console -a \
|
||||
-ldflags '-extldflags "-f no-PIC -static"' \
|
||||
-tags 'osusergo netgo static_build' \
|
||||
-ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-console
|
||||
cc=$?
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-migrator -a -ldflags '-extldflags "-f no-PIC -static"' -tags 'osusergo netgo static_build' -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-migrator
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-migrator -a \
|
||||
-ldflags '-extldflags "-f no-PIC -static"' \
|
||||
-tags 'osusergo netgo static_build' \
|
||||
-ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-migrator
|
||||
cm=$?
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-tester -a -ldflags '-extldflags "-f no-PIC -static"' -tags 'osusergo netgo static_build' -ldflags "-X 'github.com/cgrates/cgrates/utils.GitLastLog=$GIT_LAST_LOG'" github.com/cgrates/cgrates/cmd/cgr-tester
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o cgr-tester -a \
|
||||
-ldflags '-extldflags "-f no-PIC -static"' \
|
||||
-tags 'osusergo netgo static_build' \
|
||||
-ldflags "-X 'github.com/cgrates/cgrates/utils.GitCommitDate=$GIT_COMMIT_DATE' \
|
||||
-X 'github.com/cgrates/cgrates/utils.GitCommitHash=$GIT_COMMIT_HASH'" \
|
||||
github.com/cgrates/cgrates/cmd/cgr-tester
|
||||
ct=$?
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
exit $cr || $cl || $cc || $cm || $ct
|
||||
|
||||
@@ -28,7 +28,8 @@ var (
|
||||
PreRated, CostSource, CostDetails, ExtraInfo, OrderID})
|
||||
PostPaidRatedSlice = []string{MetaPostpaid, MetaRated}
|
||||
|
||||
GitLastLog string // If set, it will be processed as part of versioning
|
||||
GitCommitDate string // If set, it will be processed as part of versioning
|
||||
GitCommitHash string // If set, it will be processed as part of versioning
|
||||
|
||||
extraDBPartition = NewStringSet([]string{CacheDispatchers,
|
||||
CacheDispatcherRoutes, CacheDispatcherLoads, CacheDiameterMessages, CacheRPCResponses, CacheClosedSessions,
|
||||
|
||||
@@ -665,41 +665,23 @@ func MaskSuffix(dest string, maskLen int) string {
|
||||
|
||||
func GetCGRVersion() (vers string, err error) {
|
||||
vers = fmt.Sprintf("%s@%s", CGRateS, Version)
|
||||
if GitLastLog == "" {
|
||||
if GitCommitDate == "" || GitCommitHash == "" {
|
||||
return vers, nil
|
||||
}
|
||||
rdr := bytes.NewBufferString(GitLastLog)
|
||||
var commitHash string
|
||||
var commitDate time.Time
|
||||
for i := 0; i < 5; i++ { // read a maximum of 5 lines
|
||||
var ln string
|
||||
ln, err = rdr.ReadString('\n')
|
||||
if err != nil {
|
||||
return vers, fmt.Errorf("Building version - error: <%s> reading line from file", err.Error()) //or errorsNew()
|
||||
}
|
||||
if strings.HasPrefix(ln, "commit ") {
|
||||
commitSplt := strings.Split(ln, " ")
|
||||
if len(commitSplt) != 2 {
|
||||
return vers, fmt.Errorf("Building version - cannot extract commit hash")
|
||||
}
|
||||
commitHash = commitSplt[1]
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(ln, "Date:") {
|
||||
dateSplt := strings.Split(ln, ": ")
|
||||
if len(dateSplt) != 2 {
|
||||
return vers, fmt.Errorf("Building version - cannot split commit date")
|
||||
}
|
||||
commitDate, err = time.Parse("Mon Jan 2 15:04:05 2006 -0700", strings.TrimSpace(dateSplt[1]))
|
||||
if err != nil {
|
||||
return vers, fmt.Errorf("Building version - error: <%s> compiling commit date", err.Error())
|
||||
}
|
||||
break
|
||||
}
|
||||
var matched bool
|
||||
commitDate, err = time.Parse("2006-01-02T15:04:05-07:00", strings.TrimSpace(GitCommitDate))
|
||||
if err != nil {
|
||||
return vers, fmt.Errorf("Building version - error: <%s> compiling commit date", err.Error())
|
||||
}
|
||||
if commitHash == "" || commitDate.IsZero() {
|
||||
return vers, fmt.Errorf("Cannot find commitHash or commitDate information")
|
||||
matched, err = regexp.MatchString("^[0-9a-f]{12,}$", GitCommitHash)
|
||||
if err != nil {
|
||||
return vers, fmt.Errorf("Building version - error: <%s> compiling commit hash", err.Error())
|
||||
} else if !matched {
|
||||
return vers, fmt.Errorf("Building version - error: <%s> compiling commit hash", "Regex not matched")
|
||||
}
|
||||
commitHash = GitCommitHash
|
||||
//CGRateS@v0.11.0~dev-20200110075344-7572e7b11e00
|
||||
return fmt.Sprintf("%s@%s-%s-%s", CGRateS, Version, commitDate.UTC().Format("20060102150405"), commitHash[:12]), nil
|
||||
}
|
||||
|
||||
@@ -1103,12 +1103,8 @@ func TestToIJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCGRVersion(t *testing.T) {
|
||||
GitLastLog = `commit 73014daa0c1d7edcb532d5fe600b8a20d588cdf8
|
||||
Author: DanB <danb@cgrates.org>
|
||||
Date: Fri Dec 30 19:48:09 2016 +0100
|
||||
|
||||
Fixes for db driver to avoid returning new values in case of errors
|
||||
`
|
||||
GitCommitDate = "2016-12-30T19:48:09+01:00"
|
||||
GitCommitHash = "73014daa0c1d7edcb532d5fe600b8a20d588cdf8"
|
||||
expVers := "CGRateS@" + Version
|
||||
eVers := expVers + "-20161230184809-73014daa0c1d"
|
||||
if vers, err := GetCGRVersion(); err != nil {
|
||||
@@ -1116,46 +1112,23 @@ Date: Fri Dec 30 19:48:09 2016 +0100
|
||||
} else if vers != eVers {
|
||||
t.Errorf("Expecting: <%s>, received: <%s>", eVers, vers)
|
||||
}
|
||||
GitLastLog = ""
|
||||
GitCommitDate = ""
|
||||
GitCommitHash = ""
|
||||
if vers, err := GetCGRVersion(); err != nil {
|
||||
t.Error(err)
|
||||
} else if vers != expVers {
|
||||
t.Errorf("Expecting: <%s>, received: <%s>", expVers, vers)
|
||||
}
|
||||
GitLastLog = "\n"
|
||||
if vers, err := GetCGRVersion(); err == nil || err.Error() != "Building version - error: <EOF> reading line from file" {
|
||||
GitCommitDate = "wrong format"
|
||||
GitCommitHash = "73014daa0c1d7edcb532d5fe600b8a20d588cdf8"
|
||||
if vers, err := GetCGRVersion(); err == nil || err.Error() != `Building version - error: <parsing time "wrong format" as "2006-01-02T15:04:05-07:00": cannot parse "wrong format" as "2006"> compiling commit date` {
|
||||
t.Error(err)
|
||||
} else if vers != expVers {
|
||||
t.Errorf("Expecting: <%s>, received: <%s>", expVers, vers)
|
||||
}
|
||||
GitLastLog = `commit . . .
|
||||
`
|
||||
if vers, err := GetCGRVersion(); err == nil || err.Error() != "Building version - cannot extract commit hash" {
|
||||
t.Error(err)
|
||||
} else if vers != expVers {
|
||||
t.Errorf("Expecting: <%s>, received: <%s>", expVers, vers)
|
||||
}
|
||||
GitLastLog = `Date: : :
|
||||
`
|
||||
if vers, err := GetCGRVersion(); err == nil || err.Error() != "Building version - cannot split commit date" {
|
||||
t.Error(err)
|
||||
} else if vers != expVers {
|
||||
t.Errorf("Expecting: <%s>, received: <%s>", expVers, vers)
|
||||
}
|
||||
GitLastLog = `Date: wrong format
|
||||
`
|
||||
if vers, err := GetCGRVersion(); err == nil || err.Error() != `Building version - error: <parsing time "wrong format" as "Mon Jan 2 15:04:05 2006 -0700": cannot parse "wrong format" as "Mon"> compiling commit date` {
|
||||
t.Error(err)
|
||||
} else if vers != expVers {
|
||||
t.Errorf("Expecting: <%s>, received: <%s>", expVers, vers)
|
||||
}
|
||||
GitLastLog = `ommit 73014daa0c1d7edcb532d5fe600b8a20d588cdf8
|
||||
Author: DanB <danb@cgrates.org>
|
||||
Date: Fri Dec 30 19:48:09 2016 +0100
|
||||
|
||||
Fixes for db driver to avoid returning new values in case of errors
|
||||
`
|
||||
if vers, err := GetCGRVersion(); err == nil || err.Error() != "Cannot find commitHash or commitDate information" {
|
||||
GitCommitDate = "2016-12-30T19:48:09+01:00"
|
||||
GitCommitHash = "73014DAA0C1D7EDCB532D5FE600B8A20D588CDF8"
|
||||
if vers, err := GetCGRVersion(); err == nil || err.Error() != `Building version - error: <Regex not matched> compiling commit hash` {
|
||||
t.Error(err)
|
||||
} else if vers != expVers {
|
||||
t.Errorf("Expecting: <%s>, received: <%s>", expVers, vers)
|
||||
|
||||
Reference in New Issue
Block a user