( ctx context.Context, t *ast.Task, opts ...CheckerOption, )
| 56 | } |
| 57 | |
| 58 | func IsTaskUpToDate( |
| 59 | ctx context.Context, |
| 60 | t *ast.Task, |
| 61 | opts ...CheckerOption, |
| 62 | ) (bool, error) { |
| 63 | var statusUpToDate bool |
| 64 | var sourcesUpToDate bool |
| 65 | var err error |
| 66 | |
| 67 | // Default config |
| 68 | config := &CheckerConfig{ |
| 69 | method: "none", |
| 70 | tempDir: "", |
| 71 | dry: false, |
| 72 | logger: nil, |
| 73 | statusChecker: nil, |
| 74 | sourcesChecker: nil, |
| 75 | } |
| 76 | |
| 77 | // Apply functional options |
| 78 | for _, opt := range opts { |
| 79 | opt(config) |
| 80 | } |
| 81 | |
| 82 | // If no status checker was given, set up the default one |
| 83 | if config.statusChecker == nil { |
| 84 | config.statusChecker = NewStatusChecker(config.logger) |
| 85 | } |
| 86 | |
| 87 | // If no sources checker was given, set up the default one |
| 88 | if config.sourcesChecker == nil { |
| 89 | config.sourcesChecker, err = NewSourcesChecker(config.method, config.tempDir, config.dry) |
| 90 | if err != nil { |
| 91 | return false, err |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | statusIsSet := len(t.Status) != 0 |
| 96 | sourcesIsSet := len(t.Sources) != 0 |
| 97 | |
| 98 | // If status is set, check if it is up-to-date |
| 99 | if statusIsSet { |
| 100 | statusUpToDate, err = config.statusChecker.IsUpToDate(ctx, t) |
| 101 | if err != nil { |
| 102 | return false, err |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // If sources is set, check if they are up-to-date |
| 107 | if sourcesIsSet { |
| 108 | sourcesUpToDate, err = config.sourcesChecker.IsUpToDate(t) |
| 109 | if err != nil { |
| 110 | return false, err |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // If both status and sources are set, the task is up-to-date if both are up-to-date |
| 115 | if statusIsSet && sourcesIsSet { |
searching dependent graphs…