Skip to content

Commit

Permalink
Merge branch 'master' of github.com:go-task/task into upstream-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tonobo committed Feb 11, 2019
2 parents 067f035 + 21e66c7 commit b5c3565
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 51 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

- Allow calling a task of the root Taskfile from an included Taskfile
by prefixing it with `:`
([#161](https://github.com/go-task/task/issues/161), [#172](https://github.com/go-task/task/issues/172)).
([#161](https://github.com/go-task/task/issues/161), [#172](https://github.com/go-task/task/issues/172)),
- Add flag to override the `output` option
([#173](https://github.com/go-task/task/pull/173));
- Fix bug where Task was persisting the new checksum on the disk when the Dry
Mode is enabled
([#166](https://github.com/go-task/task/issues/166)).

## v2.3.0 - 2019-01-02

Expand Down
20 changes: 11 additions & 9 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func main() {
dry bool
update bool
dir string
output string
)

pflag.BoolVar(&versionFlag, "version", false, "show Task version")
Expand All @@ -128,6 +129,7 @@ func main() {
pflag.BoolVarP(&silent, "silent", "s", false, "disables echoing")
pflag.BoolVar(&dry, "dry", false, "compiles and prints tasks in the order that they would be run, without executing them")
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
pflag.StringVarP(&output, "output", "o", "", "sets output style: [interleaved|group|prefixed]")
pflag.Parse()

if versionFlag {
Expand All @@ -153,11 +155,6 @@ func main() {
return
}

ctx := context.Background()
if !watch {
ctx = getSignalContext()
}

e := task.Executor{
Force: force,
Watch: watch,
Expand All @@ -167,11 +164,11 @@ func main() {
Dry: dry,
TaskfileLocation: taskfileLocation,

Context: ctx,

Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,

OutputStyle: output,
}
if err := e.Setup(); err != nil {
log.Fatal(err)
Expand All @@ -198,14 +195,19 @@ func main() {
log.Fatal(err)
}

ctx := context.Background()
if !watch {
ctx = getSignalContext()
}

if status {
if err = e.Status(calls...); err != nil {
if err = e.Status(ctx, calls...); err != nil {
log.Fatal(err)
}
return
}

if err := e.Run(calls...); err != nil {
if err := e.Run(ctx, calls...); err != nil {
log.Fatal(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
name: 'Task',
repo: 'go-task/task',
ga: 'UA-126286662-1',
themeColor: '#83d0f2',
themeColor: '#00add8',
loadSidebar: true,
auto2top: true,
maxLevel: 3,
Expand Down
2 changes: 2 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ $ task default
[print-baz] baz
```

> The `output` option can also be specified by the `--output` or `-o` flags.

## Watch tasks

If you give a `--watch` or `-w` argument, task will watch for file changes
Expand Down
9 changes: 6 additions & 3 deletions internal/status/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Checksum struct {
Dir string
Task string
Sources []string
Dry bool
}

// IsUpToDate implements the Checker interface
Expand All @@ -36,9 +37,11 @@ func (c *Checksum) IsUpToDate() (bool, error) {
return false, nil
}

_ = os.MkdirAll(filepath.Join(c.Dir, ".task", "checksum"), 0755)
if err = ioutil.WriteFile(checksumFile, []byte(newMd5+"\n"), 0644); err != nil {
return false, err
if !c.Dry {
_ = os.MkdirAll(filepath.Join(c.Dir, ".task", "checksum"), 0755)
if err = ioutil.WriteFile(checksumFile, []byte(newMd5+"\n"), 0644); err != nil {
return false, err
}
}
return oldMd5 == newMd5, nil
}
Expand Down
19 changes: 10 additions & 9 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
)

// Status returns an error if any the of given tasks is not up-to-date
func (e *Executor) Status(calls ...taskfile.Call) error {
func (e *Executor) Status(ctx context.Context, calls ...taskfile.Call) error {
for _, call := range calls {
t, err := e.CompiledTask(call)
if err != nil {
return err
}
isUpToDate, err := isTaskUpToDate(e.Context, t)
isUpToDate, err := e.isTaskUpToDate(ctx, t)
if err != nil {
return err
}
Expand All @@ -27,28 +27,28 @@ func (e *Executor) Status(calls ...taskfile.Call) error {
return nil
}

func isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) {
func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) {
if len(t.Status) > 0 {
return isTaskUpToDateStatus(ctx, t)
return e.isTaskUpToDateStatus(ctx, t)
}

checker, err := getStatusChecker(t)
checker, err := e.getStatusChecker(t)
if err != nil {
return false, err
}

return checker.IsUpToDate()
}

func statusOnError(t *taskfile.Task) error {
checker, err := getStatusChecker(t)
func (e *Executor) statusOnError(t *taskfile.Task) error {
checker, err := e.getStatusChecker(t)
if err != nil {
return err
}
return checker.OnError()
}

func getStatusChecker(t *taskfile.Task) (status.Checker, error) {
func (e *Executor) getStatusChecker(t *taskfile.Task) (status.Checker, error) {
switch t.Method {
case "", "timestamp":
return &status.Timestamp{
Expand All @@ -61,6 +61,7 @@ func getStatusChecker(t *taskfile.Task) (status.Checker, error) {
Dir: t.Dir,
Task: t.Task,
Sources: t.Sources,
Dry: e.Dry,
}, nil
case "none":
return status.None{}, nil
Expand All @@ -69,7 +70,7 @@ func getStatusChecker(t *taskfile.Task) (status.Checker, error) {
}
}

func isTaskUpToDateStatus(ctx context.Context, t *taskfile.Task) (bool, error) {
func (e *Executor) isTaskUpToDateStatus(ctx context.Context, t *taskfile.Task) (bool, error) {
for _, s := range t.Status {
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: s,
Expand Down
23 changes: 11 additions & 12 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,22 @@ type Executor struct {
Dry bool
TaskfileLocation string

Context context.Context

Stdin io.Reader
Stdout io.Writer
Stderr io.Writer

Logger *logger.Logger
Compiler compiler.Compiler
Output output.Output
Logger *logger.Logger
Compiler compiler.Compiler
Output output.Output
OutputStyle string

taskvars taskfile.Vars

taskCallCount map[string]*int32
}

// Run runs Task
func (e *Executor) Run(calls ...taskfile.Call) error {
func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
// check if given tasks exist
for _, c := range calls {
if _, ok := e.Taskfile.Tasks[c.Task]; !ok {
Expand All @@ -69,7 +68,7 @@ func (e *Executor) Run(calls ...taskfile.Call) error {
}

for _, c := range calls {
if err := e.RunTask(e.Context, c); err != nil {
if err := e.RunTask(ctx, c); err != nil {
return err
}
}
Expand All @@ -93,9 +92,6 @@ func (e *Executor) Setup() error {
return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err)
}

if e.Context == nil {
e.Context = context.Background()
}
if e.Stdin == nil {
e.Stdin = os.Stdin
}
Expand Down Expand Up @@ -135,6 +131,9 @@ func (e *Executor) Setup() error {
if !version.IsV22(v) && 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
}
switch e.Taskfile.Output {
case "", "interleaved":
e.Output = output.Interleaved{}
Expand Down Expand Up @@ -183,7 +182,7 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
}

if !e.Force {
upToDate, err := isTaskUpToDate(ctx, t)
upToDate, err := e.isTaskUpToDate(ctx, t)
if err != nil {
return err
}
Expand All @@ -197,7 +196,7 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {

for i := range t.Cmds {
if err := e.runCommand(ctx, t, call, i); err != nil {
if err2 := statusOnError(t); err2 != nil {
if err2 := e.statusOnError(t); err2 != nil {
e.Logger.VerboseErrf("task: error cleaning status on error: %v", err2)
}

Expand Down
Loading

0 comments on commit b5c3565

Please sign in to comment.