2020-08-17 21:25:17 +02:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
2024-08-14 15:37:05 +02:00
|
|
|
"cmp"
|
2020-08-17 21:25:17 +02:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-task/task/v3/internal/hash"
|
2023-12-29 22:32:03 +02:00
|
|
|
"github.com/go-task/task/v3/taskfile/ast"
|
2020-08-17 21:25:17 +02:00
|
|
|
)
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func (e *Executor) GetHash(t *ast.Task) (string, error) {
|
2024-08-14 15:37:05 +02:00
|
|
|
r := cmp.Or(t.Run, e.Taskfile.Run)
|
2020-08-17 21:25:17 +02:00
|
|
|
var h hash.HashFunc
|
|
|
|
switch r {
|
|
|
|
case "always":
|
|
|
|
h = hash.Empty
|
|
|
|
case "once":
|
|
|
|
h = hash.Name
|
|
|
|
case "when_changed":
|
|
|
|
h = hash.Hash
|
|
|
|
default:
|
|
|
|
return "", fmt.Errorf(`task: invalid run "%s"`, r)
|
|
|
|
}
|
|
|
|
return h(t)
|
|
|
|
}
|