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

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

View File

@@ -1,5 +1,10 @@
# Changelog # Changelog
## Unreleased
- Improve version reporting when building Task from source using Go Modules
([#462](https://github.com/go-task/task/pull/462), [#473](https://github.com/go-task/task/pull/473)).
## v3.4.1 - 2021-04-17 ## v3.4.1 - 2021-04-17
- Improve error reporting when parsing YAML: in some situations where you - Improve error reporting when parsing YAML: in some situations where you

View File

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