From da40aabcc7a351dfb4b0d198227a5d6eec47331e Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Mon, 30 Dec 2024 19:11:27 +0100 Subject: [PATCH] fix: task level vars are not ignored in requires (#1960) Co-authored-by: MOKEKO --- task_test.go | 4 ++++ testdata/requires/Taskfile.yml | 8 ++++++++ variables.go | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/task_test.go b/task_test.go index 093f0fa7..a0f1e7bf 100644 --- a/task_test.go +++ b/task_test.go @@ -203,6 +203,9 @@ func TestRequires(t *testing.T) { require.NoError(t, e.Setup()) require.ErrorContains(t, e.Run(context.Background(), &ast.Call{Task: "require-before-compile"}), "task: Task \"require-before-compile\" cancelled because it is missing required variables: MY_VAR") buff.Reset() + + require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "var-defined-in-task"})) + buff.Reset() } func TestSpecialVars(t *testing.T) { @@ -1671,6 +1674,7 @@ func TestIncludesInterpolation(t *testing.T) { // nolint:paralleltest // cannot func TestIncludesWithExclude(t *testing.T) { t.Parallel() + var buff bytes.Buffer e := task.Executor{ Dir: "testdata/includes_with_excludes", diff --git a/testdata/requires/Taskfile.yml b/testdata/requires/Taskfile.yml index 83d4110f..21983878 100644 --- a/testdata/requires/Taskfile.yml +++ b/testdata/requires/Taskfile.yml @@ -10,6 +10,14 @@ tasks: - foo cmd: echo "{{.foo}}" + var-defined-in-task: + vars: + FOO: bar + requires: + vars: + - FOO + cmd: echo "{{.FOO}}" + validation-var: requires: diff --git a/variables.go b/variables.go index 5258ef23..108834fa 100644 --- a/variables.go +++ b/variables.go @@ -56,7 +56,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task, Dir: templater.Replace(origTask.Dir, cache), Set: origTask.Set, Shopt: origTask.Shopt, - Vars: nil, + Vars: vars, Env: nil, Dotenv: templater.Replace(origTask.Dotenv, cache), Silent: origTask.Silent,