From f38ba7fcd31dd2d1ba0a09154990516bb4948705 Mon Sep 17 00:00:00 2001 From: Evgeny Abramovich Date: Sat, 15 Feb 2020 16:40:42 +0300 Subject: [PATCH] Removed automatic inclusion of Taskfiles by OS and update tests --- internal/taskfile/read/taskfile.go | 18 +++--------------- task_test.go | 1 - testdata/includes/Taskfile.yml | 6 +----- testdata/includes/Taskfile2.yml | 2 +- testdata/includes/included/Taskfile.yml | 2 +- testdata/includes/module1/Taskfile.yml | 3 ++- testdata/includes/module2/Taskfile.yml | 3 ++- testdata/includes/module3/CustomTaskfile.yml | 6 ------ .../includes/module3/CustomTaskfile_darwin.yml | 6 ------ .../includes/module3/CustomTaskfile_linux.yml | 6 ------ .../module3/CustomTaskfile_windows.yml | 6 ------ 11 files changed, 10 insertions(+), 49 deletions(-) delete mode 100644 testdata/includes/module3/CustomTaskfile.yml delete mode 100644 testdata/includes/module3/CustomTaskfile_darwin.yml delete mode 100644 testdata/includes/module3/CustomTaskfile_linux.yml delete mode 100644 testdata/includes/module3/CustomTaskfile_windows.yml diff --git a/internal/taskfile/read/taskfile.go b/internal/taskfile/read/taskfile.go index cd80ca8b..8cf149d2 100644 --- a/internal/taskfile/read/taskfile.go +++ b/internal/taskfile/read/taskfile.go @@ -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 { diff --git a/task_test.go b/task_test.go index ce31ff1b..9bda7b93 100644 --- a/task_test.go +++ b/task_test.go @@ -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) diff --git a/testdata/includes/Taskfile.yml b/testdata/includes/Taskfile.yml index 144116fb..e94099e1 100644 --- a/testdata/includes/Taskfile.yml +++ b/testdata/includes/Taskfile.yml @@ -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: diff --git a/testdata/includes/Taskfile2.yml b/testdata/includes/Taskfile2.yml index dbb4a34c..858fb38b 100644 --- a/testdata/includes/Taskfile2.yml +++ b/testdata/includes/Taskfile2.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' tasks: gen: diff --git a/testdata/includes/included/Taskfile.yml b/testdata/includes/included/Taskfile.yml index e8fe2ad2..93b82347 100644 --- a/testdata/includes/included/Taskfile.yml +++ b/testdata/includes/included/Taskfile.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3' tasks: gen: diff --git a/testdata/includes/module1/Taskfile.yml b/testdata/includes/module1/Taskfile.yml index e5d5126b..3659073e 100644 --- a/testdata/includes/module1/Taskfile.yml +++ b/testdata/includes/module1/Taskfile.yml @@ -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 diff --git a/testdata/includes/module2/Taskfile.yml b/testdata/includes/module2/Taskfile.yml index e746d559..09bbdb60 100644 --- a/testdata/includes/module2/Taskfile.yml +++ b/testdata/includes/module2/Taskfile.yml @@ -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 diff --git a/testdata/includes/module3/CustomTaskfile.yml b/testdata/includes/module3/CustomTaskfile.yml deleted file mode 100644 index a9a954a5..00000000 --- a/testdata/includes/module3/CustomTaskfile.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: '2' - -tasks: - gen: - cmds: - - echo "INVALID" > os_related.txt diff --git a/testdata/includes/module3/CustomTaskfile_darwin.yml b/testdata/includes/module3/CustomTaskfile_darwin.yml deleted file mode 100644 index 5b9ed323..00000000 --- a/testdata/includes/module3/CustomTaskfile_darwin.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: '2' - -tasks: - gen: - cmds: - - echo "darwin" > os_related.txt diff --git a/testdata/includes/module3/CustomTaskfile_linux.yml b/testdata/includes/module3/CustomTaskfile_linux.yml deleted file mode 100644 index 2fc40546..00000000 --- a/testdata/includes/module3/CustomTaskfile_linux.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: '2' - -tasks: - gen: - cmds: - - echo "linux" > os_related.txt diff --git a/testdata/includes/module3/CustomTaskfile_windows.yml b/testdata/includes/module3/CustomTaskfile_windows.yml deleted file mode 100644 index 5307e81f..00000000 --- a/testdata/includes/module3/CustomTaskfile_windows.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: '2' - -tasks: - gen: - cmds: - - echo "windows" > os_related.txt