From 78595fba0b775128107e5687214ab63c0f3e8220 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sun, 8 Sep 2019 22:51:56 -0300 Subject: [PATCH] Make "checksum" the default method in v3 --- internal/status/checksum.go | 4 ++++ status.go | 2 +- task.go | 8 ++++++++ task_test.go | 4 ++-- testdata/generates/Taskfile.yml | 4 ++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/status/checksum.go b/internal/status/checksum.go index 572d4650..00fe9d60 100644 --- a/internal/status/checksum.go +++ b/internal/status/checksum.go @@ -23,6 +23,10 @@ type Checksum struct { // IsUpToDate implements the Checker interface func (c *Checksum) IsUpToDate() (bool, error) { + if len(c.Sources) == 0 { + return false, nil + } + checksumFile := c.checksumFilePath() data, _ := ioutil.ReadFile(checksumFile) diff --git a/status.go b/status.go index 554bb569..59a128fe 100644 --- a/status.go +++ b/status.go @@ -55,7 +55,7 @@ func (e *Executor) getStatusChecker(t *taskfile.Task) (status.Checker, error) { method = e.Taskfile.Method } switch method { - case "", "timestamp": + case "timestamp": return &status.Timestamp{ Dir: t.Dir, Sources: t.Sources, diff --git a/task.go b/task.go index 4d8097e7..a96742af 100644 --- a/task.go +++ b/task.go @@ -169,6 +169,14 @@ func (e *Executor) Setup() error { return fmt.Errorf(`task: output option "%s" not recognized`, e.Taskfile.Output) } + if e.Taskfile.Method == "" { + if v >= 3 { + e.Taskfile.Method = "checksum" + } else { + e.Taskfile.Method = "timestamp" + } + } + if v <= 2.1 { err := errors.New(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`) diff --git a/task_test.go b/task_test.go index 39bedb01..4c7c2d0b 100644 --- a/task_test.go +++ b/task_test.go @@ -630,7 +630,7 @@ func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) { } // Ensure that the directory to be created doesn't actually exist. - _ = os.Remove(toBeCreated) + _ = os.RemoveAll(toBeCreated) if _, err := os.Stat(toBeCreated); err == nil { t.Errorf("Directory should not exist: %v", err) } @@ -641,7 +641,7 @@ func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) { assert.Equal(t, expected, got, "Mismatch in the working directory") // Clean-up after ourselves only if no error. - _ = os.Remove(toBeCreated) + _ = os.RemoveAll(toBeCreated) } func TestDisplaysErrorOnUnsupportedVersion(t *testing.T) { diff --git a/testdata/generates/Taskfile.yml b/testdata/generates/Taskfile.yml index d050aa6b..9f05cfd0 100644 --- a/testdata/generates/Taskfile.yml +++ b/testdata/generates/Taskfile.yml @@ -8,6 +8,7 @@ tasks: dir: sub cmds: - cat src.txt > '{{.BUILD_DIR}}/abs.txt' + method: timestamp sources: - src.txt generates: @@ -20,6 +21,7 @@ tasks: dir: sub cmds: - cat src.txt > '../rel.txt' + method: timestamp sources: - src.txt generates: @@ -30,6 +32,7 @@ tasks: cmds: - mkdir -p sub - echo "hello world" > sub/src.txt + method: timestamp status: - test -f sub/src.txt @@ -38,6 +41,7 @@ tasks: deps: [sub/src.txt] cmds: - cat sub/src.txt > 'my text file.txt' + method: timestamp sources: - sub/src.txt generates: