Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: evaluate requires before compiled task #1962

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func (e *Executor) RunTask(ctx context.Context, call *ast.Call) error {
return nil
}

if err := e.areTaskRequiredVarsSet(t, call); err != nil {
return err
}

t, err = e.CompiledTask(call)
if err != nil {
return err
Expand All @@ -202,10 +206,6 @@ func (e *Executor) RunTask(ctx context.Context, call *ast.Call) error {
return err
}

if err := e.areTaskRequiredVarsSet(t, call); err != nil {
return err
}

preCondMet, err := e.areTaskPreconditionsMet(ctx, t)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func TestRequires(t *testing.T) {
vars.Set("foo", ast.Var{Value: "one"})
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "validation-var", Vars: vars}))
buff.Reset()

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()
}

func TestSpecialVars(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions testdata/requires/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ tasks:
vars:
- name: foo
enum: ['one', 'two']


require-before-compile:
requires:
vars: [ MY_VAR ]
cmd: |
{{range .MY_VAR | splitList " " }}
echo {{.}}
{{end}}
Loading