1
0
mirror of https://github.com/go-task/task.git synced 2025-11-25 22:32:55 +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

@@ -134,6 +134,7 @@ func run() error {
OutputStyle: flags.Output, OutputStyle: flags.Output,
TaskSorter: taskSorter, TaskSorter: taskSorter,
EnableVersionCheck: true,
} }
listOptions := task.NewListOptions(flags.List, flags.ListAll, flags.ListJson, flags.NoStatus) listOptions := task.NewListOptions(flags.List, flags.ListAll, flags.ListJson, flags.NoStatus)
if err := listOptions.Validate(); err != nil { if err := listOptions.Validate(); err != nil {

View File

@@ -246,6 +246,9 @@ func (e *Executor) setupConcurrencyState() {
} }
func (e *Executor) doVersionChecks() error { func (e *Executor) doVersionChecks() error {
if !e.EnableVersionCheck {
return nil
}
// Copy the version to avoid modifying the original // Copy the version to avoid modifying the original
schemaVersion := &semver.Version{} schemaVersion := &semver.Version{}
*schemaVersion = *e.Taskfile.Version *schemaVersion = *e.Taskfile.Version

View File

@@ -76,6 +76,7 @@ type Executor struct {
OutputStyle ast.Output OutputStyle ast.Output
TaskSorter sort.TaskSorter TaskSorter sort.TaskSorter
UserWorkingDir string UserWorkingDir string
EnableVersionCheck bool
fuzzyModel *fuzzy.Model fuzzyModel *fuzzy.Model
@@ -383,7 +384,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *ast.Call,
if err != nil { if err != nil {
return fmt.Errorf("task: failed to get variables: %w", err) 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{ err = execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: cmd.Cmd, Command: cmd.Cmd,
@@ -395,7 +396,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call *ast.Call,
Stdout: stdOut, Stdout: stdOut,
Stderr: stdErr, 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) e.Logger.Errf(logger.Red, "task: unable to close writer: %v\n", closeErr)
} }
if _, isExitError := interp.IsExitStatus(err); isExitError && cmd.IgnoreError { if _, isExitError := interp.IsExitStatus(err); isExitError && cmd.IgnoreError {

View File

@@ -250,6 +250,7 @@ func TestSpecialVars(t *testing.T) {
Stdout: &buff, Stdout: &buff,
Stderr: &buff, Stderr: &buff,
Silent: true, Silent: true,
EnableVersionCheck: true,
} }
require.NoError(t, e.Setup()) require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: test.target})) require.NoError(t, e.Run(context.Background(), &ast.Call{Task: test.target}))
@@ -1066,6 +1067,7 @@ func TestTaskVersion(t *testing.T) {
Dir: test.Dir, Dir: test.Dir,
Stdout: io.Discard, Stdout: io.Discard,
Stderr: io.Discard, Stderr: io.Discard,
EnableVersionCheck: true,
} }
err := e.Setup() err := e.Setup()
if test.wantErr { if test.wantErr {
@@ -2018,6 +2020,7 @@ func TestDisplaysErrorOnVersion1Schema(t *testing.T) {
Dir: "testdata/version/v1", Dir: "testdata/version/v1",
Stdout: io.Discard, Stdout: io.Discard,
Stderr: io.Discard, Stderr: io.Discard,
EnableVersionCheck: true,
} }
err := e.Setup() err := e.Setup()
require.Error(t, err) require.Error(t, err)
@@ -2032,6 +2035,7 @@ func TestDisplaysErrorOnVersion2Schema(t *testing.T) {
Dir: "testdata/version/v2", Dir: "testdata/version/v2",
Stdout: io.Discard, Stdout: io.Discard,
Stderr: &buff, Stderr: &buff,
EnableVersionCheck: true,
} }
err := e.Setup() err := e.Setup()
require.Error(t, err) require.Error(t, err)