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:
parent
9009124192
commit
c995fe6d11
@ -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())
|
||||||
|
12
testdata/cmds_vars/Taskfile.yml
vendored
12
testdata/cmds_vars/Taskfile.yml
vendored
@ -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}}'
|
||||||
|
8
testdata/status_vars/Taskfile.yml
vendored
8
testdata/status_vars/Taskfile.yml
vendored
@ -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}}'
|
||||||
|
13
variables.go
13
variables.go
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user