Skip to content

Commit

Permalink
added source hash
Browse files Browse the repository at this point in the history
  • Loading branch information
RA341 committed Mar 11, 2025
1 parent 04e233e commit 9975a6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ ENV BUILD_DATE=${BUILD_DATE}
ENV BRANCH=${BRANCH}

# build optimized binary without debugging symbols
RUN go build -ldflags "-s -w \
RUN SOURCE_HASH=$(find . -type f -name "*.go" -print0 | sort -z | xargs -0 cat | sha256sum | cut -d ' ' -f1) && \
go build -ldflags "-s -w \
-X github.com/makeopensource/leviathan/common.Version=${VERSION} \
-X github.com/makeopensource/leviathan/common.CommitInfo=${COMMIT_INFO} \
-X github.com/makeopensource/leviathan/common.BuildDate=${BUILD_DATE} \
-X github.com/makeopensource/leviathan/common.Branch=${BRANCH}" \
-X github.com/makeopensource/leviathan/common.Branch=${BRANCH} \
-X github.com/makeopensource/leviathan/common.SourceHash=${SOURCE_HASH}" \
-o leviathan

FROM alpine:latest
Expand Down
13 changes: 6 additions & 7 deletions src/common/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var Version = "dev"
var CommitInfo = "unknown"
var BuildDate = "unknown"
var Branch = "unknown" // Git branch
var SourceHash = "unknown"
var GoVersion = runtime.Version()

func PrintInfo() {
Expand Down Expand Up @@ -100,11 +101,13 @@ func PrintInfo() {
}

printField("Version", Version)
printField("CommitInfo", CommitInfo)
printField("BuildDate", formatTime(BuildDate))
printField("Branch", Branch)
printField("GoVersion", runtime.Version())
printField("CommitInfo", CommitInfo)
printField("Source Hash", SourceHash)
printField("GoVersion", GoVersion)

//nolint
if Branch != "unknown" && CommitInfo != "unknown" {
fmt.Println(nord10 + strings.Repeat("-", width) + colorReset)
githubURL := GetGitHubURL(Branch, CommitInfo)
Expand Down Expand Up @@ -160,7 +163,7 @@ const (
//
// stolen from -> https://github.com/dustin/go-humanize/blob/master/times.go
func timeago(then time.Time) string {
return RelTime(then, time.Now(), "ago", "from now")
return CustomRelTime(then, time.Now(), "ago", "from now", defaultMagnitudes)
}

type RelTimeMagnitude struct {
Expand Down Expand Up @@ -189,10 +192,6 @@ var defaultMagnitudes = []RelTimeMagnitude{
{math.MaxInt64, "a long while %s", 1},
}

func RelTime(a, b time.Time, albl, blbl string) string {
return CustomRelTime(a, b, albl, blbl, defaultMagnitudes)
}

func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string {
lbl := albl
diff := b.Sub(a)
Expand Down

0 comments on commit 9975a6c

Please sign in to comment.