This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7c5e98
commit 76e1920
Showing
6 changed files
with
19 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,13 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"runtime/debug" | ||
"github.com/acorn-io/baaah/pkg/version" | ||
) | ||
|
||
var ( | ||
Tag = "v0.0.0-dev" | ||
) | ||
|
||
type Version struct { | ||
Tag string `json:"tag,omitempty"` | ||
Commit string `json:"commit,omitempty"` | ||
Dirty bool `json:"dirty,omitempty"` | ||
} | ||
|
||
func (v Version) String() string { | ||
if len(v.Commit) < 12 { | ||
return v.Tag | ||
} else if v.Dirty { | ||
return fmt.Sprintf("%s-%s-dirty", v.Tag, v.Commit[:8]) | ||
} | ||
|
||
return fmt.Sprintf("%s+%s", v.Tag, v.Commit[:8]) | ||
} | ||
|
||
func Get() Version { | ||
v := Version{ | ||
Tag: Tag, | ||
} | ||
v.Commit, v.Dirty = GitCommit() | ||
return v | ||
} | ||
|
||
func GitCommit() (commit string, dirty bool) { | ||
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return "", false | ||
} | ||
for _, setting := range bi.Settings { | ||
switch setting.Key { | ||
case "vcs.modified": | ||
dirty = setting.Value == "true" | ||
case "vcs.revision": | ||
commit = setting.Value | ||
} | ||
} | ||
|
||
return | ||
} | ||
func Get() version.Version { | ||
return version.NewVersion(Tag) | ||
} |