Skip to content

include generated files in the checksum method #2313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 7 additions & 2 deletions internal/fingerprint/sources_checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// ChecksumChecker validates if a task is up to date by calculating its source
// files checksum
// and destination (generates) files checksum
type ChecksumChecker struct {
tempDir string
dry bool
Expand Down Expand Up @@ -92,10 +92,15 @@ func (c *ChecksumChecker) checksum(t *ast.Task) (string, error) {
if err != nil {
return "", err
}
generates, err := Globs(t.Dir, t.Generates)
if err != nil {
return "", err
}
files := append(sources, generates...)

h := xxh3.New()
buf := make([]byte, 128*1024)
for _, f := range sources {
for _, f := range files {
// also sum the filename, so checksum changes for renaming a file
if _, err := io.CopyBuffer(h, strings.NewReader(filepath.Base(f)), buf); err != nil {
return "", err
Expand Down
46 changes: 46 additions & 0 deletions internal/fingerprint/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,49 @@ func IsTaskUpToDate(
// i.e. it is never considered "up-to-date"
return false, nil
}

func FinalizeTask(
ctx context.Context,
t *ast.Task,
opts ...CheckerOption,
) error {
var err error

// Default config
config := &CheckerConfig{
method: "none",
tempDir: "",
dry: false,
logger: nil,
statusChecker: nil,
sourcesChecker: nil,
}

// Apply functional options
for _, opt := range opts {
opt(config)
}

// If no status checker was given, set up the default one
if config.statusChecker == nil {
config.statusChecker = NewStatusChecker(config.logger)
}

// If no sources checker was given, set up the default one
if config.sourcesChecker == nil {
config.sourcesChecker, err = NewSourcesChecker(config.method, config.tempDir, config.dry)
if err != nil {
return err
}
}

// If sources and generates are set, regenerate the checksum / timestamp file
if len(t.Sources) != 0 && len(t.Generates) != 0 {
_, err = config.sourcesChecker.IsUpToDate(t)
if err != nil {
return err
}
}

return nil
}
20 changes: 20 additions & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,26 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
return &errors.TaskRunError{TaskName: t.Task, Err: err}
}
}

if !skipFingerprinting {
// Get the fingerprinting method to use
method := e.Taskfile.Method
if t.Method != "" {
method = t.Method
}

// Finalize the task fingerprinting
err := fingerprint.FinalizeTask(ctx, t,
fingerprint.WithMethod(method),
fingerprint.WithTempDir(e.TempDir.Fingerprint),
fingerprint.WithDry(e.Dry),
fingerprint.WithLogger(e.Logger),
)
if err != nil {
return err
}
}

e.Logger.VerboseErrf(logger.Magenta, "task: %q finished\n", call.Task)
return nil
})
Expand Down
Loading