Skip to content
Open
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
22 changes: 22 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2377,6 +2377,28 @@ func TestRunOnceSharedDeps(t *testing.T) {
assert.Contains(t, buff.String(), `task: [service-b:build] echo "build b"`)
}

func TestRunOnceGlobalInIncludedTaskfile(t *testing.T) {
t.Parallel()

const dir = "testdata/run_once_included"

var buff bytes.Buffer
e := task.NewExecutor(
task.WithDir(dir),
task.WithStdout(&buff),
task.WithStderr(&buff),
task.WithForceAll(true),
)
require.NoError(t, e.Setup())
require.NoError(t, e.Run(t.Context(), &task.Call{Task: "build"}))

// The included Taskfile sets `run: once` globally, so its build task should
// execute once even though both service-a and service-b depend on it.
assert.Equal(t, 1, strings.Count(buff.String(), `echo "build library"`))
assert.Contains(t, buff.String(), `task: [service-a] echo "build a"`)
assert.Contains(t, buff.String(), `task: [service-b] echo "build b"`)
}

func TestRunOnceSharedFailurePropagates(t *testing.T) {
t.Parallel()

Expand Down
7 changes: 7 additions & 0 deletions taskfile/ast/taskfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ func (t1 *Taskfile) Merge(t2 *Taskfile, include *Include) error {
}
}
}
if t2.Run != "" {
for _, t := range t2.Tasks.All(nil) {
if t.Run == "" {
t.Run = t2.Run
}
}
}
t1.Vars.Merge(t2.Vars, include)
t1.Env.Merge(t2.Env, include)
return t1.Tasks.Merge(t2.Tasks, include, t1.Vars)
Expand Down
22 changes: 22 additions & 0 deletions testdata/run_once_included/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'

includes:
library: ./library

tasks:
build:
deps:
- service-a
- service-b

service-a:
deps:
- library:build
cmds:
- echo "build a"

service-b:
deps:
- library:build
cmds:
- echo "build b"
8 changes: 8 additions & 0 deletions testdata/run_once_included/library/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

run: once

tasks:
build:
cmds:
- echo "build library"