diff --git a/CHANGELOG.md b/CHANGELOG.md index b2fe27f9..a7420c5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ (`{{splitArgs "foo bar 'foo bar baz'"}}`) to ensure string is splitted as arguments not whitespaces ([#1040](https://github.com/go-task/task/issues/1040), [#1059](https://github.com/go-task/task/pull/1059) by @dhanusaputra). +- Fix the value of `{{.CHECKSUM}}` variable in status ([#1076](https://github.com/go-task/task/issues/1076), [#1080](https://github.com/go-task/task/pull/1080) by @pd93). ## v3.22.0 - 2023-03-10 diff --git a/internal/fingerprint/sources_checksum.go b/internal/fingerprint/sources_checksum.go index 85680da5..64e57f3f 100644 --- a/internal/fingerprint/sources_checksum.go +++ b/internal/fingerprint/sources_checksum.go @@ -37,12 +37,7 @@ func (checker *ChecksumChecker) IsUpToDate(t *taskfile.Task) (bool, error) { data, _ := os.ReadFile(checksumFile) oldMd5 := strings.TrimSpace(string(data)) - sources, err := globs(t.Dir, t.Sources) - if err != nil { - return false, err - } - - newMd5, err := checker.checksum(sources...) + newMd5, err := checker.checksum(t) if err != nil { return false, nil } @@ -74,7 +69,7 @@ func (checker *ChecksumChecker) IsUpToDate(t *taskfile.Task) (bool, error) { } func (checker *ChecksumChecker) Value(t *taskfile.Task) (interface{}, error) { - return checker.checksum() + return checker.checksum(t) } func (checker *ChecksumChecker) OnError(t *taskfile.Task) error { @@ -88,10 +83,14 @@ func (*ChecksumChecker) Kind() string { return "checksum" } -func (c *ChecksumChecker) checksum(files ...string) (string, error) { - h := md5.New() +func (c *ChecksumChecker) checksum(t *taskfile.Task) (string, error) { + sources, err := globs(t.Dir, t.Sources) + if err != nil { + return "", err + } - for _, f := range files { + h := md5.New() + for _, f := range sources { // also sum the filename, so checksum changes for renaming a file if _, err := io.Copy(h, strings.NewReader(filepath.Base(f))); err != nil { return "", err diff --git a/task_test.go b/task_test.go index 36c444f6..7aafa6cc 100644 --- a/task_test.go +++ b/task_test.go @@ -691,7 +691,7 @@ func TestStatusVariables(t *testing.T) { assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "build"})) - assert.Contains(t, buff.String(), "d41d8cd98f00b204e9800998ecf8427e") + assert.Contains(t, buff.String(), "a41e7948dcd321db412ce61d3d5c9864") inf, err := os.Stat(filepathext.SmartJoin(dir, "source.txt")) assert.NoError(t, err)