Created
February 15, 2024 07:33
-
-
Save Bhupesh-V/9574109e6aaebe65cb054e8b3997867a to your computer and use it in GitHub Desktop.
Providing Git VCS commit info from Go
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
package main | |
import ( | |
"fmt" | |
"log" | |
"runtime/debug" | |
) | |
func main() { | |
// Only works when we do a main module build (doesn't work with direct go run) | |
// See https://github.com/golang/go/issues/51279 | |
info, _ := debug.ReadBuildInfo() | |
bi, err := debug.ParseBuildInfo(info.String()) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, dep := range bi.Settings { | |
if dep.Key == "vcs.revision" || dep.Key == "vcs.time" { | |
fmt.Println(dep.Key, dep.Value) | |
} | |
} | |
} |
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
vcs.revision ab83d948829673d24206a1e0bc67brf400cdb059 | |
vcs.time 2024-02-15T07:26:01Z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment