mirror of
https://github.com/go-task/task.git
synced 2025-01-22 05:10:17 +02:00
Added version validation and updated tests
This commit is contained in:
parent
f38ba7fcd3
commit
17ad7060b3
@ -11,6 +11,7 @@ var (
|
|||||||
type IncludedTaskfile struct {
|
type IncludedTaskfile struct {
|
||||||
Taskfile string
|
Taskfile string
|
||||||
Dir string
|
Dir string
|
||||||
|
AdvancedImport bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// IncludedTaskfiles represents information about included tasksfiles
|
// IncludedTaskfiles represents information about included tasksfiles
|
||||||
@ -31,6 +32,7 @@ func (it *IncludedTaskfile) UnmarshalYAML(unmarshal func(interface{}) error) err
|
|||||||
if err := unmarshal(&includedTaskfile); err == nil {
|
if err := unmarshal(&includedTaskfile); err == nil {
|
||||||
it.Dir = includedTaskfile.Dir
|
it.Dir = includedTaskfile.Dir
|
||||||
it.Taskfile = includedTaskfile.Taskfile
|
it.Taskfile = includedTaskfile.Taskfile
|
||||||
|
it.AdvancedImport = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,11 +45,13 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
|
|||||||
return nil, ErrIncludedTaskfilesCantHaveIncludes
|
return nil, ErrIncludedTaskfilesCantHaveIncludes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if includedTask.AdvancedImport {
|
||||||
for _, task := range includedTaskfile.Tasks {
|
for _, task := range includedTaskfile.Tasks {
|
||||||
if !filepath.IsAbs(task.Dir) {
|
if !filepath.IsAbs(task.Dir) {
|
||||||
task.Dir = filepath.Join(includedTask.Dir, task.Dir)
|
task.Dir = filepath.Join(includedTask.Dir, task.Dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {
|
if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
8
task.go
8
task.go
@ -207,6 +207,14 @@ func (e *Executor) Setup() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v < 3 {
|
||||||
|
for _, taskfile := range e.Taskfile.Includes {
|
||||||
|
if taskfile.AdvancedImport {
|
||||||
|
return errors.New(`task: Import with additional parameters is only available starting on Taskfile version v3`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks))
|
e.taskCallCount = make(map[string]*int32, len(e.Taskfile.Tasks))
|
||||||
e.mkdirMutexMap = make(map[string]*sync.Mutex, len(e.Taskfile.Tasks))
|
e.mkdirMutexMap = make(map[string]*sync.Mutex, len(e.Taskfile.Tasks))
|
||||||
for k := range e.Taskfile.Tasks {
|
for k := range e.Taskfile.Tasks {
|
||||||
|
15
task_test.go
15
task_test.go
@ -551,6 +551,21 @@ func TestIncludes(t *testing.T) {
|
|||||||
tt.Run(t)
|
tt.Run(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIncorrectVersionIncludes(t *testing.T) {
|
||||||
|
const dir = "testdata/incorrect_includes"
|
||||||
|
expectedError := "task: Import with additional parameters is only available starting on Taskfile version v3"
|
||||||
|
|
||||||
|
var buff bytes.Buffer
|
||||||
|
e := task.Executor{
|
||||||
|
Dir: dir,
|
||||||
|
Stdout: &buff,
|
||||||
|
Stderr: &buff,
|
||||||
|
Silent: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.EqualError(t, e.Setup(), expectedError)
|
||||||
|
}
|
||||||
|
|
||||||
func TestIncludesEmptyMain(t *testing.T) {
|
func TestIncludesEmptyMain(t *testing.T) {
|
||||||
tt := fileContentTest{
|
tt := fileContentTest{
|
||||||
Dir: "testdata/includes_empty",
|
Dir: "testdata/includes_empty",
|
||||||
|
10
testdata/incorrect_includes/Taskfile.yml
vendored
Normal file
10
testdata/incorrect_includes/Taskfile.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version: '2.6'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
included:
|
||||||
|
taskfile: ./included
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- task: gen
|
6
testdata/incorrect_includes/included/Taskfile.yml
vendored
Normal file
6
testdata/incorrect_includes/included/Taskfile.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
version: '2.6'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
gen:
|
||||||
|
cmds:
|
||||||
|
- echo incorrect includes test
|
Loading…
x
Reference in New Issue
Block a user