Skip to content

Commit

Permalink
Read release info from build info
Browse files Browse the repository at this point in the history
Since go1.18, vcs.revision gets compiled into the binary and can be
read.

Conveniently, debug.ReadBuildInfo has been around since go1.12, so
there's no need to conditionally compile this unless sentry-go needs to
support < go1.12 for some reason.

So in builds newer than 1.18, this key just simply won't exist and
effectively will do nothing.

This is much more convenient to detect in anything go1.18 since it's
much more common to have this compiled in.
  • Loading branch information
mattrobenolt authored and Arun Philip committed Aug 23, 2023
1 parent 82a00ab commit 968d9ca
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"os"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -66,6 +67,15 @@ func defaultRelease() (release string) {
}
}

if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" && setting.Value != "" {
Logger.Printf("Using release from debug info: %s", setting.Value)
return setting.Value
}
}
}

// Derive a version string from Git. Example outputs:
// v1.0.1-0-g9de4
// v2.0-8-g77df-dirty
Expand Down

0 comments on commit 968d9ca

Please sign in to comment.