mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +02:00 
			
		
		
		
	v3: Allow interpolation on "includes"
The idea is to allow manual inclusion of a OS-dependant Taskfile, since it's not automatically included anymore.
This commit is contained in:
		| @@ -8,6 +8,7 @@ import ( | ||||
| 	"runtime" | ||||
|  | ||||
| 	"github.com/go-task/task/v2/internal/taskfile" | ||||
| 	"github.com/go-task/task/v2/internal/templater" | ||||
|  | ||||
| 	"gopkg.in/yaml.v3" | ||||
| ) | ||||
| @@ -28,7 +29,24 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	v, err := t.ParsedVersion() | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	for namespace, includedTask := range t.Includes { | ||||
| 		if v >= 3.0 { | ||||
| 			tr := templater.Templater{Vars: &taskfile.Vars{}, RemoveNoValue: true} | ||||
| 			includedTask = taskfile.IncludedTaskfile{ | ||||
| 				Taskfile:       tr.Replace(includedTask.Taskfile), | ||||
| 				Dir:            tr.Replace(includedTask.Dir), | ||||
| 				AdvancedImport: includedTask.AdvancedImport, | ||||
| 			} | ||||
| 			if err := tr.Err(); err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if filepath.IsAbs(includedTask.Taskfile) { | ||||
| 			path = includedTask.Taskfile | ||||
| 		} else { | ||||
| @@ -63,10 +81,6 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	v, err := t.ParsedVersion() | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if v < 3.0 { | ||||
| 		path = filepath.Join(dir, fmt.Sprintf("Taskfile_%s.yml", runtime.GOOS)) | ||||
| 		if _, err = os.Stat(path); err == nil { | ||||
|   | ||||
| @@ -560,6 +560,7 @@ func TestIncludes(t *testing.T) { | ||||
| 			"included_taskfile_without_dir.txt":         "included_taskfile_without_dir", | ||||
| 			"./module2/included_directory_with_dir.txt": "included_directory_with_dir", | ||||
| 			"./module2/included_taskfile_with_dir.txt":  "included_taskfile_with_dir", | ||||
| 			"os_include.txt":                            "os", | ||||
| 		}, | ||||
| 	} | ||||
| 	tt.Run(t) | ||||
|   | ||||
							
								
								
									
										2
									
								
								testdata/includes/Taskfile.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								testdata/includes/Taskfile.yml
									
									
									
									
										vendored
									
									
								
							| @@ -13,6 +13,7 @@ includes: | ||||
|   included_taskfile_with_dir: | ||||
|     taskfile:  ./module2/Taskfile.yml | ||||
|     dir:  ./module2 | ||||
|   included_os: ./Taskfile_{{OS}}.yml | ||||
|  | ||||
| tasks: | ||||
|   default: | ||||
| @@ -24,6 +25,7 @@ tasks: | ||||
|       - task: included_taskfile_without_dir:gen_dir | ||||
|       - task: included_with_dir:gen_file | ||||
|       - task: included_taskfile_with_dir:gen_dir | ||||
|       - task: included_os:gen | ||||
|  | ||||
|   gen: | ||||
|     cmds: | ||||
|   | ||||
							
								
								
									
										4
									
								
								testdata/includes/Taskfile_darwin.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								testdata/includes/Taskfile_darwin.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| version: '3' | ||||
|  | ||||
| tasks: | ||||
|   gen: echo 'os' > os_include.txt | ||||
							
								
								
									
										4
									
								
								testdata/includes/Taskfile_linux.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								testdata/includes/Taskfile_linux.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| version: '3' | ||||
|  | ||||
| tasks: | ||||
|   gen: echo 'os' > os_include.txt | ||||
							
								
								
									
										4
									
								
								testdata/includes/Taskfile_windows.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								testdata/includes/Taskfile_windows.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| version: '3' | ||||
|  | ||||
| tasks: | ||||
|   gen: echo 'os' > os_include.txt | ||||
		Reference in New Issue
	
	Block a user