Skip to content

Commit

Permalink
Merge pull request go-task#815 from pd93/default-included-task
Browse files Browse the repository at this point in the history
feat: run default task in included file when task is omitted
  • Loading branch information
andreynering authored Nov 2, 2022
2 parents 9bbdac3 + 5a08409 commit 13f4b37
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 0 deletions.
24 changes: 24 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,30 @@ func TestInternalTask(t *testing.T) {
}
}

func TestIncludesShadowedDefault(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/includes_shadowed_default",
Target: "included",
TrimSpace: true,
Files: map[string]string{
"file.txt": "shadowed",
},
}
tt.Run(t)
}

func TestIncludesUnshadowedDefault(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/includes_unshadowed_default",
Target: "included",
TrimSpace: true,
Files: map[string]string{
"file.txt": "included",
},
}
tt.Run(t)
}

func TestSupportedFileNames(t *testing.T) {
fileNames := []string{
"Taskfile.yml",
Expand Down
7 changes: 7 additions & 0 deletions taskfile/read/taskfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, error) {
if err = taskfile.Merge(t, includedTaskfile, &includedTask, namespace); err != nil {
return err
}

if includedTaskfile.Tasks["default"] != nil && t.Tasks[namespace] == nil {
defaultTaskName := fmt.Sprintf("%s:default", namespace)
t.Tasks[defaultTaskName].Aliases = append(t.Tasks[defaultTaskName].Aliases, namespace)
t.Tasks[defaultTaskName].Aliases = append(t.Tasks[defaultTaskName].Aliases, includedTask.Aliases...)
}

return nil
})
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions testdata/includes_shadowed_default/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

includes:
included:
taskfile: Taskfile2.yml

tasks:
included:
cmds:
- echo "shadowed" > file.txt
6 changes: 6 additions & 0 deletions testdata/includes_shadowed_default/Taskfile2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'

tasks:
default:
cmds:
- echo "included" > file.txt
1 change: 1 addition & 0 deletions testdata/includes_shadowed_default/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shadowed
5 changes: 5 additions & 0 deletions testdata/includes_unshadowed_default/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'

includes:
included:
taskfile: Taskfile2.yml
6 changes: 6 additions & 0 deletions testdata/includes_unshadowed_default/Taskfile2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'

tasks:
default:
cmds:
- echo "included" > file.txt
1 change: 1 addition & 0 deletions testdata/includes_unshadowed_default/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
included

0 comments on commit 13f4b37

Please sign in to comment.