From dab7cb3c6d4041b22ee8037d3929c065e0cde23c Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Sun, 15 Sep 2024 12:11:05 +0200 Subject: [PATCH] feat: improve fingerprint and output with wildcard --- task.go | 4 ++-- task_test.go | 1 + taskfile/ast/task.go | 6 ++++++ testdata/checksum/Taskfile.yml | 8 ++++++++ testdata/checksum/generated-wildcard.txt | 1 + variables.go | 2 +- 6 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 testdata/checksum/generated-wildcard.txt diff --git a/task.go b/task.go index d0f82a2d3a..5e9d71c9f9 100644 --- a/task.go +++ b/task.go @@ -216,7 +216,6 @@ func (e *Executor) RunTask(ctx context.Context, call *ast.Call) error { if t.Method != "" { method = t.Method } - upToDate, err := fingerprint.IsTaskUpToDate(ctx, t, fingerprint.WithMethod(method), fingerprint.WithTempDir(e.TempDir.Fingerprint), @@ -447,6 +446,7 @@ func (e *Executor) GetTask(call *ast.Call) (*ast.Task, error) { call.Vars = &ast.Vars{} } call.Vars.Set("MATCH", ast.Var{Value: matchingTasks[0].Wildcards}) + matchingTasks[0].Task.FullName = call.Task return matchingTasks[0].Task, nil default: taskNames := make([]string, len(matchingTasks)) @@ -486,7 +486,7 @@ func (e *Executor) GetTask(call *ast.Call) (*ast.Task, error) { DidYouMean: didYouMean, } } - + matchingTask.FullName = matchingTask.Task return matchingTask, nil } diff --git a/task_test.go b/task_test.go index 33c3a3099b..67eb0e64b2 100644 --- a/task_test.go +++ b/task_test.go @@ -474,6 +474,7 @@ func TestStatusChecksum(t *testing.T) { task string }{ {[]string{"generated.txt", ".task/checksum/build"}, "build"}, + {[]string{"generated-wildcard.txt", ".task/checksum/build-wildcard"}, "build-wildcard"}, {[]string{"generated.txt", ".task/checksum/build-with-status"}, "build-with-status"}, } diff --git a/taskfile/ast/task.go b/taskfile/ast/task.go index de6986c6b8..257dc2eb04 100644 --- a/taskfile/ast/task.go +++ b/taskfile/ast/task.go @@ -46,12 +46,17 @@ type Task struct { Namespace string IncludeVars *Vars IncludedTaskfileVars *Vars + + FullName string } func (t *Task) Name() string { if t.Label != "" { return t.Label } + if t.FullName != "" { + return t.FullName + } return t.Task } @@ -220,6 +225,7 @@ func (t *Task) DeepCopy() *Task { Location: t.Location.DeepCopy(), Requires: t.Requires.DeepCopy(), Namespace: t.Namespace, + FullName: t.FullName, } return c } diff --git a/testdata/checksum/Taskfile.yml b/testdata/checksum/Taskfile.yml index 9a34ea51f8..4a669aa566 100644 --- a/testdata/checksum/Taskfile.yml +++ b/testdata/checksum/Taskfile.yml @@ -12,6 +12,14 @@ tasks: generates: - ./generated.txt method: checksum + build-*: + cmds: + - cp ./source.txt ./generated-{{index .MATCH 0}}.txt + sources: + - ./source.txt + generates: + - ./generated-{{index .MATCH 0}}.txt + method: checksum build-with-status: cmds: diff --git a/testdata/checksum/generated-wildcard.txt b/testdata/checksum/generated-wildcard.txt new file mode 100644 index 0000000000..8ab686eafe --- /dev/null +++ b/testdata/checksum/generated-wildcard.txt @@ -0,0 +1 @@ +Hello, World! diff --git a/variables.go b/variables.go index cfdb70ae46..722c3c3267 100644 --- a/variables.go +++ b/variables.go @@ -44,7 +44,6 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task, } cache := &templater.Cache{Vars: vars} - new := ast.Task{ Task: origTask.Task, Label: templater.Replace(origTask.Label, cache), @@ -74,6 +73,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task, Requires: origTask.Requires, Watch: origTask.Watch, Namespace: origTask.Namespace, + FullName: origTask.FullName, } new.Dir, err = execext.Expand(new.Dir) if err != nil {