From 0ad6e5b04411ca53ba5e1c0edfcb6f702688ced7 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 2 Aug 2024 19:40:06 -0400 Subject: [PATCH] refactor: rename Runner.Execute > Runner.RunWorkflow for consistency --- internal/commands/execute_workflow.go | 2 +- internal/runner/runner.go | 38 +++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/commands/execute_workflow.go b/internal/commands/execute_workflow.go index ae15d6d..3135b4c 100644 --- a/internal/commands/execute_workflow.go +++ b/internal/commands/execute_workflow.go @@ -36,7 +36,7 @@ func ExecuteWorkflow(configuration Configuration, workflowFile string) error { return errors.New("Jobs encountered errors.") } - taskResult := runnerInstance.Execute(*workflow) + taskResult := runnerInstance.RunWorkflow(*workflow) if !taskResult.HasError() { return nil diff --git a/internal/runner/runner.go b/internal/runner/runner.go index 41f48b9..95a4a57 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -83,7 +83,7 @@ func (r *Runner) GetTask(taskId string) *Task { // This is the high-level call that will set up the container // that the jobs will be executed in, run the jobs's steps and // tear down the container once no longer useful. -func (r *Runner) Execute(workflow workflow.Workflow) Task { +func (r *Runner) RunWorkflow(workflow workflow.Workflow) Task { log.Printf("Executing workflow: %s", workflow.SourcePath) task := r.GetTask(r.AddTask()) @@ -114,6 +114,24 @@ func (r *Runner) Execute(workflow workflow.Workflow) Task { return *task } +// Executes a command within the given container. +// +// If the command raises an error while in the container or fails to run +// the command at all, an error is returned, otherwise nil. +func (r *Runner) RunCommandInContainer(containerId string, command string) error { + result := r.Driver.Exec(containerId, command) + + if result.Error != nil { + return result.Error + } + + if result.ExitCode != 0 { + return errors.New(fmt.Sprintf("Command returned a non-zero exit code (%d).", result.ExitCode)) + } + + return nil +} + // Executes a job within a container. // // The container is started before the job steps are run and cleaned up after. @@ -136,21 +154,3 @@ func (r *Runner) RunJobInContainer(imageUri string, containerId string, job work return nil } - -// Executes a command within the given container. -// -// If the command raises an error while in the container or fails to run -// the command at all, an error is returned, otherwise nil. -func (r *Runner) RunCommandInContainer(containerId string, command string) error { - result := r.Driver.Exec(containerId, command) - - if result.Error != nil { - return result.Error - } - - if result.ExitCode != 0 { - return errors.New(fmt.Sprintf("Command returned a non-zero exit code (%d).", result.ExitCode)) - } - - return nil -}