1
0
mirror of https://github.com/go-task/task.git synced 2025-05-29 23:17:53 +02:00

Merge pull request #1037 from go-task/fix-status-and-sources

fix: status and sources
This commit is contained in:
Pete Davison 2023-03-07 00:35:45 +00:00 committed by GitHub
commit a29e5d39ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 15 deletions

View File

@ -4,7 +4,7 @@
- Fixed bug where `.task/checksum` file was sometimes not being created when - Fixed bug where `.task/checksum` file was sometimes not being created when
task also declares a `status:` task also declares a `status:`
([#840](https://github.com/go-task/task/issues/840), [#1035](https://github.com/go-task/task/pull/1035) by @harelwa). ([#840](https://github.com/go-task/task/issues/840), [#1035](https://github.com/go-task/task/pull/1035) by @harelwa, [#1037](https://github.com/go-task/task/pull/1037) by @pd93).
- Fixed deadlock issue when using `run: once` - Fixed deadlock issue when using `run: once`
([#715](https://github.com/go-task/task/issues/715), [#1025](https://github.com/go-task/task/pull/1025) by @theunrepentantgeek). ([#715](https://github.com/go-task/task/issues/715), [#1025](https://github.com/go-task/task/pull/1025) by @theunrepentantgeek).

View File

@ -29,36 +29,51 @@ func (e *Executor) Status(ctx context.Context, calls ...taskfile.Call) error {
} }
func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) { func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) {
isUpToDateStatus := true var statusUpToDate bool
isUpToDateChecker := true var sourcesUpToDate bool
var err error
if len(t.Status) > 0 { statusIsSet := len(t.Status) != 0
isUpToDate, err := e.isTaskUpToDateStatus(ctx, t) sourcesIsSet := len(t.Sources) != 0
// If status is set, check if it is up-to-date
if statusIsSet {
statusUpToDate, err = e.isTaskUpToDateStatus(ctx, t)
if err != nil { if err != nil {
return false, err return false, err
} }
if !isUpToDate {
isUpToDateStatus = false
}
} }
if len(t.Sources) > 0 { // If sources is set, check if they are up-to-date
if sourcesIsSet {
checker, err := e.getStatusChecker(t) checker, err := e.getStatusChecker(t)
if err != nil { if err != nil {
return false, err return false, err
} }
isUpToDate, err := checker.IsUpToDate() sourcesUpToDate, err = checker.IsUpToDate()
if err != nil { if err != nil {
return false, err return false, err
} }
if !isUpToDate {
isUpToDateChecker = false
}
} }
isUpToDate := isUpToDateStatus && isUpToDateChecker // If both status and sources are set, the task is up-to-date if both are up-to-date
if statusIsSet && sourcesIsSet {
return statusUpToDate && sourcesUpToDate, nil
}
return isUpToDate, nil // If only status is set, the task is up-to-date if the status is up-to-date
if statusIsSet {
return statusUpToDate, nil
}
// If only sources is set, the task is up-to-date if the sources are up-to-date
if sourcesIsSet {
return sourcesUpToDate, nil
}
// If no status or sources are set, the task should always run
// i.e. it is never considered "up-to-date"
return false, nil
} }
func (e *Executor) statusOnError(t *taskfile.Task) error { func (e *Executor) statusOnError(t *taskfile.Task) error {