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 ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| @@ -121,7 +122,7 @@ func (c *CompilerV1) HandleDynamicVar(v taskfile.Var) (string, error) { | ||||
| 		Stdout:  &stdout, | ||||
| 		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) | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package v2 | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| @@ -93,7 +94,7 @@ func (c *CompilerV2) HandleDynamicVar(v taskfile.Var) (string, error) { | ||||
| 		Stdout:  &stdout, | ||||
| 		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) | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -13,7 +13,6 @@ import ( | ||||
|  | ||||
| // RunCommandOptions is the options for the RunCommand func | ||||
| type RunCommandOptions struct { | ||||
| 	Context context.Context | ||||
| 	Command string | ||||
| 	Dir     string | ||||
| 	Env     []string | ||||
| @@ -28,7 +27,7 @@ var ( | ||||
| ) | ||||
|  | ||||
| // RunCommand runs a shell command | ||||
| func RunCommand(opts *RunCommandOptions) error { | ||||
| func RunCommand(ctx context.Context, opts *RunCommandOptions) error { | ||||
| 	if opts == nil { | ||||
| 		return ErrNilOptions | ||||
| 	} | ||||
| @@ -47,20 +46,27 @@ func RunCommand(opts *RunCommandOptions) error { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	r := interp.Runner{ | ||||
| 		Context: opts.Context, | ||||
| 		Dir:     opts.Dir, | ||||
| 		Env:     env, | ||||
| 	r, err := interp.New( | ||||
| 		interp.Dir(opts.Dir), | ||||
| 		interp.Env(env), | ||||
|  | ||||
| 		Exec: interp.DefaultExec, | ||||
| 		Open: interp.OpenDevImpls(interp.DefaultOpen), | ||||
| 		interp.Module(interp.DefaultExec), | ||||
| 		interp.Module(interp.OpenDevImpls(interp.DefaultOpen)), | ||||
|  | ||||
| 		Stdin:  opts.Stdin, | ||||
| 		Stdout: opts.Stdout, | ||||
| 		Stderr: opts.Stderr, | ||||
| 	} | ||||
| 	if err = r.Reset(); err != nil { | ||||
| 		interp.StdIO(opts.Stdin, opts.Stdout, opts.Stderr), | ||||
| 	) | ||||
| 	if err != nil { | ||||
| 		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) { | ||||
| 	for _, s := range t.Status { | ||||
| 		err := execext.RunCommand(&execext.RunCommandOptions{ | ||||
| 			Context: ctx, | ||||
| 		err := execext.RunCommand(ctx, &execext.RunCommandOptions{ | ||||
| 			Command: s, | ||||
| 			Dir:     t.Dir, | ||||
| 			Env:     getEnviron(t), | ||||
|   | ||||
							
								
								
									
										8
									
								
								task.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								task.go
									
									
									
									
									
								
							| @@ -19,7 +19,6 @@ import ( | ||||
|  | ||||
| 	"github.com/Masterminds/semver" | ||||
| 	"golang.org/x/sync/errgroup" | ||||
| 	"mvdan.cc/sh/interp" | ||||
| ) | ||||
|  | ||||
| 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) | ||||
| 			} | ||||
|  | ||||
| 			if _, ok := err.(interp.ExitCode); ok && t.IgnoreError { | ||||
| 			if execext.IsExitError(err) && t.IgnoreError { | ||||
| 				e.Logger.VerboseErrf("task: task error ignored: %v", err) | ||||
| 				continue | ||||
| 			} | ||||
| @@ -243,8 +242,7 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi | ||||
| 		defer stdOut.Close() | ||||
| 		defer stdErr.Close() | ||||
|  | ||||
| 		err := execext.RunCommand(&execext.RunCommandOptions{ | ||||
| 			Context: ctx, | ||||
| 		err := execext.RunCommand(ctx, &execext.RunCommandOptions{ | ||||
| 			Command: cmd.Cmd, | ||||
| 			Dir:     t.Dir, | ||||
| 			Env:     getEnviron(t), | ||||
| @@ -252,7 +250,7 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi | ||||
| 			Stdout:  stdOut, | ||||
| 			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) | ||||
| 			return nil | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user