Skip to content

Commit

Permalink
refactor following review
Browse files Browse the repository at this point in the history
  • Loading branch information
vmaerten committed May 20, 2024
1 parent 03df707 commit 50ee3cb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func run() error {
entrypoint := flags.Entrypoint

if flags.Version {
fmt.Printf("Task version: %s\n", ver.GetVersion(true))
fmt.Printf("Task version: %s\n", ver.GetVersionWithSum())
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ func (c *Compiler) getSpecialVars(t *ast.Task) (map[string]string, error) {
"TASKFILE": t.Location.Taskfile,
"TASKFILE_DIR": filepath.Dir(t.Location.Taskfile),
"USER_WORKING_DIR": c.UserWorkingDir,
"TASK_VERSION": version.GetVersion(false),
"TASK_VERSION": version.GetVersion(),
}, nil
}
28 changes: 16 additions & 12 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ import (
"runtime/debug"
)

var version = ""

func GetVersion(withSum bool) string {
if version != "" {
return version
}
var (
version = ""
sum = ""
)

func init() {
info, ok := debug.ReadBuildInfo()
if !ok || info.Main.Version == "" {
return "unknown"
version = "unknown"
} else {
version = info.Main.Version
sum = info.Main.Sum
}
}

ver := info.Main.Version
if info.Main.Sum != "" && withSum {
ver += fmt.Sprintf(" (%s)", info.Main.Sum)
}
return ver
func GetVersion() string {
return version
}

func GetVersionWithSum() string {
return fmt.Sprintf("%s (%s)", version, sum)
}
2 changes: 1 addition & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (e *Executor) doVersionChecks() error {

// Get the current version of Task
// If we can't parse the version (e.g. when its "devel"), then ignore the current version checks
currentVersion, err := semver.NewVersion(version.GetVersion(false))
currentVersion, err := semver.NewVersion(version.GetVersion())
if err != nil {
return nil
}
Expand Down

0 comments on commit 50ee3cb

Please sign in to comment.