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

feat(gimmeproj): improve version information using embedded build data #4260

Merged
merged 19 commits into from
Oct 25, 2024
Merged
Changes from 10 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
21 changes: 20 additions & 1 deletion testing/gimmeproj/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"fmt"
"log"
"os"
"runtime/debug"
"time"

ds "cloud.google.com/go/datastore"
Expand All @@ -38,6 +39,7 @@ var (
datastore *ds.Client

version = "dev"
buildSource = "unknown"
buildDate = "unknown"
ErrNoProjects = errors.New("could not find a free project")
)
Expand Down Expand Up @@ -92,6 +94,23 @@ func (p *Project) Expired() bool {
return time.Now().After(p.LeaseExpiry)
}

func init() {
// set version info from embedded details.
if bi, ok := debug.ReadBuildInfo(); ok {
packagename := bi.Main.Path
for _, s := range bi.Settings {
switch s.Key {
case "vcs":
buildSource = fmt.Sprintf("%s://%s", s.Value, packagename)
case "vcs.revision":
version = s.Value
case "vcs.time":
buildDate = s.Value
}
}
}
}

func main() {
flag.Parse()
if err := submain(); err != nil {
Expand Down Expand Up @@ -120,7 +139,7 @@ Administrative commands:
`)

if flag.Arg(0) == "version" {
fmt.Printf("gimmeproj %s; built at %s\n", version, buildDate)
fmt.Printf("gimmeproj %s@%s; built at %s\n", buildSource, version, buildDate)
return nil
}

Expand Down
Loading