mirror of
https://github.com/go-task/task.git
synced 2025-10-08 23:02:02 +02:00
feat: improve fingerprint, run and output with wildcard (#1808)
This commit is contained in:
2
task.go
2
task.go
@@ -172,7 +172,6 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
|
||||
if t.Method != "" {
|
||||
method = t.Method
|
||||
}
|
||||
|
||||
upToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
|
||||
fingerprint.WithMethod(method),
|
||||
fingerprint.WithTempDir(e.TempDir.Fingerprint),
|
||||
@@ -467,7 +466,6 @@ func (e *Executor) GetTask(call *Call) (*ast.Task, error) {
|
||||
DidYouMean: didYouMean,
|
||||
}
|
||||
}
|
||||
|
||||
return matchingTask, nil
|
||||
}
|
||||
|
||||
|
17
task_test.go
17
task_test.go
@@ -437,6 +437,7 @@ func TestStatusChecksum(t *testing.T) { // nolint:paralleltest // cannot run in
|
||||
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"},
|
||||
}
|
||||
|
||||
@@ -1810,6 +1811,22 @@ func TestRunOnlyRunsJobsHashOnce(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunOnlyRunsJobsHashOnceWithWildcard(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tt := fileContentTest{
|
||||
Dir: "testdata/run",
|
||||
Target: "deploy",
|
||||
Files: map[string]string{
|
||||
"wildcard.txt": "Deploy infra\nDeploy js\nDeploy go\n",
|
||||
},
|
||||
}
|
||||
t.Run("", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tt.Run(t)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunOnceSharedDeps(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@@ -46,17 +46,22 @@ 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
|
||||
}
|
||||
|
||||
func (t *Task) LocalName() string {
|
||||
name := t.Task
|
||||
name := t.FullName
|
||||
name = strings.TrimPrefix(name, t.Namespace)
|
||||
name = strings.TrimPrefix(name, ":")
|
||||
return name
|
||||
@@ -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
testdata/checksum/Taskfile.yml
vendored
8
testdata/checksum/Taskfile.yml
vendored
@@ -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:
|
||||
|
1
testdata/checksum/generated-wildcard.txt
vendored
Normal file
1
testdata/checksum/generated-wildcard.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Hello, World!
|
11
testdata/run/Taskfile.yml
vendored
11
testdata/run/Taskfile.yml
vendored
@@ -22,3 +22,14 @@ tasks:
|
||||
run: once
|
||||
cmds:
|
||||
- echo starting {{.CONTENT}} >> hash.txt
|
||||
|
||||
deploy:
|
||||
cmds:
|
||||
- rm -rf wildcard.txt
|
||||
- task: deploy:infra
|
||||
- task: deploy:js
|
||||
- task: deploy:go
|
||||
|
||||
deploy:*:
|
||||
run: once
|
||||
cmd: echo "Deploy {{index .MATCH 0}}" >> wildcard.txt
|
||||
|
@@ -44,9 +44,14 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fullName := origTask.Task
|
||||
if matches, exists := vars.Get("MATCH"); exists {
|
||||
for _, match := range matches.Value.([]string) {
|
||||
fullName = strings.Replace(fullName, "*", match, 1)
|
||||
}
|
||||
}
|
||||
|
||||
cache := &templater.Cache{Vars: vars}
|
||||
|
||||
new := ast.Task{
|
||||
Task: origTask.Task,
|
||||
Label: templater.Replace(origTask.Label, cache),
|
||||
@@ -76,6 +81,7 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
|
||||
Requires: origTask.Requires,
|
||||
Watch: origTask.Watch,
|
||||
Namespace: origTask.Namespace,
|
||||
FullName: fullName,
|
||||
}
|
||||
new.Dir, err = execext.ExpandLiteral(new.Dir)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user