Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func run() error {
dir := flags.Dir
entrypoint := flags.Entrypoint

// Initialise version
ver.Init()
Comment on lines +61 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer required after the discussed changes


if flags.Version {
fmt.Printf("Task version: %s\n", ver.GetVersionWithSum())
return nil
Expand Down Expand Up @@ -132,8 +135,9 @@ func run() error {
Stdout: os.Stdout,
Stderr: os.Stderr,

OutputStyle: flags.Output,
TaskSorter: taskSorter,
OutputStyle: flags.Output,
TaskSorter: taskSorter,
EnableVersionCheck: true,
}
listOptions := task.NewListOptions(flags.List, flags.ListAll, flags.ListJson, flags.NoStatus)
if err := listOptions.Validate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
sum = ""
)

func init() {
func Init() {
info, ok := debug.ReadBuildInfo()
if !ok || info.Main.Version == "" {
version = "unknown"
Expand Down
3 changes: 3 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func (e *Executor) setupConcurrencyState() {
}

func (e *Executor) doVersionChecks() error {
if !e.EnableVersionCheck {
return nil
}
// Copy the version to avoid modifying the original
schemaVersion := &semver.Version{}
*schemaVersion = *e.Taskfile.Version
Expand Down
17 changes: 9 additions & 8 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ type Executor struct {
Stdout io.Writer
Stderr io.Writer

Logger *logger.Logger
Compiler *compiler.Compiler
Output output.Output
OutputStyle ast.Output
TaskSorter sort.TaskSorter
UserWorkingDir string
Logger *logger.Logger
Compiler *compiler.Compiler
Output output.Output
OutputStyle ast.Output
TaskSorter sort.TaskSorter
UserWorkingDir string
EnableVersionCheck bool

fuzzyModel *fuzzy.Model

Expand Down Expand Up @@ -383,7 +384,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *ast.Call,
if err != nil {
return fmt.Errorf("task: failed to get variables: %w", err)
}
stdOut, stdErr, close := outputWrapper.WrapWriter(e.Stdout, e.Stderr, t.Prefix, outputTemplater)
stdOut, stdErr, closer := outputWrapper.WrapWriter(e.Stdout, e.Stderr, t.Prefix, outputTemplater)

err = execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: cmd.Cmd,
Expand All @@ -395,7 +396,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *ast.Call,
Stdout: stdOut,
Stderr: stdErr,
})
if closeErr := close(err); closeErr != nil {
if closeErr := closer(err); closeErr != nil {
e.Logger.Errf(logger.Red, "task: unable to close writer: %v\n", closeErr)
}
if _, isExitError := interp.IsExitStatus(err); isExitError && cmd.IgnoreError {
Expand Down
30 changes: 17 additions & 13 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ func TestSpecialVars(t *testing.T) {
t.Run(test.target, func(t *testing.T) {
var buff bytes.Buffer
e := &task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
Silent: true,
Dir: dir,
Stdout: &buff,
Stderr: &buff,
Silent: true,
EnableVersionCheck: true,
}
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: test.target}))
Expand Down Expand Up @@ -945,9 +946,10 @@ func TestTaskVersion(t *testing.T) {
for _, test := range tests {
t.Run(test.Dir, func(t *testing.T) {
e := task.Executor{
Dir: test.Dir,
Stdout: io.Discard,
Stderr: io.Discard,
Dir: test.Dir,
Stdout: io.Discard,
Stderr: io.Discard,
EnableVersionCheck: true,
}
err := e.Setup()
if test.wantErr {
Expand Down Expand Up @@ -1767,9 +1769,10 @@ func TestDynamicVariablesShouldRunOnTheTaskDir(t *testing.T) {

func TestDisplaysErrorOnVersion1Schema(t *testing.T) {
e := task.Executor{
Dir: "testdata/version/v1",
Stdout: io.Discard,
Stderr: io.Discard,
Dir: "testdata/version/v1",
Stdout: io.Discard,
Stderr: io.Discard,
EnableVersionCheck: true,
}
err := e.Setup()
require.Error(t, err)
Expand All @@ -1779,9 +1782,10 @@ func TestDisplaysErrorOnVersion1Schema(t *testing.T) {
func TestDisplaysErrorOnVersion2Schema(t *testing.T) {
var buff bytes.Buffer
e := task.Executor{
Dir: "testdata/version/v2",
Stdout: io.Discard,
Stderr: &buff,
Dir: "testdata/version/v2",
Stdout: io.Discard,
Stderr: &buff,
EnableVersionCheck: true,
}
err := e.Setup()
require.Error(t, err)
Expand Down
Loading