Skip to content
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

feat: improve fingerprint and output with wildcard #1808

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we'd be getting a race condition here, no? Parallel calls to this task would be overiding the same attribute.

Tricky to implement this in another way, though, I know...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are totally right. The same task with a wildcard, used twice in a dep (ran in parallel) the first one will be overridden by the last

Put this in draft until I find a solution for it

Thanks!

return matchingTasks[0].Task, nil
default:
taskNames := make([]string, len(matchingTasks))
Expand Down Expand Up @@ -486,7 +486,7 @@ func (e *Executor) GetTask(call *ast.Call) (*ast.Task, error) {
DidYouMean: didYouMean,
}
}

matchingTask.FullName = matchingTask.Task
return matchingTask, nil
}

Expand Down
1 change: 1 addition & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}

Expand Down
6 changes: 6 additions & 0 deletions taskfile/ast/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions testdata/checksum/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions testdata/checksum/generated-wildcard.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, World!
2 changes: 1 addition & 1 deletion variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down
Loading