1
0
mirror of https://github.com/go-task/task.git synced 2025-01-08 04:04:08 +02:00

fix: task level vars are not ignored in requires (#1960)

Co-authored-by: MOKEKO <Anthurium.1605@gmail.com>
This commit is contained in:
Valentin Maerten 2024-12-30 19:11:27 +01:00 committed by GitHub
parent 8ce9bdc8c7
commit da40aabcc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View File

@ -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",

View File

@ -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:

View File

@ -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,