Skip to content

Commit

Permalink
Add notice to build info if build is dirty (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored Nov 2, 2022
1 parent 5f103cc commit 24f6408
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion experimental/command/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func BuildInfo(manifest model.Manifest) (string, error) {
revision string
revisionShort string
buildTime time.Time
dirty bool
)
for _, s := range info.Settings {
switch s.Key {
Expand All @@ -40,6 +41,10 @@ func BuildInfo(manifest model.Manifest) (string, error) {
if err != nil {
return "", err
}
case "vcs.modified":
if s.Value == "true" {
dirty = true
}
}
}

Expand All @@ -50,12 +55,18 @@ func BuildInfo(manifest model.Manifest) (string, error) {
path = strings.TrimSuffix(path, matches[len(matches)-1])
}

dirtyText := ""
if dirty {
dirtyText = " (dirty)"
}

commit := fmt.Sprintf("[%s](https://%s/commit/%s)", revisionShort, path, revision)

return fmt.Sprintf("%s version: %s, %s, built %s with %s\n",
return fmt.Sprintf("%s version: %s, %s%s, built %s with %s\n",
manifest.Name,
manifest.Version,
commit,
dirtyText,
buildTime.Format(time.RFC1123),
info.GoVersion),
nil
Expand Down

0 comments on commit 24f6408

Please sign in to comment.