1
0
mirror of https://github.com/go-task/task.git synced 2025-06-17 00:17:51 +02:00

feat: make CHECKSUM and TIMESTAMP vars available in cmds commands (#1872)

This commit is contained in:
Niklas Rousset
2024-12-31 16:04:42 +01:00
committed by GitHub
parent dc2eceb634
commit c1e14c461b
5 changed files with 62 additions and 16 deletions

View File

@ -127,6 +127,23 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
}
}
if len(origTask.Sources) > 0 {
timestampChecker := fingerprint.NewTimestampChecker(e.TempDir.Fingerprint, e.Dry)
checksumChecker := fingerprint.NewChecksumChecker(e.TempDir.Fingerprint, e.Dry)
for _, checker := range []fingerprint.SourcesCheckable{timestampChecker, checksumChecker} {
value, err := checker.Value(&new)
if err != nil {
return nil, err
}
vars.Set(strings.ToUpper(checker.Kind()), ast.Var{Live: value})
}
// Adding new variables, requires us to refresh the templaters
// cache of the the values manually
cache.ResetCache()
}
if len(origTask.Cmds) > 0 {
new.Cmds = make([]*ast.Cmd, 0, len(origTask.Cmds))
for _, cmd := range origTask.Cmds {
@ -228,21 +245,6 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
}
if len(origTask.Status) > 0 {
timestampChecker := fingerprint.NewTimestampChecker(e.TempDir.Fingerprint, e.Dry)
checksumChecker := fingerprint.NewChecksumChecker(e.TempDir.Fingerprint, e.Dry)
for _, checker := range []fingerprint.SourcesCheckable{timestampChecker, checksumChecker} {
value, err := checker.Value(&new)
if err != nil {
return nil, err
}
vars.Set(strings.ToUpper(checker.Kind()), ast.Var{Live: value})
}
// Adding new variables, requires us to refresh the templaters
// cache of the the values manually
cache.ResetCache()
new.Status = templater.Replace(origTask.Status, cache)
}