1
0
mirror of https://github.com/go-task/task.git synced 2025-08-08 22:36:57 +02:00

fix: disable version check for use as an external library

Closes #1938
This commit is contained in:
Lea Anthony
2024-12-07 09:11:37 +11:00
committed by Andrey Nering
parent b3e4cfcf48
commit 69f5714e45
4 changed files with 32 additions and 23 deletions

View File

@@ -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 {

View File

@@ -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

17
task.go
View File

@@ -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
@@ -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,
@@ -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 {

View File

@@ -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}))
@@ -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 {
@@ -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)
@@ -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)