mirror of
https://github.com/go-task/task.git
synced 2025-02-01 13:17:56 +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
|
// Task represents a task
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Task string
|
Task string
|
||||||
Cmds []*Cmd
|
Cmds []*Cmd
|
||||||
Deps []*Dep
|
Deps []*Dep
|
||||||
Desc string
|
Desc string
|
||||||
Sources []string
|
Sources []string
|
||||||
Generates []string
|
Generates []string
|
||||||
Status []string
|
Status []string
|
||||||
Dir string
|
Dir string
|
||||||
Vars Vars
|
Vars Vars
|
||||||
Env Vars
|
Env Vars
|
||||||
Silent bool
|
Silent bool
|
||||||
Method string
|
Method string
|
||||||
Prefix 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 {
|
if err2 := statusOnError(t); err2 != nil {
|
||||||
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 {
|
||||||
|
e.Logger.VerboseErrf("task: task error ignored: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
return &taskRunError{t.Task, err}
|
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) {
|
func TestTaskIgnoreErrors(t *testing.T) {
|
||||||
const dir = "testdata/ignore_errors"
|
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) {
|
t.Run("cmd-should-pass", func(t *testing.T) {
|
||||||
e := task.Executor{
|
e := task.Executor{
|
||||||
Dir: dir,
|
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:
|
tasks:
|
||||||
|
task-should-pass:
|
||||||
|
cmds:
|
||||||
|
- exit 1
|
||||||
|
ignore_error: true
|
||||||
|
|
||||||
|
task-should-fail:
|
||||||
|
cmds:
|
||||||
|
- exit 1
|
||||||
|
|
||||||
cmd-should-pass:
|
cmd-should-pass:
|
||||||
cmds:
|
cmds:
|
||||||
- cmd: exit 1
|
- cmd: exit 1
|
||||||
@ -8,4 +17,4 @@ tasks:
|
|||||||
|
|
||||||
cmd-should-fail:
|
cmd-should-fail:
|
||||||
cmds:
|
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}
|
r := templater.Templater{Vars: vars}
|
||||||
|
|
||||||
new := taskfile.Task{
|
new := taskfile.Task{
|
||||||
Task: origTask.Task,
|
Task: origTask.Task,
|
||||||
Desc: r.Replace(origTask.Desc),
|
Desc: r.Replace(origTask.Desc),
|
||||||
Sources: r.ReplaceSlice(origTask.Sources),
|
Sources: r.ReplaceSlice(origTask.Sources),
|
||||||
Generates: r.ReplaceSlice(origTask.Generates),
|
Generates: r.ReplaceSlice(origTask.Generates),
|
||||||
Status: r.ReplaceSlice(origTask.Status),
|
Status: r.ReplaceSlice(origTask.Status),
|
||||||
Dir: r.Replace(origTask.Dir),
|
Dir: r.Replace(origTask.Dir),
|
||||||
Vars: nil,
|
Vars: nil,
|
||||||
Env: r.ReplaceVars(origTask.Env),
|
Env: r.ReplaceVars(origTask.Env),
|
||||||
Silent: origTask.Silent,
|
Silent: origTask.Silent,
|
||||||
Method: r.Replace(origTask.Method),
|
Method: r.Replace(origTask.Method),
|
||||||
Prefix: r.Replace(origTask.Prefix),
|
Prefix: r.Replace(origTask.Prefix),
|
||||||
|
IgnoreError: origTask.IgnoreError,
|
||||||
}
|
}
|
||||||
new.Dir, err = shell.Expand(new.Dir, nil)
|
new.Dir, err = shell.Expand(new.Dir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user