From a3273e9debd29067d53f124412dee99db613f4a0 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 24 Jun 2020 12:55:49 -0700 Subject: [PATCH] Value injection at build time seems to only work for the main package --- core/constants.go | 20 -------------------- main.go | 19 ++++++++++++++++++- scripts/build.sh | 2 +- 3 files changed, 19 insertions(+), 22 deletions(-) delete mode 100644 core/constants.go diff --git a/core/constants.go b/core/constants.go deleted file mode 100644 index a724e1942..000000000 --- a/core/constants.go +++ /dev/null @@ -1,20 +0,0 @@ -package core - -import ( - "fmt" -) - -// the following are injected at build-time -var ( - //GitCommit is the commit which this version of owncast is running - GitCommit = "unknown" - //BuildVersion is the version - BuildVersion = "0.0.0" - //BuildType is the type of build - BuildType = "localdev" -) - -//GetVersion gets the version string -func GetVersion() string { - return fmt.Sprintf("Owncast v%s-%s (%s)", BuildVersion, BuildType, GitCommit) -} diff --git a/main.go b/main.go index e333a0cdd..ac3e7af3a 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "fmt" + log "github.com/sirupsen/logrus" "github.com/gabek/owncast/config" @@ -8,9 +10,19 @@ import ( "github.com/gabek/owncast/router" ) +// the following are injected at build-time +var ( + //GitCommit is the commit which this version of owncast is running + GitCommit = "unknown" + //BuildVersion is the version + BuildVersion = "0.0.0" + //BuildType is the type of build + BuildType = "localdev" +) + func main() { // logrus.SetReportCaller(true) - log.Println(core.GetVersion()) + log.Println(getVersion()) //TODO: potentially load the config from a flag like: //configFile := flag.String("configFile", "config.yaml", "Config File full path. Defaults to current folder") @@ -31,3 +43,8 @@ func main() { panic(err) } } + +//getVersion gets the version string +func getVersion() string { + return fmt.Sprintf("Owncast v%s-%s (%s)", BuildVersion, BuildType, GitCommit) +} diff --git a/scripts/build.sh b/scripts/build.sh index f5d4646ff..674a79eff 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -50,7 +50,7 @@ build() { cp -R doc/ dist/${NAME}/doc/ cp README.md dist/${NAME} - env CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -ldflags "-X core.GitCommit=$GIT_COMMIT -X core.BuildVersion=$VERSION -X core.BuildType=$NAME" -a -o dist/$NAME/owncast + env CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -ldflags "-X main.GitCommit=$GIT_COMMIT -X main.BuildVersion=$VERSION -X main.BuildType=$NAME" -a -o dist/$NAME/owncast pushd dist/${NAME} >> /dev/null zip -r -q -8 ../owncast-$NAME-$VERSION.zip .