1
0
mirror of https://github.com/go-task/task.git synced 2024-12-14 10:52:43 +02:00

Merge pull request #172 from go-task/allow-calling-root-task-from-included

Allow calling a task of the root Taskfile from within an included Taskfile
This commit is contained in:
Andrey Nering 2019-02-02 21:26:22 -02:00 committed by GitHub
commit 2cb070f5b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 0 deletions

View File

@ -1,5 +1,11 @@
# Changelog # 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 ## v2.3.0 - 2019-01-02
- On Windows, Task can now be installed using [Scoop](https://scoop.sh/) - On Windows, Task can now be installed using [Scoop](https://scoop.sh/)

View File

@ -258,6 +258,10 @@ tasks:
The above syntax is also supported in `deps`. 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 ## Prevent unnecessary work
If a task generates something, you can inform Task the source and generated If a task generates something, you can inform Task the source and generated

View File

@ -66,5 +66,8 @@ func Merge(t1, t2 *Taskfile, namespaces ...string) error {
} }
func taskNameWithNamespace(taskName string, namespaces ...string) string { func taskNameWithNamespace(taskName string, namespaces ...string) string {
if strings.HasPrefix(taskName, ":") {
return strings.TrimPrefix(taskName, ":")
}
return strings.Join(append(namespaces, taskName), NamespaceSeparator) return strings.Join(append(namespaces, taskName), NamespaceSeparator)
} }

View File

@ -511,3 +511,15 @@ func TestIncludesDependencies(t *testing.T) {
} }
tt.Run(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)
}

View File

@ -0,0 +1 @@
*.txt

View File

@ -0,0 +1,9 @@
version: '2'
includes:
included: Taskfile2.yml
tasks:
root-task:
cmds:
- echo "root task" > root_task.txt

View File

@ -0,0 +1,6 @@
version: '2'
tasks:
call-root:
cmds:
- task: :root-task