Skip to content

go.mod integration as a tool: forward to the declared Task version #2784

@dolmen

Description

@dolmen

Description

Summary

When working in a Go module where a version of Task is declared as a tool dependency, transfer execution to go tool task.

Rationale

Since Go 1.24 the Go toolchain has special support for versioning tools in go.mod: https://go.dev/doc/modules/managing-dependencies#tools
As Task is written in Go, it can be installed as a tool (see also #2783).
But for a complete integration, it would be better to ensure that task and go tool task run the same version.
So I propose that the task command running from $PATH would delegate to the version of the task command declared in go.mod.

Proposal

When:

  1. task detects it works from a Go module (a go.mod is found in a directory up to the directory of the Taskfile.yml config)
  2. go env GO111MODULE is not off
  3. that go.mod declares a version of task (github.com/go-task/task/v[1-9][0-9]*/cmd/task) in a tool directive: the go tool command lists the declared tools
  4. there is a single tool named task declared (avoid ambiguous tool)
  5. task isn't already the exact requested version (matching runtime/debug.BuildInfo): avoid useless recursion
  6. task has been launched as a simple command (os.Args[0] is not an absolute path, and doesn't even contain a path separator): avoid infinite recursion, and let the user override this behavior

Then:

  • Pass all the received arguments (os.Args[1:]) to go tool task and exit

Related issues

Implementation hints

Usefull go commands:

  • go list tool: list tools declared in the Go module
  • go list -f '{{.ImportPath}}{{if not .Module.Main}}@{{.Module.Version}}{{end}}' tool: list tools with their versions
  • go list -f '{{.Module.Version}}' github.com/go-task/task/v3/cmd/task: list the requested version of Task

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions