Skip to content

Commit

Permalink
Add git branch to version package (flyteorg#151)
Browse files Browse the repository at this point in the history
* Add git branch to version package

Signed-off-by: Iaroslav Ciupin <iaroslav@union.ai>
  • Loading branch information
iaroslav-ciupin committed Feb 11, 2023
1 parent 9ad34a1 commit 406ca6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion flytestdlib/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package version

import (
"fmt"
"time"

"github.com/sirupsen/logrus"
Expand All @@ -18,12 +19,18 @@ var (
Version = "unknown"
// Build timestamp
BuildTime = time.Now().String()
// Git branch that was used to build the binary
GitBranch = ""
)

// Use this method to log the build information for the current app. The app name should be provided. To inject the build
// and version information refer to the top-level comment in this file
func LogBuildInformation(appName string) {
logrus.Info("------------------------------------------------------------------------")
logrus.Infof("App [%s], Version [%s], BuildSHA [%s], BuildTS [%s]", appName, Version, Build, BuildTime)
msg := fmt.Sprintf("App [%s], Version [%s], BuildSHA [%s], BuildTS [%s]", appName, Version, Build, BuildTime)
if GitBranch != "" {
msg += fmt.Sprintf(", Git Branch [%s]", GitBranch)
}
logrus.Info(msg)
logrus.Info("------------------------------------------------------------------------")
}
3 changes: 2 additions & 1 deletion flytestdlib/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ func TestLogBuildInformation(t *testing.T) {

n := time.Now()
BuildTime = n.String()
GitBranch = "main"
buf := bytes.NewBufferString("")
logrus.SetFormatter(dFormat{})
logrus.SetOutput(buf)
LogBuildInformation("hello")
assert.Equal(t, buf.String(), fmt.Sprintf("------------------------------------------------------------------------App [hello], Version [unknown], BuildSHA [unknown], BuildTS [%s]------------------------------------------------------------------------", n.String()))
assert.Equal(t, buf.String(), fmt.Sprintf("------------------------------------------------------------------------App [hello], Version [unknown], BuildSHA [unknown], BuildTS [%s], Git Branch [main]------------------------------------------------------------------------", n.String()))
}

0 comments on commit 406ca6c

Please sign in to comment.