mirror of
https://github.com/ko-build/ko.git
synced 2025-03-03 15:32:20 +02:00
Use debug.ReadBuildInfo to populate ko version
(#81)
* Use debug.ReadBuildInfo to populate `ko version` * don't print version on build info failure * Build using Go 1.12 and 1.13 * drop 'version: ' prefix * println
This commit is contained in:
parent
99a587ede5
commit
133ae27c63
@ -6,8 +6,8 @@ language:
|
||||
- go
|
||||
|
||||
go:
|
||||
- "1.11"
|
||||
- "1.12"
|
||||
- "1.13"
|
||||
|
||||
git:
|
||||
depth: 1
|
||||
|
@ -16,10 +16,7 @@ package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -40,12 +37,12 @@ func addVersion(topLevel *cobra.Command) {
|
||||
|
||||
func version() {
|
||||
if Version == "" {
|
||||
gitDir := fmt.Sprintf("--git-dir=%v/src/github.com/google/ko/.git", os.Getenv("GOPATH"))
|
||||
hash, err := exec.Command("git", gitDir, "rev-parse", "HEAD").Output()
|
||||
if err != nil {
|
||||
log.Fatalf("error during command execution: %v", err)
|
||||
i, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
fmt.Println("could not determine build information")
|
||||
return
|
||||
}
|
||||
Version = strings.TrimSpace(string(hash))
|
||||
Version = i.Main.Version
|
||||
}
|
||||
fmt.Printf("version: %v\n", Version)
|
||||
fmt.Println(Version)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user