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

feat: allow direct calling of tasks with inputs when required inputs have default values #146

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func Run(tasksFile types.TasksFile, taskName string, setVariables map[string]str
return err
}

// can't call a task directly from the CLI if it has inputs
if task.Inputs != nil {
return fmt.Errorf("task '%s' contains 'inputs' and cannot be called directly by the CLI", taskName)
// can't call a task directly from the CLI if it has inputs that are required without a default
if err := validateActionableTaskCall(task.Name, task.Inputs, nil); err != nil {
return err
}

if err = runner.checkForTaskLoops(task, runner.TasksFile, setVariables); err != nil {
Expand Down
16 changes: 16 additions & 0 deletions src/test/e2e/runner_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ func TestRunnerInputs(t *testing.T) {
require.NotContains(t, stdErr, "{{")
})

t.Run("test that direct calling of task with default values for required inputs work", func(t *testing.T) {
t.Parallel()

stdOut, stdErr, err := e2e.Maru("run", "has-default-and-required", "--file", "src/test/tasks/inputs/tasks-with-inputs.yaml")
require.NoError(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "Completed \"echo $INPUT_HAS_DEFAULT_AND_REQUIRED; ; \"")
})

t.Run("test that direct calling of task without default values for required inputs fails", func(t *testing.T) {
t.Parallel()

stdOut, stdErr, err := e2e.Maru("run", "no-default-and-required", "--file", "src/test/tasks/inputs/tasks-with-inputs.yaml")
require.Error(t, err, stdOut, stdErr)
require.Contains(t, stdErr, "Failed to run action: task no-default-and-required is missing required inputs:")
})

t.Run("test that inputs that aren't required with no default don't error", func(t *testing.T) {
t.Parallel()

Expand Down
Loading