Skip to content

Commit

Permalink
fix: disable version check for use as an external library
Browse files Browse the repository at this point in the history
Closes #1938
  • Loading branch information
leaanthony authored and andreynering committed Jan 18, 2025
1 parent b3e4cfc commit 69f5714
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
5 changes: 3 additions & 2 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,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
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 @@ -246,10 +246,11 @@ func TestSpecialVars(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 @@ -1063,9 +1064,10 @@ func TestTaskVersion(t *testing.T) {
t.Parallel()

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 @@ -2015,9 +2017,10 @@ func TestDisplaysErrorOnVersion1Schema(t *testing.T) {
t.Parallel()

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 @@ -2029,9 +2032,10 @@ 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

0 comments on commit 69f5714

Please sign in to comment.