Skip to content

Commit

Permalink
Handle building from sources instead of go getting
Browse files Browse the repository at this point in the history
  • Loading branch information
debovema committed Mar 13, 2019
1 parent 2197572 commit 13a79b1
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions util/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@ import (
)

func GetVersion() string {
cmd := exec.Command("git", "describe", "--tags", "--dirty", "--always")
gopath, set := os.LookupEnv("GOPATH")
if !set {
out, err := exec.Command("go", "env", "GOPATH").Output()
if err != nil {
log.Fatal(err)
cmd := exec.Command("git", "remote", "get-url", "origin")
cmd.Env = append(os.Environ())

re := regexp.MustCompile("\\n")

currentRemoteURLOutput, err := cmd.Output() // determine whether we're building from source
currentRemoteURL := re.ReplaceAllString(string(currentRemoteURLOutput), "")

cmd = exec.Command("git", "describe", "--tags", "--dirty", "--always")

if !strings.HasSuffix(currentRemoteURL, "cli.git") { // we're not building from source but we are "go getting"
gopath, set := os.LookupEnv("GOPATH")
if !set {
out, err := exec.Command("go", "env", "GOPATH").Output()
if err != nil {
log.Fatal(err)
}
gopath = strings.TrimSuffix(string(out), "\n")
}
gopath = strings.TrimSuffix(string(out), "\n")
cmd.Dir = filepath.Join(gopath, "src", "github.com", "project-flogo", "cli")
}
cmd.Dir = filepath.Join(gopath, "src", "github.com", "project-flogo", "cli")
cmd.Env = append(os.Environ())

out, err := cmd.Output()
out, err := cmd.Output() // execute "git describe"
if err != nil {
log.Fatal(err)
}
re := regexp.MustCompile("\\n")
fc := re.ReplaceAllString(string(out), "")

return fc
Expand Down

0 comments on commit 13a79b1

Please sign in to comment.