Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into upstream-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tonobo committed Feb 8, 2019
2 parents 52de065 + 2cb070f commit 067f035
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

- Allow calling a task of the root Taskfile from an included Taskfile
by prefixing it with `:`
([#161](https://github.com/go-task/task/issues/161), [#172](https://github.com/go-task/task/issues/172)).

## v2.3.0 - 2019-01-02

- On Windows, Task can now be installed using [Scoop](https://scoop.sh/)
Expand Down
4 changes: 4 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ tasks:

The above syntax is also supported in `deps`.

> NOTE: If you want to call a task declared in the root Taskfile from within an
> [included Taskfile](#including-other-taskfiles), add a leading `:` like this:
> `task: :task-name`.

## Prevent unnecessary work

If a task generates something, you can inform Task the source and generated
Expand Down
13 changes: 10 additions & 3 deletions internal/taskfile/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ func (t *Task) ApplyNamespace(taskName string, ns ...string) []*Task {
}
for _, cmd := range t.Cmds {
if cmd.Task != "" {
cmd.Task = strings.Join(append(ns, cmd.Task), NamespaceSeparator)
cmd.Task = taskWithNamespace(ns, cmd.Task)
}
}
for _, dep := range t.Deps {
if dep.Task != "" {
dep.Task = strings.Join(append(ns, dep.Task), NamespaceSeparator)
dep.Task = taskWithNamespace(ns, dep.Task)
}
}
t.Task = strings.Join(append(ns, taskName), NamespaceSeparator)
t.Task = taskWithNamespace(ns, taskName)
return append(tasks, t)
}

func taskWithNamespace(ns []string, taskName string) string {
if strings.HasPrefix(taskName, ":") {
return strings.TrimPrefix(taskName, ":")
}
return strings.Join(append(ns, taskName), NamespaceSeparator)
}
12 changes: 12 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,15 @@ func TestIncludesDependencies(t *testing.T) {
}
tt.Run(t)
}

func TestIncludesCallingRoot(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/includes_call_root_task",
Target: "included:call-root",
TrimSpace: true,
Files: map[string]string{
"root_task.txt": "root task",
},
}
tt.Run(t)
}
1 change: 1 addition & 0 deletions testdata/includes_call_root_task/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.txt
9 changes: 9 additions & 0 deletions testdata/includes_call_root_task/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '2'

includes:
included: Taskfile2.yml

tasks:
root-task:
cmds:
- echo "root task" > root_task.txt
6 changes: 6 additions & 0 deletions testdata/includes_call_root_task/Taskfile2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '2'

tasks:
call-root:
cmds:
- task: :root-task

0 comments on commit 067f035

Please sign in to comment.