1
0
mirror of https://github.com/go-task/task.git synced 2025-02-03 13:22:11 +02:00

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

This commit is contained in:
Jamie Edge 2021-04-04 12:57:58 +01:00
parent 0c91011e88
commit 2a3f049336
2 changed files with 26 additions and 4 deletions

View File

@ -17,6 +17,11 @@ build:
goarch: 386
env:
- CGO_ENABLED=0
ldflags:
- -s -w # Don't set main.version.
gomod:
proxy: true
archives:
- name_template: "{{.Binary}}_{{.Os}}_{{.Arch}}"

View File

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