Skip to content

Commit

Permalink
Simplify distinction between from sources or from $GOPATH/src
Browse files Browse the repository at this point in the history
  • Loading branch information
debovema committed Mar 14, 2019
1 parent 13a79b1 commit 2c1eb75
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/flogo/gen/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// Users getting the CLI with a classic "go get" command will still have the version retrieved from the directory
// $GOPATH/src/github.com/project-flogo/cli
func main() {
currentVersion := util.GetVersion()
currentVersion := util.GetVersion(false)

f, err := os.Create("./currentversion.go")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/flogo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"github.com/project-flogo/cli/commands"
)

var Version string = "" // Not set by default, will be filled by init() function in "./currentversion.go" file, if it
// exists. This latter file is generated with a "go generate" command.
// Not set by default, will be filled by init() function in "./currentversion.go" file, if it exists.
// This latter file is generated with a "go generate" command.
var Version string = ""

//go:generate go run gen/version.go
func main() {
Expand Down
4 changes: 2 additions & 2 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func Initialize(version string) {
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "verbose output")

if len(version) > 0 {
rootCmd.Version = version
rootCmd.Version = version // use version hardcoded by a "go generate" command
} else {
rootCmd.Version = util.GetVersion()
rootCmd.Version = util.GetVersion(true) // guess version from sources in $GOPATH/src
}

rootCmd.SetVersionTemplate(VersionTpl)
Expand Down
13 changes: 4 additions & 9 deletions util/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ import (
"strings"
)

func GetVersion() string {
cmd := exec.Command("git", "remote", "get-url", "origin")
cmd.Env = append(os.Environ())

func GetVersion(fromGoPathSources bool) string {
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")
cmd := exec.Command("git", "describe", "--tags", "--dirty", "--always")
cmd.Env = append(os.Environ())

if !strings.HasSuffix(currentRemoteURL, "cli.git") { // we're not building from source but we are "go getting"
if fromGoPathSources {
gopath, set := os.LookupEnv("GOPATH")
if !set {
out, err := exec.Command("go", "env", "GOPATH").Output()
Expand Down

0 comments on commit 2c1eb75

Please sign in to comment.