diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..6adf4e27 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +open_collective: task diff --git a/.gitignore b/.gitignore index d5340eb2..c5de0bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ dist/ # intellij idea/goland .idea/ + +# exuberant ctags +tags diff --git a/CHANGELOG.md b/CHANGELOG.md index 6facc17d..c7d83880 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Unreleased + +- Fixed some bugs regarding minor version checks on `version:`. +- Add `preconditions:` to task + ([#205](https://github.com/go-task/task/pull/205)). +- Create directory informed on `dir:` if it doesn't exist + ([#209](https://github.com/go-task/task/issues/209), [#211](https://github.com/go-task/task/pull/211)). + ## v2.5.2 - 2019-05-11 - Reverted YAML upgrade due issues with CRLF on Windows diff --git a/docs/taskfile_versions.md b/docs/taskfile_versions.md index 82c80463..a318f12a 100644 --- a/docs/taskfile_versions.md +++ b/docs/taskfile_versions.md @@ -141,6 +141,21 @@ includes: docker: ./DockerTasks.yml ``` +## Version 2.6 + +Version 2.6 comes with `preconditions` stanza in tasks. + +```yaml +version: '2' + +tasks: + upload_environment: + preconditions: + - test -f .env + cmds: + - aws s3 cp .env s3://myenvironment +``` + Please check the [documentation][includes] [output]: usage.md#output-syntax diff --git a/docs/usage.md b/docs/usage.md index 40c3dd4a..ea42b945 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -344,6 +344,55 @@ up-to-date. Also, `task --status [tasks]...` will exit with a non-zero exit code if any of the tasks are not up-to-date. +If you need a certain set of conditions to be _true_ you can use the +`preconditions` stanza. `preconditions` are very similar to `status` +lines except they support `sh` expansion and they SHOULD all return 0. + +```yaml +version: '2' + +tasks: + generate-files: + cmds: + - mkdir directory + - touch directory/file1.txt + - touch directory/file2.txt + # test existence of files + preconditions: + - test -f .env + - sh: "[ 1 = 0 ]" + msg: "One doesn't equal Zero, Halting" +``` + +Preconditions can set specific failure messages that can tell +a user what steps to take using the `msg` field. + +If a task has a dependency on a sub-task with a precondition, and that +precondition is not met - the calling task will fail. Note that a task +executed with a failing precondition will not run unless `--force` is +given. + +Unlike `status` which will skip a task if it is up to date, and continue +executing tasks that depend on it, a `precondition` will fail a task, along +with any other tasks that depend on it. + +```yaml +version: '2' +tasks: + task_will_fail: + preconditions: + - sh: "exit 1" + + task_will_also_fail: + deps: + - task_will_fail + + task_will_still_fail: + cmds: + - task: task_will_fail + - echo "I will not run" +``` + ## Variables When doing interpolation of variables, Task will look for the below. @@ -385,7 +434,7 @@ version: '2' tasks: print-var: cmds: - echo "{{.VAR}}" + - echo "{{.VAR}}" vars: VAR: Hello! ``` diff --git a/go.mod b/go.mod index 7074204a..0a730d83 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/go-task/task/v2 require ( - github.com/Masterminds/semver v1.4.2 + github.com/Masterminds/semver v1.4.2 // indirect github.com/Masterminds/sprig v2.16.0+incompatible github.com/aokoli/goutils v1.0.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/internal/taskfile/precondition.go b/internal/taskfile/precondition.go new file mode 100644 index 00000000..04c1e532 --- /dev/null +++ b/internal/taskfile/precondition.go @@ -0,0 +1,45 @@ +package taskfile + +import ( + "errors" + "fmt" +) + +var ( + // ErrCantUnmarshalPrecondition is returned for invalid precond YAML. + ErrCantUnmarshalPrecondition = errors.New("task: Can't unmarshal precondition value") +) + +// Precondition represents a precondition necessary for a task to run +type Precondition struct { + Sh string + Msg string +} + +// UnmarshalYAML implements yaml.Unmarshaler interface. +func (p *Precondition) UnmarshalYAML(unmarshal func(interface{}) error) error { + var cmd string + + if err := unmarshal(&cmd); err == nil { + p.Sh = cmd + p.Msg = fmt.Sprintf("`%s` failed", cmd) + return nil + } + + var sh struct { + Sh string + Msg string + } + + if err := unmarshal(&sh); err != nil { + return err + } + + p.Sh = sh.Sh + p.Msg = sh.Msg + if p.Msg == "" { + p.Msg = fmt.Sprintf("%s failed", sh.Sh) + } + + return nil +} diff --git a/internal/taskfile/precondition_test.go b/internal/taskfile/precondition_test.go new file mode 100644 index 00000000..799e9ac4 --- /dev/null +++ b/internal/taskfile/precondition_test.go @@ -0,0 +1,48 @@ +package taskfile_test + +import ( + "testing" + + "github.com/go-task/task/v2/internal/taskfile" + + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v2" +) + +func TestPreconditionParse(t *testing.T) { + tests := []struct { + content string + v interface{} + expected interface{} + }{ + { + "test -f foo.txt", + &taskfile.Precondition{}, + &taskfile.Precondition{Sh: `test -f foo.txt`, Msg: "`test -f foo.txt` failed"}, + }, + { + "sh: '[ 1 = 0 ]'", + &taskfile.Precondition{}, + &taskfile.Precondition{Sh: "[ 1 = 0 ]", Msg: "[ 1 = 0 ] failed"}, + }, + {` +sh: "[ 1 = 2 ]" +msg: "1 is not 2" +`, + &taskfile.Precondition{}, + &taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"}, + }, + {` +sh: "[ 1 = 2 ]" +msg: "1 is not 2" +`, + &taskfile.Precondition{}, + &taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"}, + }, + } + for _, test := range tests { + err := yaml.Unmarshal([]byte(test.content), test.v) + assert.NoError(t, err) + assert.Equal(t, test.expected, test.v) + } +} diff --git a/internal/taskfile/task.go b/internal/taskfile/task.go index 1afcbfa3..bc4bf981 100644 --- a/internal/taskfile/task.go +++ b/internal/taskfile/task.go @@ -5,19 +5,20 @@ type Tasks map[string]*Task // Task represents a task type Task struct { - Task string - Cmds []*Cmd - Deps []*Dep - Desc string - Summary string - Sources []string - Generates []string - Status []string - Dir string - Vars Vars - Env Vars - Silent bool - Method string - Prefix string - IgnoreError bool `yaml:"ignore_error"` + Task string + Cmds []*Cmd + Deps []*Dep + Desc string + Summary string + Sources []string + Generates []string + Status []string + Preconditions []*Precondition + Dir string + Vars Vars + Env Vars + Silent bool + Method string + Prefix string + IgnoreError bool `yaml:"ignore_error"` } diff --git a/internal/taskfile/version/version.go b/internal/taskfile/version/version.go deleted file mode 100644 index bb2176e4..00000000 --- a/internal/taskfile/version/version.go +++ /dev/null @@ -1,46 +0,0 @@ -package version - -import ( - "github.com/Masterminds/semver" -) - -var ( - v1 = mustVersion("1") - v2 = mustVersion("2") - v21 = mustVersion("2.1") - v22 = mustVersion("2.2") - v23 = mustVersion("2.3") -) - -// IsV1 returns if is a given Taskfile version is version 1 -func IsV1(v *semver.Constraints) bool { - return v.Check(v1) -} - -// IsV2 returns if is a given Taskfile version is at least version 2 -func IsV2(v *semver.Constraints) bool { - return v.Check(v2) -} - -// IsV21 returns if is a given Taskfile version is at least version 2.1 -func IsV21(v *semver.Constraints) bool { - return v.Check(v21) -} - -// IsV22 returns if is a given Taskfile version is at least version 2.2 -func IsV22(v *semver.Constraints) bool { - return v.Check(v22) -} - -// IsV23 returns if is a given Taskfile version is at least version 2.3 -func IsV23(v *semver.Constraints) bool { - return v.Check(v23) -} - -func mustVersion(s string) *semver.Version { - v, err := semver.NewVersion(s) - if err != nil { - panic(err) - } - return v -} diff --git a/precondition.go b/precondition.go new file mode 100644 index 00000000..eff123a0 --- /dev/null +++ b/precondition.go @@ -0,0 +1,31 @@ +package task + +import ( + "context" + "errors" + + "github.com/go-task/task/v2/internal/execext" + "github.com/go-task/task/v2/internal/taskfile" +) + +var ( + // ErrPreconditionFailed is returned when a precondition fails + ErrPreconditionFailed = errors.New("task: precondition not met") +) + +func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *taskfile.Task) (bool, error) { + for _, p := range t.Preconditions { + err := execext.RunCommand(ctx, &execext.RunCommandOptions{ + Command: p.Sh, + Dir: t.Dir, + Env: getEnviron(t), + }) + + if err != nil { + e.Logger.Errf("task: %s", p.Msg) + return false, ErrPreconditionFailed + } + } + + return true, nil +} diff --git a/status.go b/status.go index 173be34b..7ebb5f84 100644 --- a/status.go +++ b/status.go @@ -78,8 +78,10 @@ func (e *Executor) isTaskUpToDateStatus(ctx context.Context, t *taskfile.Task) ( Env: getEnviron(t), }) if err != nil { + e.Logger.VerboseOutf("task: status command %s exited non-zero: %s", s, err) return false, nil } + e.Logger.VerboseOutf("task: status command %s exited zero", s) } return true, nil } diff --git a/task.go b/task.go index b7a2dec4..f7b4e1c3 100644 --- a/task.go +++ b/task.go @@ -2,9 +2,12 @@ package task import ( "context" + "errors" "fmt" "io" "os" + "strconv" + "sync" "sync/atomic" "github.com/go-task/task/v2/internal/compiler" @@ -16,9 +19,7 @@ import ( "github.com/go-task/task/v2/internal/summary" "github.com/go-task/task/v2/internal/taskfile" "github.com/go-task/task/v2/internal/taskfile/read" - "github.com/go-task/task/v2/internal/taskfile/version" - "github.com/Masterminds/semver" "golang.org/x/sync/errgroup" ) @@ -51,6 +52,7 @@ type Executor struct { taskvars taskfile.Vars taskCallCount map[string]*int32 + mkdirMutexMap map[string]*sync.Mutex } // Run runs Task @@ -93,11 +95,6 @@ func (e *Executor) Setup() error { return err } - v, err := semver.NewConstraint(e.Taskfile.Version) - if err != nil { - return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err) - } - if e.Stdin == nil { e.Stdin = os.Stdin } @@ -112,14 +109,30 @@ func (e *Executor) Setup() error { Stderr: e.Stderr, Verbose: e.Verbose, } - switch { - case version.IsV1(v): + + v, err := strconv.ParseFloat(e.Taskfile.Version, 64) + if err != nil { + return fmt.Errorf(`task: Could not parse taskfile version "%s": %v`, e.Taskfile.Version, err) + } + // consider as equal to the greater version if round + if v == 2.0 { + v = 2.6 + } + + if v < 1 { + return fmt.Errorf(`task: Taskfile version should be greater or equal to v1`) + } + if v > 2.6 { + return fmt.Errorf(`task: Taskfile versions greater than v2.6 not implemented in the version of Task`) + } + + if v < 2 { e.Compiler = &compilerv1.CompilerV1{ Dir: e.Dir, Vars: e.taskvars, Logger: e.Logger, } - case version.IsV2(v), version.IsV21(v), version.IsV22(v): + } else { // v >= 2 e.Compiler = &compilerv2.CompilerV2{ Dir: e.Dir, Taskvars: e.taskvars, @@ -127,16 +140,15 @@ func (e *Executor) Setup() error { Expansions: e.Taskfile.Expansions, Logger: e.Logger, } - case version.IsV23(v): - return fmt.Errorf(`task: Taskfile versions greater than v2.3 not implemented in the version of Task`) } - if !version.IsV21(v) && e.Taskfile.Output != "" { + if v < 2.1 && e.Taskfile.Output != "" { return fmt.Errorf(`task: Taskfile option "output" is only available starting on Taskfile version v2.1`) } - if !version.IsV22(v) && len(e.Taskfile.Includes) > 0 { + if v < 2.2 && len(e.Taskfile.Includes) > 0 { return fmt.Errorf(`task: Including Taskfiles is only available starting on Taskfile version v2.2`) } + if e.OutputStyle != "" { e.Taskfile.Output = e.OutputStyle } @@ -151,8 +163,8 @@ func (e *Executor) Setup() error { return fmt.Errorf(`task: output option "%s" not recognized`, e.Taskfile.Output) } - if !version.IsV21(v) { - err := fmt.Errorf(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`) + if v <= 2.1 { + err := errors.New(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`) for _, task := range e.Taskfile.Tasks { if task.IgnoreError { @@ -166,9 +178,19 @@ func (e *Executor) Setup() error { } } + if v < 2.6 { + for _, task := range e.Taskfile.Tasks { + if len(task.Preconditions) > 0 { + return errors.New(`task: Task option "preconditions" is only available starting on Taskfile version v2.6`) + } + } + } + e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks)) + e.mkdirMutexMap = make(map[string]*sync.Mutex, len(e.Taskfile.Tasks)) for k := range e.Taskfile.Tasks { e.taskCallCount[k] = new(int32) + e.mkdirMutexMap[k] = &sync.Mutex{} } return nil } @@ -188,11 +210,17 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { } if !e.Force { + preCondMet, err := e.areTaskPreconditionsMet(ctx, t) + if err != nil { + return err + } + upToDate, err := e.isTaskUpToDate(ctx, t) if err != nil { return err } - if upToDate { + + if upToDate && preCondMet { if !e.Silent { e.Logger.Errf(logger.Magenta, `task: Task "%s" is up to date`, t.Task) } @@ -200,6 +228,10 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { } } + if err := e.mkdir(t); err != nil { + e.Logger.Errf("task: cannot make directory %q: %v", t.Dir, err) + } + for i := range t.Cmds { if err := e.runCommand(ctx, t, call, i); err != nil { if err2 := e.statusOnError(t); err2 != nil { @@ -217,6 +249,23 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { return nil } +func (e *Executor) mkdir(t *taskfile.Task) error { + if t.Dir == "" { + return nil + } + + mutex := e.mkdirMutexMap[t.Task] + mutex.Lock() + defer mutex.Unlock() + + if _, err := os.Stat(t.Dir); os.IsNotExist(err) { + if err := os.MkdirAll(t.Dir, 0755); err != nil { + return err + } + } + return nil +} + func (e *Executor) runDeps(ctx context.Context, t *taskfile.Task) error { g, ctx := errgroup.WithContext(ctx) @@ -224,7 +273,11 @@ func (e *Executor) runDeps(ctx context.Context, t *taskfile.Task) error { d := d g.Go(func() error { - return e.RunTask(ctx, taskfile.Call{Task: d.Task, Vars: d.Vars}) + err := e.RunTask(ctx, taskfile.Call{Task: d.Task, Vars: d.Vars}) + if err != nil { + return err + } + return nil }) } @@ -236,7 +289,11 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi switch { case cmd.Task != "": - return e.RunTask(ctx, taskfile.Call{Task: cmd.Task, Vars: cmd.Vars}) + err := e.RunTask(ctx, taskfile.Call{Task: cmd.Task, Vars: cmd.Vars}) + if err != nil { + return err + } + return nil case cmd.Cmd != "": if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) { e.Logger.Errf(logger.Green, "task: %s", cmd.Cmd) diff --git a/task_test.go b/task_test.go index 0d929420..b4aa4544 100644 --- a/task_test.go +++ b/task_test.go @@ -236,7 +236,7 @@ func TestDeps(t *testing.T) { for _, f := range files { f = filepath.Join(dir, f) if _, err := os.Stat(f); err != nil { - t.Errorf("File %s should exists", f) + t.Errorf("File %s should exist", f) } } } @@ -248,7 +248,7 @@ func TestStatus(t *testing.T) { _ = os.Remove(file) if _, err := os.Stat(file); err == nil { - t.Errorf("File should not exists: %v", err) + t.Errorf("File should not exist: %v", err) } var buff bytes.Buffer @@ -262,7 +262,7 @@ func TestStatus(t *testing.T) { assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "gen-foo"})) if _, err := os.Stat(file); err != nil { - t.Errorf("File should exists: %v", err) + t.Errorf("File should exist: %v", err) } e.Silent = false @@ -273,6 +273,47 @@ func TestStatus(t *testing.T) { } } +func TestPrecondition(t *testing.T) { + const dir = "testdata/precondition" + + var buff bytes.Buffer + e := &task.Executor{ + Dir: dir, + Stdout: &buff, + Stderr: &buff, + } + + // A precondition that has been met + assert.NoError(t, e.Setup()) + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"})) + if buff.String() != "" { + t.Errorf("Got Output when none was expected: %s", buff.String()) + } + + // A precondition that was not met + assert.Error(t, e.Run(context.Background(), taskfile.Call{Task: "impossible"})) + + if buff.String() != "task: 1 != 0 obviously!\n" { + t.Errorf("Wrong output message: %s", buff.String()) + } + buff.Reset() + + // Calling a task with a precondition in a dependency fails the task + assert.Error(t, e.Run(context.Background(), taskfile.Call{Task: "depends_on_impossible"})) + + if buff.String() != "task: 1 != 0 obviously!\n" { + t.Errorf("Wrong output message: %s", buff.String()) + } + buff.Reset() + + // Calling a task with a precondition in a cmd fails the task + assert.Error(t, e.Run(context.Background(), taskfile.Call{Task: "executes_failing_task_as_cmd"})) + if buff.String() != "task: 1 != 0 obviously!\n" { + t.Errorf("Wrong output message: %s", buff.String()) + } + buff.Reset() +} + func TestGenerates(t *testing.T) { const ( srcTask = "sub/src.txt" @@ -290,7 +331,7 @@ func TestGenerates(t *testing.T) { path := filepath.Join(dir, task) _ = os.Remove(path) if _, err := os.Stat(path); err == nil { - t.Errorf("File should not exists: %v", err) + t.Errorf("File should not exist: %v", err) } } @@ -311,10 +352,10 @@ func TestGenerates(t *testing.T) { assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: theTask})) if _, err := os.Stat(srcFile); err != nil { - t.Errorf("File should exists: %v", err) + t.Errorf("File should exist: %v", err) } if _, err := os.Stat(destFile); err != nil { - t.Errorf("File should exists: %v", err) + t.Errorf("File should exist: %v", err) } // Ensure task was not incorrectly found to be up-to-date on first run. if buff.String() == upToDate { @@ -371,7 +412,7 @@ func TestInit(t *testing.T) { _ = os.Remove(file) if _, err := os.Stat(file); err == nil { - t.Errorf("Taskfile.yml should not exists") + t.Errorf("Taskfile.yml should not exist") } if err := task.InitTaskfile(ioutil.Discard, dir); err != nil { @@ -379,7 +420,7 @@ func TestInit(t *testing.T) { } if _, err := os.Stat(file); err != nil { - t.Errorf("Taskfile.yml should exists") + t.Errorf("Taskfile.yml should exist") } } @@ -575,3 +616,65 @@ func readTestFixture(t *testing.T, dir string, file string) string { assert.NoError(t, err, "error reading text fixture") return string(b) } + +func TestWhenNoDirAttributeItRunsInSameDirAsTaskfile(t *testing.T) { + const expected = "dir" + const dir = "testdata/" + expected + var out bytes.Buffer + e := &task.Executor{ + Dir: dir, + Stdout: &out, + Stderr: &out, + } + + assert.NoError(t, e.Setup()) + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "whereami"})) + + // got should be the "dir" part of "testdata/dir" + got := strings.TrimSuffix(filepath.Base(out.String()), "\n") + assert.Equal(t, expected, got, "Mismatch in the working directory") +} + +func TestWhenDirAttributeAndDirExistsItRunsInThatDir(t *testing.T) { + const expected = "exists" + const dir = "testdata/dir/explicit_exists" + var out bytes.Buffer + e := &task.Executor{ + Dir: dir, + Stdout: &out, + Stderr: &out, + } + + assert.NoError(t, e.Setup()) + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "whereami"})) + + got := strings.TrimSuffix(filepath.Base(out.String()), "\n") + assert.Equal(t, expected, got, "Mismatch in the working directory") +} + +func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) { + const expected = "createme" + const dir = "testdata/dir/explicit_doesnt_exist/" + const toBeCreated = dir + expected + const target = "whereami" + var out bytes.Buffer + e := &task.Executor{ + Dir: dir, + Stdout: &out, + Stderr: &out, + } + + // Ensure that the directory to be created doesn't actually exist. + _ = os.Remove(toBeCreated) + if _, err := os.Stat(toBeCreated); err == nil { + t.Errorf("Directory should not exist: %v", err) + } + assert.NoError(t, e.Setup()) + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: target})) + + got := strings.TrimSuffix(filepath.Base(out.String()), "\n") + assert.Equal(t, expected, got, "Mismatch in the working directory") + + // Clean-up after ourselves only if no error. + _ = os.Remove(toBeCreated) +} diff --git a/testdata/dir/Taskfile.yml b/testdata/dir/Taskfile.yml new file mode 100644 index 00000000..f17dd9fe --- /dev/null +++ b/testdata/dir/Taskfile.yml @@ -0,0 +1,7 @@ +version: '2' + +tasks: + whereami: + cmds: + - pwd + silent: true diff --git a/testdata/dir/explicit_doesnt_exist/Taskfile.yml b/testdata/dir/explicit_doesnt_exist/Taskfile.yml new file mode 100644 index 00000000..1b6fb7d1 --- /dev/null +++ b/testdata/dir/explicit_doesnt_exist/Taskfile.yml @@ -0,0 +1,8 @@ +version: '2' + +tasks: + whereami: + dir: createme + cmds: + - pwd + silent: true diff --git a/testdata/dir/explicit_exists/Taskfile.yml b/testdata/dir/explicit_exists/Taskfile.yml new file mode 100644 index 00000000..0ab53b26 --- /dev/null +++ b/testdata/dir/explicit_exists/Taskfile.yml @@ -0,0 +1,8 @@ +version: '2' + +tasks: + whereami: + dir: exists + cmds: + - pwd + silent: true diff --git a/testdata/dir/explicit_exists/exists/.keep b/testdata/dir/explicit_exists/exists/.keep new file mode 100644 index 00000000..e69de29b diff --git a/testdata/precondition/Taskfile.yml b/testdata/precondition/Taskfile.yml new file mode 100644 index 00000000..eedc588f --- /dev/null +++ b/testdata/precondition/Taskfile.yml @@ -0,0 +1,19 @@ +version: '2' + +tasks: + foo: + preconditions: + - test -f foo.txt + + impossible: + preconditions: + - sh: "[ 1 = 0 ]" + msg: "1 != 0 obviously!" + + depends_on_impossible: + deps: + - impossible + + executes_failing_task_as_cmd: + cmds: + - task: impossible diff --git a/testdata/precondition/foo.txt b/testdata/precondition/foo.txt new file mode 100644 index 00000000..e69de29b diff --git a/variables.go b/variables.go index 8e360073..9c227372 100644 --- a/variables.go +++ b/variables.go @@ -84,5 +84,15 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) { } } + if len(origTask.Preconditions) > 0 { + new.Preconditions = make([]*taskfile.Precondition, len(origTask.Preconditions)) + for i, precond := range origTask.Preconditions { + new.Preconditions[i] = &taskfile.Precondition{ + Sh: r.Replace(precond.Sh), + Msg: r.Replace(precond.Msg), + } + } + } + return &new, r.Err() }