Skip to content

Commit

Permalink
fix: fix checking for the source/status combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 15, 2023
1 parent 8a4dcef commit 749028e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions internal/fingerprint/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func (checker *DefinitionChecker) IsUpToDate(maybeDefinitionPath *string) (bool,
_, err := os.Stat(definitionPath)
if err == nil {
checker.logger.VerboseOutf(logger.Magenta, "task: task definition is up-to-date: %s\n", definitionPath)
// file exists, the task definition is up to
// file exists, the task definition is-up-to-date
return true, nil
}

// task is not up-to-date as the file does not exist
// create the hash file if not in dry mode
// create the definition file if not in dry mode for the later runs
if !checker.dry {
// create the file
if err := os.MkdirAll(filepath.Dir(definitionPath), 0o755); err != nil {
Expand Down
14 changes: 5 additions & 9 deletions internal/fingerprint/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func IsTaskUpToDate(
// if the status or sources are set, check if the definition is up-to-date
// TODO: allow caching based on the task definition even if status or sources are not set
if sourcesIsSet || statusIsSet {
// if other conditions are , check if the definition is up-to-date
// check if the definition is up-to-date
isDefinitionUpToDate, err := config.definitionChecker.IsUpToDate(maybeDefinitionPath)
if err != nil {
return false, err
Expand Down Expand Up @@ -145,15 +145,11 @@ func IsTaskUpToDate(
// If both status and sources are set, the task is up-to-date if both are up-to-date
if statusIsSet && sourcesIsSet {
isUpToDate = statusUpToDate && sourcesUpToDate
}

// If only status is set, the task is up-to-date if the status is up-to-date
if statusIsSet {
} else if statusIsSet {
// If only status is set, the task is up-to-date if the status is up-to-date
isUpToDate = statusUpToDate
}

// If only sources is set, the task is up-to-date if the sources are up-to-date
if sourcesIsSet {
} else if sourcesIsSet {
// If only sources is set, the task is up-to-date if the sources are up-to-date
isUpToDate = sourcesUpToDate
}

Expand Down
7 changes: 6 additions & 1 deletion task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,12 @@ func TestAlias(t *testing.T) {
}
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "f"}))
assert.Equal(t, string(data), buff.String())

dataString := string(data)
// replace \r\n with \n to unify line endings
dataString = strings.ReplaceAll(dataString, "\r\n", "\n")

assert.Equal(t, dataString, buff.String())
}

func TestDuplicateAlias(t *testing.T) {
Expand Down

0 comments on commit 749028e

Please sign in to comment.