status.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package task
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/go-task/task/v3/internal/fingerprint"
  6. "github.com/go-task/task/v3/taskfile/ast"
  7. )
  8. // Status returns an error if any the of given tasks is not up-to-date
  9. func (e *Executor) Status(ctx context.Context, calls ...*ast.Call) error {
  10. for _, call := range calls {
  11. // Compile the task
  12. t, err := e.CompiledTask(call)
  13. if err != nil {
  14. return err
  15. }
  16. // Get the fingerprinting method to use
  17. method := e.Taskfile.Method
  18. if t.Method != "" {
  19. method = t.Method
  20. }
  21. // Check if the task is up-to-date
  22. isUpToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
  23. fingerprint.WithMethod(method),
  24. fingerprint.WithTempDir(e.TempDir.Fingerprint),
  25. fingerprint.WithDry(e.Dry),
  26. fingerprint.WithLogger(e.Logger),
  27. )
  28. if err != nil {
  29. return err
  30. }
  31. if !isUpToDate {
  32. return fmt.Errorf(`task: Task "%s" is not up-to-date`, t.Name())
  33. }
  34. }
  35. return nil
  36. }
  37. func (e *Executor) statusOnError(t *ast.Task) error {
  38. method := t.Method
  39. if method == "" {
  40. method = e.Taskfile.Method
  41. }
  42. checker, err := fingerprint.NewSourcesChecker(method, e.TempDir.Fingerprint, e.Dry)
  43. if err != nil {
  44. return err
  45. }
  46. return checker.OnError(t)
  47. }