mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
Allow ignore_error at task level
This commit is contained in:
parent
c70343a5bc
commit
feaf70922d
@ -5,17 +5,18 @@ type Tasks map[string]*Task
|
||||
|
||||
// Task represents a task
|
||||
type Task struct {
|
||||
Task string
|
||||
Cmds []*Cmd
|
||||
Deps []*Dep
|
||||
Desc string
|
||||
Sources []string
|
||||
Generates []string
|
||||
Status []string
|
||||
Dir string
|
||||
Vars Vars
|
||||
Env Vars
|
||||
Silent bool
|
||||
Method string
|
||||
Prefix string
|
||||
Task string
|
||||
Cmds []*Cmd
|
||||
Deps []*Dep
|
||||
Desc string
|
||||
Sources []string
|
||||
Generates []string
|
||||
Status []string
|
||||
Dir string
|
||||
Vars Vars
|
||||
Env Vars
|
||||
Silent bool
|
||||
Method string
|
||||
Prefix string
|
||||
IgnoreError bool `yaml:"ignore_error"`
|
||||
}
|
||||
|
6
task.go
6
task.go
@ -182,6 +182,12 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
||||
if err2 := statusOnError(t); err2 != nil {
|
||||
e.Logger.VerboseErrf("task: error cleaning status on error: %v", err2)
|
||||
}
|
||||
|
||||
if _, ok := err.(interp.ExitCode); ok && t.IgnoreError {
|
||||
e.Logger.VerboseErrf("task: task error ignored: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
return &taskRunError{t.Task, err}
|
||||
}
|
||||
}
|
||||
|
20
task_test.go
20
task_test.go
@ -416,6 +416,26 @@ func TestTaskVersion(t *testing.T) {
|
||||
func TestTaskIgnoreErrors(t *testing.T) {
|
||||
const dir = "testdata/ignore_errors"
|
||||
|
||||
t.Run("task-should-pass", func(t *testing.T) {
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: ioutil.Discard,
|
||||
Stderr: ioutil.Discard,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(taskfile.Call{Task: "task-should-pass"}))
|
||||
})
|
||||
|
||||
t.Run("task-should-fail", func(t *testing.T) {
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: ioutil.Discard,
|
||||
Stderr: ioutil.Discard,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.Error(t, e.Run(taskfile.Call{Task: "task-should-fail"}))
|
||||
})
|
||||
|
||||
t.Run("cmd-should-pass", func(t *testing.T) {
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
|
13
testdata/ignore_errors/Taskfile.yml
vendored
13
testdata/ignore_errors/Taskfile.yml
vendored
@ -1,6 +1,15 @@
|
||||
version: 2
|
||||
version: '2'
|
||||
|
||||
tasks:
|
||||
task-should-pass:
|
||||
cmds:
|
||||
- exit 1
|
||||
ignore_error: true
|
||||
|
||||
task-should-fail:
|
||||
cmds:
|
||||
- exit 1
|
||||
|
||||
cmd-should-pass:
|
||||
cmds:
|
||||
- cmd: exit 1
|
||||
@ -8,4 +17,4 @@ tasks:
|
||||
|
||||
cmd-should-fail:
|
||||
cmds:
|
||||
- cmd: exit 1
|
||||
- cmd: exit 1
|
||||
|
23
variables.go
23
variables.go
@ -24,17 +24,18 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||
r := templater.Templater{Vars: vars}
|
||||
|
||||
new := taskfile.Task{
|
||||
Task: origTask.Task,
|
||||
Desc: r.Replace(origTask.Desc),
|
||||
Sources: r.ReplaceSlice(origTask.Sources),
|
||||
Generates: r.ReplaceSlice(origTask.Generates),
|
||||
Status: r.ReplaceSlice(origTask.Status),
|
||||
Dir: r.Replace(origTask.Dir),
|
||||
Vars: nil,
|
||||
Env: r.ReplaceVars(origTask.Env),
|
||||
Silent: origTask.Silent,
|
||||
Method: r.Replace(origTask.Method),
|
||||
Prefix: r.Replace(origTask.Prefix),
|
||||
Task: origTask.Task,
|
||||
Desc: r.Replace(origTask.Desc),
|
||||
Sources: r.ReplaceSlice(origTask.Sources),
|
||||
Generates: r.ReplaceSlice(origTask.Generates),
|
||||
Status: r.ReplaceSlice(origTask.Status),
|
||||
Dir: r.Replace(origTask.Dir),
|
||||
Vars: nil,
|
||||
Env: r.ReplaceVars(origTask.Env),
|
||||
Silent: origTask.Silent,
|
||||
Method: r.Replace(origTask.Method),
|
||||
Prefix: r.Replace(origTask.Prefix),
|
||||
IgnoreError: origTask.IgnoreError,
|
||||
}
|
||||
new.Dir, err = shell.Expand(new.Dir, nil)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user