mirror of
https://github.com/go-task/task.git
synced 2025-03-05 15:05:42 +02:00
Merge pull request #246 from go-task/method-on-v3
Add global "method:" option to allow setting a default for all tasks. Change default from "timestamp" to "checksum"
This commit is contained in:
commit
6a7a3c0ae8
@ -4,6 +4,12 @@
|
||||
|
||||
- Taskfiles in version 1 are not supported anymore
|
||||
([#237](https://github.com/go-task/task/pull/237)).
|
||||
- Added global `method:` option. With this option, you can set a default
|
||||
method to all tasks in a Taskfile
|
||||
([#246](https://github.com/go-task/task/issues/246)).
|
||||
- Changed default method from `timestamp` to `checksum`
|
||||
([#246](https://github.com/go-task/task/issues/246)).
|
||||
|
||||
|
||||
## v3.0.0 - Preview 1
|
||||
|
||||
|
@ -23,6 +23,10 @@ type Checksum struct {
|
||||
|
||||
// IsUpToDate implements the Checker interface
|
||||
func (c *Checksum) IsUpToDate() (bool, error) {
|
||||
if len(c.Sources) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
checksumFile := c.checksumFilePath()
|
||||
|
||||
data, _ := ioutil.ReadFile(checksumFile)
|
||||
|
@ -5,6 +5,7 @@ type Taskfile struct {
|
||||
Version string
|
||||
Expansions int
|
||||
Output string
|
||||
Method string
|
||||
Includes map[string]string
|
||||
Vars Vars
|
||||
Env Vars
|
||||
@ -17,6 +18,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
Version string
|
||||
Expansions int
|
||||
Output string
|
||||
Method string
|
||||
Includes map[string]string
|
||||
Vars Vars
|
||||
Env Vars
|
||||
@ -28,6 +30,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
tf.Version = taskfile.Version
|
||||
tf.Expansions = taskfile.Expansions
|
||||
tf.Output = taskfile.Output
|
||||
tf.Method = taskfile.Method
|
||||
tf.Includes = taskfile.Includes
|
||||
tf.Vars = taskfile.Vars
|
||||
tf.Env = taskfile.Env
|
||||
|
10
status.go
10
status.go
@ -50,8 +50,12 @@ func (e *Executor) statusOnError(t *taskfile.Task) error {
|
||||
}
|
||||
|
||||
func (e *Executor) getStatusChecker(t *taskfile.Task) (status.Checker, error) {
|
||||
switch t.Method {
|
||||
case "", "timestamp":
|
||||
method := t.Method
|
||||
if method == "" {
|
||||
method = e.Taskfile.Method
|
||||
}
|
||||
switch method {
|
||||
case "timestamp":
|
||||
return &status.Timestamp{
|
||||
Dir: t.Dir,
|
||||
Sources: t.Sources,
|
||||
@ -68,7 +72,7 @@ func (e *Executor) getStatusChecker(t *taskfile.Task) (status.Checker, error) {
|
||||
case "none":
|
||||
return status.None{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf(`task: invalid method "%s"`, t.Method)
|
||||
return nil, fmt.Errorf(`task: invalid method "%s"`, method)
|
||||
}
|
||||
}
|
||||
|
||||
|
8
task.go
8
task.go
@ -169,6 +169,14 @@ func (e *Executor) Setup() error {
|
||||
return fmt.Errorf(`task: output option "%s" not recognized`, e.Taskfile.Output)
|
||||
}
|
||||
|
||||
if e.Taskfile.Method == "" {
|
||||
if v >= 3 {
|
||||
e.Taskfile.Method = "checksum"
|
||||
} else {
|
||||
e.Taskfile.Method = "timestamp"
|
||||
}
|
||||
}
|
||||
|
||||
if v <= 2.1 {
|
||||
err := errors.New(`task: Taskfile option "ignore_error" is only available starting on Taskfile version v2.1`)
|
||||
|
||||
|
@ -630,7 +630,7 @@ func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) {
|
||||
}
|
||||
|
||||
// Ensure that the directory to be created doesn't actually exist.
|
||||
_ = os.Remove(toBeCreated)
|
||||
_ = os.RemoveAll(toBeCreated)
|
||||
if _, err := os.Stat(toBeCreated); err == nil {
|
||||
t.Errorf("Directory should not exist: %v", err)
|
||||
}
|
||||
@ -641,7 +641,7 @@ func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) {
|
||||
assert.Equal(t, expected, got, "Mismatch in the working directory")
|
||||
|
||||
// Clean-up after ourselves only if no error.
|
||||
_ = os.Remove(toBeCreated)
|
||||
_ = os.RemoveAll(toBeCreated)
|
||||
}
|
||||
|
||||
func TestDisplaysErrorOnUnsupportedVersion(t *testing.T) {
|
||||
|
4
testdata/generates/Taskfile.yml
vendored
4
testdata/generates/Taskfile.yml
vendored
@ -8,6 +8,7 @@ tasks:
|
||||
dir: sub
|
||||
cmds:
|
||||
- cat src.txt > '{{.BUILD_DIR}}/abs.txt'
|
||||
method: timestamp
|
||||
sources:
|
||||
- src.txt
|
||||
generates:
|
||||
@ -20,6 +21,7 @@ tasks:
|
||||
dir: sub
|
||||
cmds:
|
||||
- cat src.txt > '../rel.txt'
|
||||
method: timestamp
|
||||
sources:
|
||||
- src.txt
|
||||
generates:
|
||||
@ -30,6 +32,7 @@ tasks:
|
||||
cmds:
|
||||
- mkdir -p sub
|
||||
- echo "hello world" > sub/src.txt
|
||||
method: timestamp
|
||||
status:
|
||||
- test -f sub/src.txt
|
||||
|
||||
@ -38,6 +41,7 @@ tasks:
|
||||
deps: [sub/src.txt]
|
||||
cmds:
|
||||
- cat sub/src.txt > 'my text file.txt'
|
||||
method: timestamp
|
||||
sources:
|
||||
- sub/src.txt
|
||||
generates:
|
||||
|
Loading…
x
Reference in New Issue
Block a user