mirror of
https://github.com/go-task/task.git
synced 2025-06-08 23:56:21 +02:00
Merge branch 'master'
Conflicts: README.md task.go
This commit is contained in:
commit
ef75d5061d
12
README.md
12
README.md
@ -42,6 +42,18 @@ task assets build
|
|||||||
If Bash is available (Linux and Windows while on Git Bash), the commands will
|
If Bash is available (Linux and Windows while on Git Bash), the commands will
|
||||||
run in Bash, otherwise will fallback to `cmd` (on Windows).
|
run in Bash, otherwise will fallback to `cmd` (on Windows).
|
||||||
|
|
||||||
|
|
||||||
|
### Environment
|
||||||
|
You can specify environment variables that are added when running a command:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
build:
|
||||||
|
cmds:
|
||||||
|
- echo $hallo
|
||||||
|
env:
|
||||||
|
hallo: welt
|
||||||
|
```
|
||||||
|
|
||||||
### OS specific task support
|
### OS specific task support
|
||||||
|
|
||||||
If you add a `Taskfile_{{GOOS}}` you can override or amend your taskfile based on the op;erating system.
|
If you add a `Taskfile_{{GOOS}}` you can override or amend your taskfile based on the op;erating system.
|
||||||
|
21
task.go
21
task.go
@ -1,6 +1,7 @@
|
|||||||
package task
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -44,6 +45,7 @@ type Task struct {
|
|||||||
Dir string
|
Dir string
|
||||||
Vars map[string]string
|
Vars map[string]string
|
||||||
Set string
|
Set string
|
||||||
|
Env map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs Task
|
// Run runs Task
|
||||||
@ -101,7 +103,7 @@ func RunTask(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := range t.Cmds {
|
for i := range t.Cmds {
|
||||||
if err = t.runCommand(i); err != nil {
|
if err = t.runCommand(i, t.Env); err != nil {
|
||||||
return &taskRunError{name, err}
|
return &taskRunError{name, err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +128,7 @@ func (t *Task) isUpToDate() bool {
|
|||||||
return generatesMinTime.After(sourcesMaxTime)
|
return generatesMinTime.After(sourcesMaxTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) runCommand(i int) error {
|
func (t *Task) runCommand(i int, envVariables map[string]string) error {
|
||||||
vars, err := t.handleVariables()
|
vars, err := t.handleVariables()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -148,6 +150,21 @@ func (t *Task) runCommand(i int) error {
|
|||||||
if dir != "" {
|
if dir != "" {
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
}
|
}
|
||||||
|
if nil != envVariables {
|
||||||
|
env := os.Environ()
|
||||||
|
for key, value := range envVariables {
|
||||||
|
replacedValue, err := ReplaceVariables(value, vars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
replacedKey, err := ReplaceVariables(key, vars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
env = append(env, fmt.Sprintf("%s=%s", replacedKey, replacedValue))
|
||||||
|
}
|
||||||
|
cmd.Env = env
|
||||||
|
}
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
if t.Set != "" {
|
if t.Set != "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user