1
0
mirror of https://github.com/go-task/task.git synced 2025-07-17 01:43:07 +02:00

feat: improve fingerprint and output with wildcard

This commit is contained in:
Valentin Maerten
2024-09-15 12:11:05 +02:00
parent 5aa68e47e5
commit dab7cb3c6d
6 changed files with 19 additions and 3 deletions

View File

@ -216,7 +216,6 @@ func (e *Executor) RunTask(ctx context.Context, call *ast.Call) error {
if t.Method != "" { if t.Method != "" {
method = t.Method method = t.Method
} }
upToDate, err := fingerprint.IsTaskUpToDate(ctx, t, upToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
fingerprint.WithMethod(method), fingerprint.WithMethod(method),
fingerprint.WithTempDir(e.TempDir.Fingerprint), 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 = &ast.Vars{}
} }
call.Vars.Set("MATCH", ast.Var{Value: matchingTasks[0].Wildcards}) call.Vars.Set("MATCH", ast.Var{Value: matchingTasks[0].Wildcards})
matchingTasks[0].Task.FullName = call.Task
return matchingTasks[0].Task, nil return matchingTasks[0].Task, nil
default: default:
taskNames := make([]string, len(matchingTasks)) taskNames := make([]string, len(matchingTasks))
@ -486,7 +486,7 @@ func (e *Executor) GetTask(call *ast.Call) (*ast.Task, error) {
DidYouMean: didYouMean, DidYouMean: didYouMean,
} }
} }
matchingTask.FullName = matchingTask.Task
return matchingTask, nil return matchingTask, nil
} }

View File

@ -474,6 +474,7 @@ func TestStatusChecksum(t *testing.T) {
task string task string
}{ }{
{[]string{"generated.txt", ".task/checksum/build"}, "build"}, {[]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"}, {[]string{"generated.txt", ".task/checksum/build-with-status"}, "build-with-status"},
} }

View File

@ -46,12 +46,17 @@ type Task struct {
Namespace string Namespace string
IncludeVars *Vars IncludeVars *Vars
IncludedTaskfileVars *Vars IncludedTaskfileVars *Vars
FullName string
} }
func (t *Task) Name() string { func (t *Task) Name() string {
if t.Label != "" { if t.Label != "" {
return t.Label return t.Label
} }
if t.FullName != "" {
return t.FullName
}
return t.Task return t.Task
} }
@ -220,6 +225,7 @@ func (t *Task) DeepCopy() *Task {
Location: t.Location.DeepCopy(), Location: t.Location.DeepCopy(),
Requires: t.Requires.DeepCopy(), Requires: t.Requires.DeepCopy(),
Namespace: t.Namespace, Namespace: t.Namespace,
FullName: t.FullName,
} }
return c return c
} }

View File

@ -12,6 +12,14 @@ tasks:
generates: generates:
- ./generated.txt - ./generated.txt
method: checksum 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: build-with-status:
cmds: cmds:

View File

@ -0,0 +1 @@
Hello, World!

View File

@ -44,7 +44,6 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
} }
cache := &templater.Cache{Vars: vars} cache := &templater.Cache{Vars: vars}
new := ast.Task{ new := ast.Task{
Task: origTask.Task, Task: origTask.Task,
Label: templater.Replace(origTask.Label, cache), Label: templater.Replace(origTask.Label, cache),
@ -74,6 +73,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
Requires: origTask.Requires, Requires: origTask.Requires,
Watch: origTask.Watch, Watch: origTask.Watch,
Namespace: origTask.Namespace, Namespace: origTask.Namespace,
FullName: origTask.FullName,
} }
new.Dir, err = execext.Expand(new.Dir) new.Dir, err = execext.Expand(new.Dir)
if err != nil { if err != nil {