Skip to content

Commit

Permalink
Fixes to Taskfile including:
Browse files Browse the repository at this point in the history
- Disallow recursive Taskfile including (i.e. included Taskfile including other Taskfiles)
- Write test for included a file instead of a directory
  • Loading branch information
andreynering committed Oct 13, 2018
1 parent 5a28560 commit 5eb1a1f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions internal/taskfile/read/taskfile.go
@@ -1,6 +1,7 @@
package read

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -11,6 +12,9 @@ import (
"gopkg.in/yaml.v2"
)

// ErrIncludedTaskfilesCantHaveIncludes is returned when a included Taskfile contains includes
var ErrIncludedTaskfilesCantHaveIncludes = errors.New("task: Included Taskfiles can't have includes. Please, move the include to the main Taskfile")

// Taskfile reads a Taskfile for a given directory
func Taskfile(dir string) (*taskfile.Taskfile, error) {
path := filepath.Join(dir, "Taskfile.yml")
Expand All @@ -35,6 +39,9 @@ func Taskfile(dir string) (*taskfile.Taskfile, error) {
if err != nil {
return nil, err
}
if len(includedTaskfile.Includes) > 0 {
return nil, ErrIncludedTaskfilesCantHaveIncludes
}
if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions task_test.go
Expand Up @@ -477,8 +477,9 @@ func TestIncludes(t *testing.T) {
Target: "default",
TrimSpace: true,
Files: map[string]string{
"main.txt": "main",
"included.txt": "included",
"main.txt": "main",
"included_directory.txt": "included_directory",
"included_taskfile.txt": "included_taskfile",
},
}
tt.Run(t)
Expand Down
2 changes: 2 additions & 0 deletions testdata/includes/Taskfile.yml
Expand Up @@ -2,12 +2,14 @@ version: '2'

includes:
included: ./included
included_taskfile: ./Taskfile2.yml

tasks:
default:
cmds:
- task: gen
- task: included:gen
- task: included_taskfile:gen

gen:
cmds:
Expand Down
6 changes: 6 additions & 0 deletions testdata/includes/Taskfile2.yml
@@ -0,0 +1,6 @@
version: '2'

tasks:
gen:
cmds:
- echo included_taskfile > included_taskfile.txt
2 changes: 1 addition & 1 deletion testdata/includes/included/Taskfile.yml
Expand Up @@ -3,4 +3,4 @@ version: '2'
tasks:
gen:
cmds:
- echo included > included.txt
- echo included_directory > included_directory.txt

0 comments on commit 5eb1a1f

Please sign in to comment.