hash.go 489 B

123456789101112131415161718192021222324
  1. package hash
  2. import (
  3. "fmt"
  4. "github.com/mitchellh/hashstructure/v2"
  5. "github.com/go-task/task/v3/taskfile/ast"
  6. )
  7. type HashFunc func(*ast.Task) (string, error)
  8. func Empty(*ast.Task) (string, error) {
  9. return "", nil
  10. }
  11. func Name(t *ast.Task) (string, error) {
  12. return fmt.Sprintf("%s:%s", t.Location.Taskfile, t.LocalName()), nil
  13. }
  14. func Hash(t *ast.Task) (string, error) {
  15. h, err := hashstructure.Hash(t, hashstructure.FormatV2, nil)
  16. return fmt.Sprintf("%s:%d", t.Task, h), err
  17. }