Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildstamp: Fix "official" build stamping #14

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions internal/buildstamp/buildstamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package buildstamp

import (
"fmt"
"regexp"
"runtime/debug"
"strconv"
"strings"
Expand All @@ -22,9 +23,8 @@ type Vars struct {
const (
unknown = "<unknown>"

gitStatusClean = "clean"
gitStatusDirty = "modified"
gitOfficialBranch = "master"
gitStatusClean = "clean"
gitStatusDirty = "modified"
)

var (
Expand All @@ -35,6 +35,8 @@ var (

Values Vars
emptyValues Vars

gitOfficialBranchRe = regexp.MustCompile(`main|release/v[0-9]+\.[0-9]+`)
)

func init() {
Expand Down Expand Up @@ -78,7 +80,7 @@ func init() {
Values.SourceBranch = gitBranch
Values.SourceRevision = gitSha
Values.IsClean = gitSourceTreeStatus == gitStatusClean
Values.IsOfficial = gitSourceTreeStatus == gitStatusClean && gitBranch == gitOfficialBranch
Values.IsOfficial = gitSourceTreeStatus == gitStatusClean && gitOfficialBranchRe.Match([]byte(gitBranch))

if ts, err := strconv.ParseInt(buildTimestamp, 10, 64); err == nil {
Values.BuildTimestamp = time.Unix(ts, 0)
Expand Down