Updated the version output to use Go module build information if avalable. Enabled GoReleaser module proxying for verifiable builds.

Co-authored-by: Jamie Edge <JamieEdge@users.noreply.github.com>
Co-authored-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
Andrey Nering
2021-04-23 17:33:13 -03:00
parent 0ae1681d9c
commit 53b2cebb66
3 changed files with 32 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"strings"
"syscall"
@@ -19,7 +20,7 @@ import (
)
var (
version = "master"
version = ""
)
const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--taskfile] [--dry] [--summary] [task...]
@@ -93,7 +94,7 @@ func main() {
pflag.Parse()
if versionFlag {
fmt.Printf("Task version: %s\n", version)
fmt.Printf("Task version: %s\n", getVersion())
return
}
@@ -217,3 +218,21 @@ func getSignalContext() context.Context {
}()
return ctx
}
func getVersion() string {
if version != "" {
return version
}
info, ok := debug.ReadBuildInfo()
if !ok || info.Main.Version == "" {
return "unknown"
}
version = info.Main.Version
if info.Main.Sum != "" {
version += fmt.Sprintf(" (%s)", info.Main.Sum)
}
return version
}