From 51c6ebcd4d4f374a5458b7ad9686ade4dcce2054 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 19 Feb 2022 18:24:43 -0300 Subject: [PATCH] Add tests, documentation and changelog for #666 --- CHANGELOG.md | 6 +++++ docs/usage.md | 14 ++++++++++++ task_test.go | 22 +++++++++++++++++++ taskfile/read/taskfile.go | 7 +++++- testdata/file_names/.gitignore | 1 + .../Taskfile.dist.yaml/Taskfile.dist.yaml | 4 ++++ .../Taskfile.dist.yml/Taskfile.dist.yml | 4 ++++ .../file_names/Taskfile.yaml/Taskfile.yaml | 4 ++++ testdata/file_names/Taskfile.yml/Taskfile.yml | 4 ++++ 9 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 testdata/file_names/.gitignore create mode 100644 testdata/file_names/Taskfile.dist.yaml/Taskfile.dist.yaml create mode 100644 testdata/file_names/Taskfile.dist.yml/Taskfile.dist.yml create mode 100644 testdata/file_names/Taskfile.yaml/Taskfile.yaml create mode 100644 testdata/file_names/Taskfile.yml/Taskfile.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d9d369..8606b341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +- Add `Taskfile.dist.yml` and `Taskfile.dist.yaml` to the supported file + name list. [Check out the documentation for more information](https://taskfile.dev/#/usage?id=supported-file-names). + ([#498](https://github.com/go-task/task/issues/498), [#666](https://github.com/go-task/task/pull/666)). + ## v3.10.0 - 2022-01-04 - A new `--list-all` (alias `-a`) flag is now available. It's similar to the diff --git a/docs/usage.md b/docs/usage.md index 780b1f27..9e8aafa3 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -33,6 +33,20 @@ executable called must be available by the OS or in PATH. If you omit a task name, "default" will be assumed. +## Supported file names + +Task will look for the following file names, in order of priority: + +- Taskfile.yml +- Taskfile.yaml +- Taskfile.dist.yml +- Taskfile.dist.yaml + +The intention of having the `.dist` variants is to allow projects to have one +commited version (`.dist`) while still allowing individual users to override +the Taskfile by adding an additional `Taskfile.yml` (which would be on +`.gitignore`). + ## Environment variables ### Task diff --git a/task_test.go b/task_test.go index cb75bb00..ff5db53a 100644 --- a/task_test.go +++ b/task_test.go @@ -856,6 +856,28 @@ func TestIncludesFromCustomTaskfile(t *testing.T) { tt.Run(t) } +func TestSupportedFileNames(t *testing.T) { + fileNames := []string{ + "Taskfile.yml", + "Taskfile.yaml", + "Taskfile.dist.yml", + "Taskfile.dist.yaml", + } + for _, fileName := range fileNames { + t.Run(fileName, func(t *testing.T) { + tt := fileContentTest{ + Dir: fmt.Sprintf("testdata/file_names/%s", fileName), + Target: "default", + TrimSpace: true, + Files: map[string]string{ + "output.txt": "hello", + }, + } + tt.Run(t) + }) + } +} + func TestSummary(t *testing.T) { const dir = "testdata/summary" diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index 851789cd..6d54f356 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -20,7 +20,12 @@ var ( // ErrIncludedTaskfilesCantHaveDotenvs is returned when a included Taskfile contains dotenvs ErrIncludedTaskfilesCantHaveDotenvs = errors.New("task: Included Taskfiles can't have dotenv declarations. Please, move the dotenv declaration to the main Taskfile") - defaultTaskfiles = []string{"Taskfile.yml", "Taskfile.yaml", "Taskfile.dist.yml", "Taskfile.dist.yaml"} + defaultTaskfiles = []string{ + "Taskfile.yml", + "Taskfile.yaml", + "Taskfile.dist.yml", + "Taskfile.dist.yaml", + } ) // Taskfile reads a Taskfile for a given directory diff --git a/testdata/file_names/.gitignore b/testdata/file_names/.gitignore new file mode 100644 index 00000000..2211df63 --- /dev/null +++ b/testdata/file_names/.gitignore @@ -0,0 +1 @@ +*.txt diff --git a/testdata/file_names/Taskfile.dist.yaml/Taskfile.dist.yaml b/testdata/file_names/Taskfile.dist.yaml/Taskfile.dist.yaml new file mode 100644 index 00000000..6c62d05b --- /dev/null +++ b/testdata/file_names/Taskfile.dist.yaml/Taskfile.dist.yaml @@ -0,0 +1,4 @@ +version: '3' + +tasks: + default: echo "hello" > output.txt diff --git a/testdata/file_names/Taskfile.dist.yml/Taskfile.dist.yml b/testdata/file_names/Taskfile.dist.yml/Taskfile.dist.yml new file mode 100644 index 00000000..6c62d05b --- /dev/null +++ b/testdata/file_names/Taskfile.dist.yml/Taskfile.dist.yml @@ -0,0 +1,4 @@ +version: '3' + +tasks: + default: echo "hello" > output.txt diff --git a/testdata/file_names/Taskfile.yaml/Taskfile.yaml b/testdata/file_names/Taskfile.yaml/Taskfile.yaml new file mode 100644 index 00000000..6c62d05b --- /dev/null +++ b/testdata/file_names/Taskfile.yaml/Taskfile.yaml @@ -0,0 +1,4 @@ +version: '3' + +tasks: + default: echo "hello" > output.txt diff --git a/testdata/file_names/Taskfile.yml/Taskfile.yml b/testdata/file_names/Taskfile.yml/Taskfile.yml new file mode 100644 index 00000000..6c62d05b --- /dev/null +++ b/testdata/file_names/Taskfile.yml/Taskfile.yml @@ -0,0 +1,4 @@ +version: '3' + +tasks: + default: echo "hello" > output.txt