mirror of
https://github.com/go-task/task.git
synced 2024-12-04 10:24:45 +02:00
remove deprecated set
keyword
This commit is contained in:
parent
c295a1998a
commit
48bf09da21
15
README.md
15
README.md
@ -326,21 +326,6 @@ DEV_MODE: production
|
||||
GIT_COMMIT: {sh: git log -n 1 --format=%h}
|
||||
```
|
||||
|
||||
> NOTE: It's also possible setting a variable globally using `set` attribute
|
||||
in task, but this is deprecated:
|
||||
|
||||
```yml
|
||||
build:
|
||||
deps: [set-message]
|
||||
cmds:
|
||||
- echo "Message: {{.MESSAGE}}"
|
||||
|
||||
set-message:
|
||||
cmds:
|
||||
- echo "This is an important message"
|
||||
set: MESSAGE
|
||||
```
|
||||
|
||||
#### Dynamic variables
|
||||
|
||||
The below syntax (`sh:` prop in a variable) is considered a dynamic variable.
|
||||
|
35
task.go
35
task.go
@ -1,12 +1,10 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
@ -58,7 +56,6 @@ type Task struct {
|
||||
Status []string
|
||||
Dir string
|
||||
Vars Vars
|
||||
Set string
|
||||
Env Vars
|
||||
Silent bool
|
||||
Method string
|
||||
@ -123,14 +120,6 @@ func (e *Executor) RunTask(ctx context.Context, call Call) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// FIXME: doing again, since a var may have been overridden using the
|
||||
// `set:` attribute of a dependency. Remove this when `set` (that is
|
||||
// deprecated) be removed.
|
||||
t, err = e.CompiledTask(call)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !e.Force {
|
||||
upToDate, err := t.isUpToDate(ctx)
|
||||
if err != nil {
|
||||
@ -174,29 +163,19 @@ func (e *Executor) runCommand(ctx context.Context, t *Task, call Call, i int) er
|
||||
return e.RunTask(ctx, Call{Task: cmd.Task, Vars: cmd.Vars})
|
||||
}
|
||||
|
||||
opts := &execext.RunCommandOptions{
|
||||
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) {
|
||||
e.println(cmd.Cmd)
|
||||
}
|
||||
|
||||
return execext.RunCommand(&execext.RunCommandOptions{
|
||||
Context: ctx,
|
||||
Command: cmd.Cmd,
|
||||
Dir: t.Dir,
|
||||
Env: t.getEnviron(),
|
||||
Stdin: e.Stdin,
|
||||
Stdout: e.Stdout,
|
||||
Stderr: e.Stderr,
|
||||
}
|
||||
|
||||
if e.Verbose || (!cmd.Silent && !t.Silent && !e.Silent) {
|
||||
e.println(cmd.Cmd)
|
||||
}
|
||||
if t.Set != "" {
|
||||
var stdout bytes.Buffer
|
||||
opts.Stdout = &stdout
|
||||
if err := execext.RunCommand(opts); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Setenv(t.Set, strings.TrimSpace(stdout.String()))
|
||||
}
|
||||
|
||||
opts.Stdout = e.Stdout
|
||||
return execext.RunCommand(opts)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *Task) getEnviron() []string {
|
||||
|
28
task_test.go
28
task_test.go
@ -94,7 +94,6 @@ func TestVars(t *testing.T) {
|
||||
"shtmpl2_foo.txt": "<no value>",
|
||||
"shtmpl2_foo2.txt": "foo2",
|
||||
"nestedtmpl2_foo2.txt": "{{.FOO2}}",
|
||||
"equal.txt": "foo=bar",
|
||||
"override.txt": "bar",
|
||||
},
|
||||
}
|
||||
@ -199,33 +198,6 @@ func TestDeps(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskCall(t *testing.T) {
|
||||
const dir = "testdata/task_call"
|
||||
|
||||
files := []string{
|
||||
"foo.txt",
|
||||
"bar.txt",
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
_ = os.Remove(filepath.Join(dir, f))
|
||||
}
|
||||
|
||||
e := &task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: ioutil.Discard,
|
||||
Stderr: ioutil.Discard,
|
||||
}
|
||||
assert.NoError(t, e.ReadTaskfile())
|
||||
assert.NoError(t, e.Run(task.Call{Task: "default"}))
|
||||
|
||||
for _, f := range files {
|
||||
if _, err := os.Stat(filepath.Join(dir, f)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatus(t *testing.T) {
|
||||
const dir = "testdata/status"
|
||||
var file = filepath.Join(dir, "foo.txt")
|
||||
|
1
testdata/task_call/.gitignore
vendored
1
testdata/task_call/.gitignore
vendored
@ -1 +0,0 @@
|
||||
*.txt
|
20
testdata/task_call/Taskfile.yml
vendored
20
testdata/task_call/Taskfile.yml
vendored
@ -1,20 +0,0 @@
|
||||
default:
|
||||
cmds:
|
||||
- ^set-foo
|
||||
- ^print
|
||||
- ^set-bar
|
||||
- ^print
|
||||
|
||||
print:
|
||||
cmds:
|
||||
- echo text > {{.FILE}}
|
||||
|
||||
set-foo:
|
||||
set: FILE
|
||||
cmds:
|
||||
- echo foo.txt
|
||||
|
||||
set-bar:
|
||||
set: FILE
|
||||
cmds:
|
||||
- echo bar.txt
|
7
testdata/vars/Taskfile.yml
vendored
7
testdata/vars/Taskfile.yml
vendored
@ -2,7 +2,6 @@ default:
|
||||
deps: [hello]
|
||||
|
||||
hello:
|
||||
deps: [set-equal]
|
||||
cmds:
|
||||
- echo {{.FOO}} > foo.txt
|
||||
- echo {{.BAR}} > bar.txt
|
||||
@ -25,7 +24,6 @@ hello:
|
||||
- echo '{{.SHTMPL2_FOO}}' > shtmpl2_foo.txt
|
||||
- echo '{{.SHTMPL2_FOO2}}' > shtmpl2_foo2.txt
|
||||
- echo '{{.NESTEDTMPL2_FOO2}}' > nestedtmpl2_foo2.txt
|
||||
- echo {{.EQUAL}} > equal.txt
|
||||
- echo {{.OVERRIDE}} > override.txt
|
||||
vars:
|
||||
FOO: foo
|
||||
@ -44,11 +42,6 @@ hello:
|
||||
NESTEDTMPL_FOO2: "{{.TMPL2_FOO2}}"
|
||||
OVERRIDE: "bar"
|
||||
|
||||
set-equal:
|
||||
set: EQUAL
|
||||
cmds:
|
||||
- echo foo=bar
|
||||
|
||||
invalid-var-tmpl:
|
||||
vars:
|
||||
CHARS: "abcd"
|
||||
|
@ -217,7 +217,6 @@ func (e *Executor) CompiledTask(call Call) (*Task, error) {
|
||||
Status: r.replaceSlice(origTask.Status),
|
||||
Dir: r.replace(origTask.Dir),
|
||||
Vars: nil,
|
||||
Set: r.replace(origTask.Set),
|
||||
Env: r.replaceVars(origTask.Env),
|
||||
Silent: origTask.Silent,
|
||||
Method: r.replace(origTask.Method),
|
||||
|
Loading…
Reference in New Issue
Block a user