mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +02:00 
			
		
		
		
	| @@ -7,6 +7,7 @@ type Taskfile struct { | ||||
| 	Output     string | ||||
| 	Includes   map[string]string | ||||
| 	Vars       Vars | ||||
| 	Env        Vars | ||||
| 	Tasks      Tasks | ||||
| } | ||||
|  | ||||
| @@ -23,6 +24,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||||
| 		Output     string | ||||
| 		Includes   map[string]string | ||||
| 		Vars       Vars | ||||
| 		Env        Vars | ||||
| 		Tasks      Tasks | ||||
| 	} | ||||
| 	if err := unmarshal(&taskfile); err != nil { | ||||
| @@ -33,6 +35,7 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||||
| 	tf.Output = taskfile.Output | ||||
| 	tf.Includes = taskfile.Includes | ||||
| 	tf.Vars = taskfile.Vars | ||||
| 	tf.Env = taskfile.Env | ||||
| 	tf.Tasks = taskfile.Tasks | ||||
| 	if tf.Expansions <= 0 { | ||||
| 		tf.Expansions = 2 | ||||
|   | ||||
							
								
								
									
										6
									
								
								task.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								task.go
									
									
									
									
									
								
							| @@ -268,9 +268,9 @@ func getEnviron(t *taskfile.Task) []string { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	envs := os.Environ() | ||||
| 	environ := os.Environ() | ||||
| 	for k, v := range t.Env.ToStringMap() { | ||||
| 		envs = append(envs, fmt.Sprintf("%s=%s", k, v)) | ||||
| 		environ = append(environ, fmt.Sprintf("%s=%s", k, v)) | ||||
| 	} | ||||
| 	return envs | ||||
| 	return environ | ||||
| } | ||||
|   | ||||
| @@ -61,7 +61,8 @@ func TestEnv(t *testing.T) { | ||||
| 		Target:    "default", | ||||
| 		TrimSpace: false, | ||||
| 		Files: map[string]string{ | ||||
| 			"env.txt": "GOOS='linux' GOARCH='amd64' CGO_ENABLED='0'\n", | ||||
| 			"local.txt":  "GOOS='linux' GOARCH='amd64' CGO_ENABLED='0'\n", | ||||
| 			"global.txt": "FOO='foo' BAR='overriden' BAZ='baz'\n", | ||||
| 		}, | ||||
| 	} | ||||
| 	tt.Run(t) | ||||
|   | ||||
							
								
								
									
										2
									
								
								testdata/env/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								testdata/env/.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1 +1 @@ | ||||
| env.txt | ||||
| *.txt | ||||
|   | ||||
							
								
								
									
										43
									
								
								testdata/env/Taskfile.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										43
									
								
								testdata/env/Taskfile.yml
									
									
									
									
										vendored
									
									
								
							| @@ -1,10 +1,33 @@ | ||||
| default: | ||||
|   vars: | ||||
|     AMD64: amd64 | ||||
|   env: | ||||
|     GOOS: linux | ||||
|     GOARCH: "{{.AMD64}}" | ||||
|     CGO_ENABLED: | ||||
|       sh: echo '0' | ||||
|   cmds: | ||||
|     - echo "GOOS='$GOOS' GOARCH='$GOARCH' CGO_ENABLED='$CGO_ENABLED'" > env.txt | ||||
| version: '2' | ||||
|  | ||||
| vars: | ||||
|   BAZ: | ||||
|     sh: echo baz | ||||
|  | ||||
| env: | ||||
|   FOO: foo | ||||
|   BAR: bar | ||||
|   BAZ: "{{.BAZ}}" | ||||
|  | ||||
| tasks: | ||||
|   default: | ||||
|     cmds: | ||||
|       - task: local | ||||
|       - task: global | ||||
|  | ||||
|   local: | ||||
|     vars: | ||||
|       AMD64: amd64 | ||||
|     env: | ||||
|       GOOS: linux | ||||
|       GOARCH: "{{.AMD64}}" | ||||
|       CGO_ENABLED: | ||||
|         sh: echo '0' | ||||
|     cmds: | ||||
|       - echo "GOOS='$GOOS' GOARCH='$GOARCH' CGO_ENABLED='$CGO_ENABLED'" > local.txt | ||||
|  | ||||
|   global: | ||||
|     env: | ||||
|       BAR: overriden | ||||
|     cmds: | ||||
|       - echo "FOO='$FOO' BAR='$BAR' BAZ='$BAZ'" > global.txt | ||||
|   | ||||
							
								
								
									
										10
									
								
								variables.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								variables.go
									
									
									
									
									
								
							| @@ -30,7 +30,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) { | ||||
| 		Status:      r.ReplaceSlice(origTask.Status), | ||||
| 		Dir:         r.Replace(origTask.Dir), | ||||
| 		Vars:        nil, | ||||
| 		Env:         r.ReplaceVars(origTask.Env), | ||||
| 		Env:         nil, | ||||
| 		Silent:      origTask.Silent, | ||||
| 		Method:      r.Replace(origTask.Method), | ||||
| 		Prefix:      r.Replace(origTask.Prefix), | ||||
| @@ -46,6 +46,14 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) { | ||||
| 	if new.Prefix == "" { | ||||
| 		new.Prefix = new.Task | ||||
| 	} | ||||
|  | ||||
| 	new.Env = make(taskfile.Vars, len(e.Taskfile.Env)+len(origTask.Env)) | ||||
| 	for k, v := range r.ReplaceVars(e.Taskfile.Env) { | ||||
| 		new.Env[k] = v | ||||
| 	} | ||||
| 	for k, v := range r.ReplaceVars(origTask.Env) { | ||||
| 		new.Env[k] = v | ||||
| 	} | ||||
| 	for k, v := range new.Env { | ||||
| 		static, err := e.Compiler.HandleDynamicVar(v) | ||||
| 		if err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user