2017-02-27 21:44:08 +02:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
2017-07-16 21:15:29 +02:00
|
|
|
"context"
|
2017-09-16 16:44:13 +02:00
|
|
|
"fmt"
|
2017-02-27 21:44:08 +02:00
|
|
|
|
2023-03-10 20:27:30 +02:00
|
|
|
"github.com/go-task/task/v3/internal/fingerprint"
|
2023-12-29 22:32:03 +02:00
|
|
|
"github.com/go-task/task/v3/taskfile/ast"
|
2017-02-27 21:44:08 +02:00
|
|
|
)
|
|
|
|
|
2017-12-27 01:43:52 +02:00
|
|
|
// Status returns an error if any the of given tasks is not up-to-date
|
2024-01-26 16:34:18 +02:00
|
|
|
func (e *Executor) Status(ctx context.Context, calls ...*ast.Call) error {
|
2017-12-27 01:43:52 +02:00
|
|
|
for _, call := range calls {
|
2023-03-10 20:27:30 +02:00
|
|
|
|
|
|
|
// Compile the task
|
2018-10-06 22:55:23 +02:00
|
|
|
t, err := e.CompiledTask(call)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-12-27 01:43:52 +02:00
|
|
|
}
|
2023-03-10 20:27:30 +02:00
|
|
|
|
|
|
|
// Get the fingerprinting method to use
|
|
|
|
method := e.Taskfile.Method
|
|
|
|
if t.Method != "" {
|
|
|
|
method = t.Method
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the task is up-to-date
|
|
|
|
isUpToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
|
|
|
|
fingerprint.WithMethod(method),
|
2024-06-28 18:01:11 +02:00
|
|
|
fingerprint.WithTempDir(e.TempDir.Fingerprint),
|
2023-03-10 20:27:30 +02:00
|
|
|
fingerprint.WithDry(e.Dry),
|
|
|
|
fingerprint.WithLogger(e.Logger),
|
|
|
|
)
|
2017-12-27 01:43:52 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !isUpToDate {
|
2020-06-03 22:19:12 +02:00
|
|
|
return fmt.Errorf(`task: Task "%s" is not up-to-date`, t.Name())
|
2017-12-27 01:43:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func (e *Executor) statusOnError(t *ast.Task) error {
|
2019-09-09 03:26:24 +02:00
|
|
|
method := t.Method
|
|
|
|
if method == "" {
|
|
|
|
method = e.Taskfile.Method
|
|
|
|
}
|
2024-06-28 18:01:11 +02:00
|
|
|
checker, err := fingerprint.NewSourcesChecker(method, e.TempDir.Fingerprint, e.Dry)
|
2023-03-10 20:27:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-07-16 21:15:29 +02:00
|
|
|
}
|
2023-03-10 20:27:30 +02:00
|
|
|
return checker.OnError(t)
|
2017-07-16 21:15:29 +02:00
|
|
|
}
|