Skip to content

Commit

Permalink
Merge pull request #172 from go-task/allow-calling-root-task-from-inc…
Browse files Browse the repository at this point in the history
…luded

Allow calling a task of the root Taskfile from within an included Taskfile
  • Loading branch information
andreynering authored Feb 2, 2019
2 parents 310394a + 1dec956 commit 2cb070f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 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 @@ -258,6 +258,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
3 changes: 3 additions & 0 deletions internal/taskfile/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ func Merge(t1, t2 *Taskfile, namespaces ...string) error {
}

func taskNameWithNamespace(taskName string, namespaces ...string) string {
if strings.HasPrefix(taskName, ":") {
return strings.TrimPrefix(taskName, ":")
}
return strings.Join(append(namespaces, 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 2cb070f

Please sign in to comment.