Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions internal/fingerprint/fingerprint_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package fingerprint

import (
"encoding/json"
"fmt"

"github.com/zeebo/xxh3"

"github.com/go-task/task/v3/taskfile/ast"
)

type fingerprintIdentity struct {
Task string `json:"task"`
Dir string `json:"dir"`
Sources []string `json:"sources,omitempty"`
Generates []string `json:"generates,omitempty"`
}

func taskFingerprintKey(t *ast.Task) string {
name := taskIdentityName(t)
identity := fingerprintIdentity{
Task: name,
Dir: t.Dir,
Sources: globPatterns(t.Sources),
Generates: globPatterns(t.Generates),
}

encoded, err := json.Marshal(identity)
if err != nil {
return normalizeFilename(name)
}

return normalizeFilename(fmt.Sprintf("%s-%x", name, xxh3.Hash(encoded)))
}

func taskIdentityName(t *ast.Task) string {
if t.FullName != "" {
return t.FullName
}
return t.Task
}

func globPatterns(globs []*ast.Glob) []string {
if len(globs) == 0 {
return nil
}

patterns := make([]string, 0, len(globs))
for _, glob := range globs {
if glob == nil {
continue
}
if glob.Negate {
patterns = append(patterns, "!"+glob.Glob)
continue
}
patterns = append(patterns, glob.Glob)
}
return patterns
}
2 changes: 1 addition & 1 deletion internal/fingerprint/sources_checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *ChecksumChecker) checksum(t *ast.Task) (string, error) {
}

func (checker *ChecksumChecker) checksumFilePath(t *ast.Task) string {
return filepath.Join(checker.tempDir, "checksum", normalizeFilename(t.Name()))
return filepath.Join(checker.tempDir, "checksum", taskFingerprintKey(t))
}

var checksumFilenameRegexp = regexp.MustCompile("[^A-z0-9]")
Expand Down
2 changes: 1 addition & 1 deletion internal/fingerprint/sources_timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ func (*TimestampChecker) OnError(t *ast.Task) error {
}

func (checker *TimestampChecker) timestampFilePath(t *ast.Task) string {
return filepath.Join(checker.tempDir, "timestamp", normalizeFilename(t.Task))
return filepath.Join(checker.tempDir, "timestamp", taskFingerprintKey(t))
}