mirror of
https://github.com/go-task/task.git
synced 2025-06-25 00:47:04 +02:00
Fixes to Taskfile including:
- Disallow recursive Taskfile including (i.e. included Taskfile including other Taskfiles) - Write test for included a file instead of a directory
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package read
|
package read
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -11,6 +12,9 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"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
|
// Taskfile reads a Taskfile for a given directory
|
||||||
func Taskfile(dir string) (*taskfile.Taskfile, error) {
|
func Taskfile(dir string) (*taskfile.Taskfile, error) {
|
||||||
path := filepath.Join(dir, "Taskfile.yml")
|
path := filepath.Join(dir, "Taskfile.yml")
|
||||||
@ -35,6 +39,9 @@ func Taskfile(dir string) (*taskfile.Taskfile, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(includedTaskfile.Includes) > 0 {
|
||||||
|
return nil, ErrIncludedTaskfilesCantHaveIncludes
|
||||||
|
}
|
||||||
if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {
|
if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -478,7 +478,8 @@ func TestIncludes(t *testing.T) {
|
|||||||
TrimSpace: true,
|
TrimSpace: true,
|
||||||
Files: map[string]string{
|
Files: map[string]string{
|
||||||
"main.txt": "main",
|
"main.txt": "main",
|
||||||
"included.txt": "included",
|
"included_directory.txt": "included_directory",
|
||||||
|
"included_taskfile.txt": "included_taskfile",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tt.Run(t)
|
tt.Run(t)
|
||||||
|
2
testdata/includes/Taskfile.yml
vendored
2
testdata/includes/Taskfile.yml
vendored
@ -2,12 +2,14 @@ version: '2'
|
|||||||
|
|
||||||
includes:
|
includes:
|
||||||
included: ./included
|
included: ./included
|
||||||
|
included_taskfile: ./Taskfile2.yml
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
cmds:
|
cmds:
|
||||||
- task: gen
|
- task: gen
|
||||||
- task: included:gen
|
- task: included:gen
|
||||||
|
- task: included_taskfile:gen
|
||||||
|
|
||||||
gen:
|
gen:
|
||||||
cmds:
|
cmds:
|
||||||
|
6
testdata/includes/Taskfile2.yml
vendored
Normal file
6
testdata/includes/Taskfile2.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
gen:
|
||||||
|
cmds:
|
||||||
|
- echo included_taskfile > included_taskfile.txt
|
2
testdata/includes/included/Taskfile.yml
vendored
2
testdata/includes/included/Taskfile.yml
vendored
@ -3,4 +3,4 @@ version: '2'
|
|||||||
tasks:
|
tasks:
|
||||||
gen:
|
gen:
|
||||||
cmds:
|
cmds:
|
||||||
- echo included > included.txt
|
- echo included_directory > included_directory.txt
|
||||||
|
Reference in New Issue
Block a user