@@ -11,6 +11,7 @@ import (
1111 "regexp"
1212 "strings"
1313 "sync"
14+ "time"
1415
1516 output "github.com/notnmeyer/tsk/internal/outputformat"
1617
@@ -48,6 +49,7 @@ type Executor struct {
4849 Stderr io.Writer
4950 Config * Config
5051 Prefix bool
52+ Time bool
5153 colorIndex int
5254 taskColors map [string ]string
5355}
@@ -131,6 +133,8 @@ func (exec *Executor) RunTasks(config *Config, tasks *[]string) error {
131133 taskConfig .Dir = config .TaskFileDir
132134 }
133135
136+ taskStart := time .Now ()
137+
134138 if len (taskConfig .Deps ) > 0 {
135139 for _ , depGroup := range taskConfig .Deps {
136140 var wg sync.WaitGroup
@@ -162,6 +166,7 @@ func (exec *Executor) RunTasks(config *Config, tasks *[]string) error {
162166 Stdin : exec .Stdin ,
163167 Config : exec .Config ,
164168 Prefix : exec .Prefix ,
169+ Time : exec .Time ,
165170 }
166171
167172 // if a task contains cmds, run them
@@ -184,6 +189,10 @@ func (exec *Executor) RunTasks(config *Config, tasks *[]string) error {
184189 os .Exit (1 )
185190 }
186191 }
192+
193+ if exec .Time && exec .Stderr != nil {
194+ fmt .Fprintf (exec .Stderr , "::%s:: duration %s\n " , task , formatDuration (time .Since (taskStart )))
195+ }
187196 }
188197 return nil
189198}
@@ -314,6 +323,18 @@ func (exec *Executor) VerifyTasks(tasks []string) error {
314323 return nil
315324}
316325
326+ func formatDuration (d time.Duration ) string {
327+ if d < time .Second {
328+ return fmt .Sprintf ("%dms" , d .Milliseconds ())
329+ }
330+ if d < time .Minute {
331+ return fmt .Sprintf ("%.2fs" , d .Seconds ())
332+ }
333+ m := int (d .Minutes ())
334+ s := d .Seconds () - float64 (m * 60 )
335+ return fmt .Sprintf ("%dm%.2fs" , m , s )
336+ }
337+
317338func filterTasks (tasks * map [string ]Task , regex * regexp.Regexp ) map [string ]Task {
318339 filtered := make (map [string ]Task )
319340 for k , v := range * tasks {
0 commit comments