Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ type Compiler struct {

Logger *logger.Logger

dynamicCache map[string]string
dynamicCache map[dynamicCacheKey]string
muDynamicCache sync.Mutex
}

type dynamicCacheKey struct {
dir string
sh string
}

func (c *Compiler) GetTaskfileVariables() (*ast.Vars, error) {
return c.getVariables(nil, nil, true)
}
Expand Down Expand Up @@ -156,9 +161,12 @@ func (c *Compiler) HandleDynamicVar(v ast.Var, dir string, e []string) (string,
}

if c.dynamicCache == nil {
c.dynamicCache = make(map[string]string, 30)
c.dynamicCache = make(map[dynamicCacheKey]string, 30)
}
if result, ok := c.dynamicCache[*v.Sh]; ok {

key := dynamicCacheKey{dir, *v.Sh}

if result, ok := c.dynamicCache[key]; ok {
return result, nil
}

Expand All @@ -184,7 +192,7 @@ func (c *Compiler) HandleDynamicVar(v ast.Var, dir string, e []string) (string,
result := strings.TrimSuffix(stdout.String(), "\r\n")
result = strings.TrimSuffix(result, "\n")

c.dynamicCache[*v.Sh] = result
c.dynamicCache[key] = result
// Never print the resolved value of a secret variable, even in verbose mode
logResult := result
if v.Secret {
Expand Down
2 changes: 2 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ func TestIncludes(t *testing.T) {
"./module2/included_directory_with_dir.txt": "included_directory_with_dir",
"./module2/included_taskfile_with_dir.txt": "included_taskfile_with_dir",
"os_include.txt": "os",
"result.txt": "includes",
"common/result.txt": "common",
},
}
t.Run("", func(t *testing.T) {
Expand Down
20 changes: 14 additions & 6 deletions testdata/includes/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ includes:
included: ./included
included_taskfile: ./Taskfile2.yml
included_without_dir:
taskfile: ./module1
taskfile: ./module1
included_taskfile_without_dir:
taskfile: ./module1/Taskfile.yml
taskfile: ./module1/Taskfile.yml
included_with_dir:
taskfile: ./module2
dir: ./module2
taskfile: ./module2
dir: ./module2
included_taskfile_with_dir:
taskfile: ./module2/Taskfile.yml
dir: ./module2
taskfile: ./module2/Taskfile.yml
dir: ./module2
included_os: ./Taskfile_{{OS}}.yml
include_common_task1:
taskfile: ./common/Taskfile.yml
dir: .
include_common_task2:
taskfile: ./common/Taskfile.yml
dir: ./common

tasks:
default:
Expand All @@ -26,6 +32,8 @@ tasks:
- task: included_with_dir:gen_file
- task: included_taskfile_with_dir:gen_dir
- task: included_os:gen
- task: include_common_task1:show
- task: include_common_task2:show

gen:
cmds:
Expand Down
10 changes: 10 additions & 0 deletions testdata/includes/common/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

tasks:
show:
vars:
CURRENT_DIR:
sh: basename "$(pwd)"

cmds:
- 'echo "{{.CURRENT_DIR}}" > result.txt'
Loading