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

fix(checker): use only one checker at the same time to improve perf (#2031)

* fix(checker): use only one checker at the same time to improve performance

* refactor

* fix test
This commit is contained in:
Valentin Maerten 2025-02-08 17:34:04 +01:00 committed by GitHub
parent 9009124192
commit c995fe6d11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 15 deletions

View File

@ -969,10 +969,13 @@ func TestStatusVariables(t *testing.T) {
Verbose: true, Verbose: true,
} }
require.NoError(t, e.Setup()) require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "build"})) require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "build-checksum"}))
assert.Contains(t, buff.String(), "3e464c4b03f4b65d740e1e130d4d108a") assert.Contains(t, buff.String(), "3e464c4b03f4b65d740e1e130d4d108a")
buff.Reset()
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "build-ts"}))
inf, err := os.Stat(filepathext.SmartJoin(dir, "source.txt")) inf, err := os.Stat(filepathext.SmartJoin(dir, "source.txt"))
require.NoError(t, err) require.NoError(t, err)
ts := fmt.Sprintf("%d", inf.ModTime().Unix()) ts := fmt.Sprintf("%d", inf.ModTime().Unix())
@ -1002,10 +1005,12 @@ func TestCmdsVariables(t *testing.T) {
Verbose: true, Verbose: true,
} }
require.NoError(t, e.Setup()) require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "build"})) require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "build-checksum"}))
assert.Contains(t, buff.String(), "3e464c4b03f4b65d740e1e130d4d108a") assert.Contains(t, buff.String(), "3e464c4b03f4b65d740e1e130d4d108a")
buff.Reset()
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "build-ts"}))
inf, err := os.Stat(filepathext.SmartJoin(dir, "source.txt")) inf, err := os.Stat(filepathext.SmartJoin(dir, "source.txt"))
require.NoError(t, err) require.NoError(t, err)
ts := fmt.Sprintf("%d", inf.ModTime().Unix()) ts := fmt.Sprintf("%d", inf.ModTime().Unix())

View File

@ -1,10 +1,16 @@
version: '3' version: '3'
tasks: tasks:
build: build-checksum:
sources: sources:
- ./source.txt - ./source.txt
cmds: cmds:
- echo "{{.CHECKSUM}}" - echo "{{.CHECKSUM}}"
- echo "{{.TIMESTAMP.Unix}}"
- echo "{{.TIMESTAMP}}" build-ts:
method: timestamp
sources:
- ./source.txt
cmds:
- echo '{{.TIMESTAMP.Unix}}'
- echo '{{.TIMESTAMP}}'

View File

@ -1,10 +1,16 @@
version: '3' version: '3'
tasks: tasks:
build: build-checksum:
sources: sources:
- ./source.txt - ./source.txt
status: status:
- echo "{{.CHECKSUM}}" - echo "{{.CHECKSUM}}"
build-ts:
method: timestamp
sources:
- ./source.txt
status:
- echo '{{.TIMESTAMP.Unix}}' - echo '{{.TIMESTAMP.Unix}}'
- echo '{{.TIMESTAMP}}' - echo '{{.TIMESTAMP}}'

View File

@ -128,17 +128,20 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task,
} }
} }
if len(origTask.Sources) > 0 { if len(origTask.Sources) > 0 && origTask.Method != "none" {
timestampChecker := fingerprint.NewTimestampChecker(e.TempDir.Fingerprint, e.Dry) var checker fingerprint.SourcesCheckable
checksumChecker := fingerprint.NewChecksumChecker(e.TempDir.Fingerprint, e.Dry)
if origTask.Method == "timestamp" {
checker = fingerprint.NewTimestampChecker(e.TempDir.Fingerprint, e.Dry)
} else {
checker = fingerprint.NewChecksumChecker(e.TempDir.Fingerprint, e.Dry)
}
for _, checker := range []fingerprint.SourcesCheckable{timestampChecker, checksumChecker} {
value, err := checker.Value(&new) value, err := checker.Value(&new)
if err != nil { if err != nil {
return nil, err return nil, err
} }
vars.Set(strings.ToUpper(checker.Kind()), ast.Var{Live: value}) vars.Set(strings.ToUpper(checker.Kind()), ast.Var{Live: value})
}
// Adding new variables, requires us to refresh the templaters // Adding new variables, requires us to refresh the templaters
// cache of the the values manually // cache of the the values manually