1
0
mirror of https://github.com/go-task/task.git synced 2025-01-26 05:27:15 +02:00

Removed automatic inclusion of Taskfiles by OS and update tests

This commit is contained in:
Evgeny Abramovich 2020-02-15 16:40:42 +03:00
parent a3464068bd
commit f38ba7fcd3
11 changed files with 10 additions and 49 deletions

View File

@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"github.com/go-task/task/v2/internal/taskfile"
@ -46,21 +45,10 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
return nil, ErrIncludedTaskfilesCantHaveIncludes
}
includedTaskDirectory := filepath.Dir(path)
includedTaskfileName := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
path = filepath.Join(includedTaskDirectory, fmt.Sprintf("%s_%s.yml", includedTaskfileName, runtime.GOOS))
if _, err = os.Stat(path); err == nil {
osIncludedTaskfile, err := readTaskfile(path)
if err != nil {
return nil, err
}
if err = taskfile.Merge(includedTaskfile, osIncludedTaskfile); err != nil {
return nil, err
}
}
for _, task := range includedTaskfile.Tasks {
task.Dir = filepath.Join(includedTask.Dir, task.Dir)
if !filepath.IsAbs(task.Dir) {
task.Dir = filepath.Join(includedTask.Dir, task.Dir)
}
}
if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {

View File

@ -546,7 +546,6 @@ func TestIncludes(t *testing.T) {
"included_taskfile_without_dir.txt": "included_taskfile_without_dir",
"./module2/included_directory_with_dir.txt": "included_directory_with_dir",
"./module2/included_taskfile_with_dir.txt": "included_taskfile_with_dir",
"./module3/os_related.txt": runtime.GOOS,
},
}
tt.Run(t)

View File

@ -1,4 +1,4 @@
version: '2'
version: '3'
includes:
included: ./included
@ -13,9 +13,6 @@ includes:
included_taskfile_with_dir:
taskfile: ./module2/Taskfile.yml
dir: ./module2
os_related:
taskfile: ./module3/CustomTaskfile.yml
dir: ./module3
tasks:
default:
@ -27,7 +24,6 @@ tasks:
- task: included_taskfile_without_dir:gen_dir
- task: included_with_dir:gen_file
- task: included_taskfile_with_dir:gen_dir
- task: os_related:gen
gen:
cmds:

View File

@ -1,4 +1,4 @@
version: '2'
version: '3'
tasks:
gen:

View File

@ -1,4 +1,4 @@
version: '2'
version: '3'
tasks:
gen:

View File

@ -1,9 +1,10 @@
version: '2'
version: '3'
tasks:
gen_dir:
cmds:
- echo included_directory_without_dir > included_directory_without_dir.txt
gen_file:
cmds:
- echo included_taskfile_without_dir > included_taskfile_without_dir.txt

View File

@ -1,9 +1,10 @@
version: '2'
version: '3'
tasks:
gen_dir:
cmds:
- echo included_directory_with_dir > included_directory_with_dir.txt
gen_file:
cmds:
- echo included_taskfile_with_dir > included_taskfile_with_dir.txt

View File

@ -1,6 +0,0 @@
version: '2'
tasks:
gen:
cmds:
- echo "INVALID" > os_related.txt

View File

@ -1,6 +0,0 @@
version: '2'
tasks:
gen:
cmds:
- echo "darwin" > os_related.txt

View File

@ -1,6 +0,0 @@
version: '2'
tasks:
gen:
cmds:
- echo "linux" > os_related.txt

View File

@ -1,6 +0,0 @@
version: '2'
tasks:
gen:
cmds:
- echo "windows" > os_related.txt