-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
221 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"runtime/debug" | ||
"time" | ||
|
||
"go.uber.org/fx" | ||
) | ||
|
||
// Module exported for initialising a new build Info. | ||
var Module = fx.Options( | ||
fx.Provide(New), | ||
) | ||
|
||
// Info contains the information about the build. | ||
type Info struct { | ||
Revision string `json:"revision"` | ||
LastCommit time.Time `json:"last_commit"` | ||
DirtyBuild bool `json:"dirty_build"` | ||
} | ||
|
||
// New returns a new instance of Info. | ||
func New() (*Info, error) { | ||
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return nil, fmt.Errorf("failed to read build info") | ||
} | ||
|
||
info := Info{ | ||
Revision: "n/a", | ||
LastCommit: time.Time{}, | ||
DirtyBuild: false, | ||
} | ||
|
||
for i := range bi.Settings { | ||
kv := &bi.Settings[i] | ||
|
||
switch kv.Key { | ||
case "vcs.revision": | ||
info.Revision = kv.Value | ||
case "vcs.time": | ||
hash, err := time.Parse(time.RFC3339, kv.Value) | ||
if err != nil { | ||
log.Printf("failed to parse vcs.time: %v", err) | ||
} | ||
|
||
info.LastCommit = hash | ||
case "vcs.modified": | ||
info.DirtyBuild = kv.Value == "true" | ||
} | ||
} | ||
|
||
return &info, nil | ||
} |
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
Oops, something went wrong.