Skip to content

Commit 48039be

Browse files
authored
feat: improve fingerprint, run and output with wildcard (#1808)
1 parent 43cb64e commit 48039be

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

task.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
172172
if t.Method != "" {
173173
method = t.Method
174174
}
175-
176175
upToDate, err := fingerprint.IsTaskUpToDate(ctx, t,
177176
fingerprint.WithMethod(method),
178177
fingerprint.WithTempDir(e.TempDir.Fingerprint),
@@ -467,7 +466,6 @@ func (e *Executor) GetTask(call *Call) (*ast.Task, error) {
467466
DidYouMean: didYouMean,
468467
}
469468
}
470-
471469
return matchingTask, nil
472470
}
473471

task_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ func TestStatusChecksum(t *testing.T) { // nolint:paralleltest // cannot run in
437437
task string
438438
}{
439439
{[]string{"generated.txt", ".task/checksum/build"}, "build"},
440+
{[]string{"generated-wildcard.txt", ".task/checksum/build-wildcard"}, "build-wildcard"},
440441
{[]string{"generated.txt", ".task/checksum/build-with-status"}, "build-with-status"},
441442
}
442443

@@ -1810,6 +1811,22 @@ func TestRunOnlyRunsJobsHashOnce(t *testing.T) {
18101811
})
18111812
}
18121813

1814+
func TestRunOnlyRunsJobsHashOnceWithWildcard(t *testing.T) {
1815+
t.Parallel()
1816+
1817+
tt := fileContentTest{
1818+
Dir: "testdata/run",
1819+
Target: "deploy",
1820+
Files: map[string]string{
1821+
"wildcard.txt": "Deploy infra\nDeploy js\nDeploy go\n",
1822+
},
1823+
}
1824+
t.Run("", func(t *testing.T) {
1825+
t.Parallel()
1826+
tt.Run(t)
1827+
})
1828+
}
1829+
18131830
func TestRunOnceSharedDeps(t *testing.T) {
18141831
t.Parallel()
18151832

taskfile/ast/task.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,22 @@ type Task struct {
4646
Namespace string
4747
IncludeVars *Vars
4848
IncludedTaskfileVars *Vars
49+
50+
FullName string
4951
}
5052

5153
func (t *Task) Name() string {
5254
if t.Label != "" {
5355
return t.Label
5456
}
57+
if t.FullName != "" {
58+
return t.FullName
59+
}
5560
return t.Task
5661
}
5762

5863
func (t *Task) LocalName() string {
59-
name := t.Task
64+
name := t.FullName
6065
name = strings.TrimPrefix(name, t.Namespace)
6166
name = strings.TrimPrefix(name, ":")
6267
return name
@@ -220,6 +225,7 @@ func (t *Task) DeepCopy() *Task {
220225
Location: t.Location.DeepCopy(),
221226
Requires: t.Requires.DeepCopy(),
222227
Namespace: t.Namespace,
228+
FullName: t.FullName,
223229
}
224230
return c
225231
}

testdata/checksum/Taskfile.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ tasks:
1212
generates:
1313
- ./generated.txt
1414
method: checksum
15+
build-*:
16+
cmds:
17+
- cp ./source.txt ./generated-{{index .MATCH 0}}.txt
18+
sources:
19+
- ./source.txt
20+
generates:
21+
- ./generated-{{index .MATCH 0}}.txt
22+
method: checksum
1523

1624
build-with-status:
1725
cmds:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, World!

testdata/run/Taskfile.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ tasks:
2222
run: once
2323
cmds:
2424
- echo starting {{.CONTENT}} >> hash.txt
25+
26+
deploy:
27+
cmds:
28+
- rm -rf wildcard.txt
29+
- task: deploy:infra
30+
- task: deploy:js
31+
- task: deploy:go
32+
33+
deploy:*:
34+
run: once
35+
cmd: echo "Deploy {{index .MATCH 0}}" >> wildcard.txt

variables.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
4444
if err != nil {
4545
return nil, err
4646
}
47+
fullName := origTask.Task
48+
if matches, exists := vars.Get("MATCH"); exists {
49+
for _, match := range matches.Value.([]string) {
50+
fullName = strings.Replace(fullName, "*", match, 1)
51+
}
52+
}
4753

4854
cache := &templater.Cache{Vars: vars}
49-
5055
new := ast.Task{
5156
Task: origTask.Task,
5257
Label: templater.Replace(origTask.Label, cache),
@@ -76,6 +81,7 @@ func (e *Executor) compiledTask(call *Call, evaluateShVars bool) (*ast.Task, err
7681
Requires: origTask.Requires,
7782
Watch: origTask.Watch,
7883
Namespace: origTask.Namespace,
84+
FullName: fullName,
7985
}
8086
new.Dir, err = execext.ExpandLiteral(new.Dir)
8187
if err != nil {

0 commit comments

Comments
 (0)