mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +02:00 
			
		
		
		
	Fixes after updating mvdan.cc/sh
This commit is contained in:
		| @@ -2,6 +2,7 @@ package v1 | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
|  | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
| @@ -121,7 +122,7 @@ func (c *CompilerV1) HandleDynamicVar(v taskfile.Var) (string, error) { | |||||||
| 		Stdout:  &stdout, | 		Stdout:  &stdout, | ||||||
| 		Stderr:  c.Logger.Stderr, | 		Stderr:  c.Logger.Stderr, | ||||||
| 	} | 	} | ||||||
| 	if err := execext.RunCommand(opts); err != nil { | 	if err := execext.RunCommand(context.Background(), opts); err != nil { | ||||||
| 		return "", fmt.Errorf(`task: Command "%s" in taskvars file failed: %s`, opts.Command, err) | 		return "", fmt.Errorf(`task: Command "%s" in taskvars file failed: %s`, opts.Command, err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ package v2 | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
|  | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"sync" | 	"sync" | ||||||
| @@ -93,7 +94,7 @@ func (c *CompilerV2) HandleDynamicVar(v taskfile.Var) (string, error) { | |||||||
| 		Stdout:  &stdout, | 		Stdout:  &stdout, | ||||||
| 		Stderr:  c.Logger.Stderr, | 		Stderr:  c.Logger.Stderr, | ||||||
| 	} | 	} | ||||||
| 	if err := execext.RunCommand(opts); err != nil { | 	if err := execext.RunCommand(context.Background(), opts); err != nil { | ||||||
| 		return "", fmt.Errorf(`task: Command "%s" in taskvars file failed: %s`, opts.Command, err) | 		return "", fmt.Errorf(`task: Command "%s" in taskvars file failed: %s`, opts.Command, err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,6 @@ import ( | |||||||
|  |  | ||||||
| // RunCommandOptions is the options for the RunCommand func | // RunCommandOptions is the options for the RunCommand func | ||||||
| type RunCommandOptions struct { | type RunCommandOptions struct { | ||||||
| 	Context context.Context |  | ||||||
| 	Command string | 	Command string | ||||||
| 	Dir     string | 	Dir     string | ||||||
| 	Env     []string | 	Env     []string | ||||||
| @@ -28,7 +27,7 @@ var ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| // RunCommand runs a shell command | // RunCommand runs a shell command | ||||||
| func RunCommand(opts *RunCommandOptions) error { | func RunCommand(ctx context.Context, opts *RunCommandOptions) error { | ||||||
| 	if opts == nil { | 	if opts == nil { | ||||||
| 		return ErrNilOptions | 		return ErrNilOptions | ||||||
| 	} | 	} | ||||||
| @@ -47,20 +46,27 @@ func RunCommand(opts *RunCommandOptions) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	r := interp.Runner{ | 	r, err := interp.New( | ||||||
| 		Context: opts.Context, | 		interp.Dir(opts.Dir), | ||||||
| 		Dir:     opts.Dir, | 		interp.Env(env), | ||||||
| 		Env:     env, |  | ||||||
|  |  | ||||||
| 		Exec: interp.DefaultExec, | 		interp.Module(interp.DefaultExec), | ||||||
| 		Open: interp.OpenDevImpls(interp.DefaultOpen), | 		interp.Module(interp.OpenDevImpls(interp.DefaultOpen)), | ||||||
|  |  | ||||||
| 		Stdin:  opts.Stdin, | 		interp.StdIO(opts.Stdin, opts.Stdout, opts.Stderr), | ||||||
| 		Stdout: opts.Stdout, | 	) | ||||||
| 		Stderr: opts.Stderr, | 	if err != nil { | ||||||
| 	} |  | ||||||
| 	if err = r.Reset(); err != nil { |  | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	return r.Run(p) | 	return r.Run(ctx, p) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // IsExitError returns true the given error is an exis status error | ||||||
|  | func IsExitError(err error) bool { | ||||||
|  | 	switch err.(type) { | ||||||
|  | 	case interp.ExitStatus, interp.ShellExitStatus: | ||||||
|  | 		return true | ||||||
|  | 	default: | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -71,8 +71,7 @@ func getStatusChecker(t *taskfile.Task) (status.Checker, error) { | |||||||
|  |  | ||||||
| func isTaskUpToDateStatus(ctx context.Context, t *taskfile.Task) (bool, error) { | func isTaskUpToDateStatus(ctx context.Context, t *taskfile.Task) (bool, error) { | ||||||
| 	for _, s := range t.Status { | 	for _, s := range t.Status { | ||||||
| 		err := execext.RunCommand(&execext.RunCommandOptions{ | 		err := execext.RunCommand(ctx, &execext.RunCommandOptions{ | ||||||
| 			Context: ctx, |  | ||||||
| 			Command: s, | 			Command: s, | ||||||
| 			Dir:     t.Dir, | 			Dir:     t.Dir, | ||||||
| 			Env:     getEnviron(t), | 			Env:     getEnviron(t), | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								task.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								task.go
									
									
									
									
									
								
							| @@ -19,7 +19,6 @@ import ( | |||||||
|  |  | ||||||
| 	"github.com/Masterminds/semver" | 	"github.com/Masterminds/semver" | ||||||
| 	"golang.org/x/sync/errgroup" | 	"golang.org/x/sync/errgroup" | ||||||
| 	"mvdan.cc/sh/interp" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| @@ -198,7 +197,7 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { | |||||||
| 				e.Logger.VerboseErrf("task: error cleaning status on error: %v", err2) | 				e.Logger.VerboseErrf("task: error cleaning status on error: %v", err2) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if _, ok := err.(interp.ExitCode); ok && t.IgnoreError { | 			if execext.IsExitError(err) && t.IgnoreError { | ||||||
| 				e.Logger.VerboseErrf("task: task error ignored: %v", err) | 				e.Logger.VerboseErrf("task: task error ignored: %v", err) | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| @@ -243,8 +242,7 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi | |||||||
| 		defer stdOut.Close() | 		defer stdOut.Close() | ||||||
| 		defer stdErr.Close() | 		defer stdErr.Close() | ||||||
|  |  | ||||||
| 		err := execext.RunCommand(&execext.RunCommandOptions{ | 		err := execext.RunCommand(ctx, &execext.RunCommandOptions{ | ||||||
| 			Context: ctx, |  | ||||||
| 			Command: cmd.Cmd, | 			Command: cmd.Cmd, | ||||||
| 			Dir:     t.Dir, | 			Dir:     t.Dir, | ||||||
| 			Env:     getEnviron(t), | 			Env:     getEnviron(t), | ||||||
| @@ -252,7 +250,7 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi | |||||||
| 			Stdout:  stdOut, | 			Stdout:  stdOut, | ||||||
| 			Stderr:  stdErr, | 			Stderr:  stdErr, | ||||||
| 		}) | 		}) | ||||||
| 		if _, ok := err.(interp.ExitCode); ok && cmd.IgnoreError { | 		if execext.IsExitError(err) && cmd.IgnoreError { | ||||||
| 			e.Logger.VerboseErrf("task: command error ignored: %v", err) | 			e.Logger.VerboseErrf("task: command error ignored: %v", err) | ||||||
| 			return nil | 			return nil | ||||||
| 		} | 		} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user