From 40ac4adc631620aaf2442f9603138c681aa7317a Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Mon, 2 Sep 2024 12:28:23 -0400 Subject: [PATCH] feat: add step input support --- WORKFLOW_SUPPORT.md | 4 ++-- internal/actions/act.go | 5 +++++ internal/actions/act_test.go | 26 ++++++++++++++++++++++++++ internal/runner/runner.go | 4 ++++ internal/workflow/models.go | 1 + 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 internal/actions/act_test.go diff --git a/WORKFLOW_SUPPORT.md b/WORKFLOW_SUPPORT.md index 6e13386..341e455 100644 --- a/WORKFLOW_SUPPORT.md +++ b/WORKFLOW_SUPPORT.md @@ -37,11 +37,11 @@ syntax](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for - [ ] jobs..steps[*].id - [ ] jobs..steps[*].if - [ ] jobs..steps[*].name - - [ ] jobs..steps[*].uses + - [ ] jobs..steps[*].use - [x] jobs..steps[*].run - [x] jobs..steps[*].working-directory - [x] jobs..steps[*].shell - - [ ] jobs..steps[*].with + - [x] jobs..steps[*].with - [x] jobs..steps[*].env - [X] jobs..steps[*].continue-on-error - [ ] jobs..steps[*].timeout-minutes diff --git a/internal/actions/act.go b/internal/actions/act.go index bac66e5..ee4c32d 100644 --- a/internal/actions/act.go +++ b/internal/actions/act.go @@ -2,6 +2,7 @@ package actions import ( + "fmt" "strings" ) @@ -20,3 +21,7 @@ func GetActionKey(url string) string { return strings.Join(parts, "__") } + +func FormatInputEnvKey(inputKey string) string { + return fmt.Sprintf("INPUT_%s", strings.ReplaceAll(strings.ToUpper(inputKey), " ", "_")) +} diff --git a/internal/actions/act_test.go b/internal/actions/act_test.go new file mode 100644 index 0000000..7a6b667 --- /dev/null +++ b/internal/actions/act_test.go @@ -0,0 +1,26 @@ +package actions + +import ( + "testing" +) + +func TestFormatInputEnvKey(t *testing.T) { + cases := []struct { + input string + expected string + }{ + {input: "test", expected: "INPUT_TEST"}, + {input: "test-test", expected: "INPUT_TEST-TEST"}, + {input: "test test", expected: "INPUT_TEST_TEST"}, + } + + for _, testCase := range cases { + t.Run(testCase.input, func(t *testing.T) { + formatted := FormatInputEnvKey(testCase.input) + + if formatted != testCase.expected { + t.Errorf("Expected input env to be formatted as %s, got %s.", testCase.expected, formatted) + } + }) + } +} diff --git a/internal/runner/runner.go b/internal/runner/runner.go index f7fe660..158c2ce 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -165,6 +165,10 @@ func (r *Runner) RunJobInContainer(imageUri string, containerId string, jobConte } stepError = r.RunCommandInContainer(containerId, step.Run, commandOptions) } else if step.Use != "" { + for key, value := range step.With { + stepEnv[actions.FormatInputEnvKey(key)] = value + } + commandOptions := driver.CommandOptions{ Cwd: stepCwd, Env: stepEnv, diff --git a/internal/workflow/models.go b/internal/workflow/models.go index f474ee9..988d845 100644 --- a/internal/workflow/models.go +++ b/internal/workflow/models.go @@ -54,6 +54,7 @@ type Step struct { Env map[string]string `yaml:"env"` Shell string `yaml:"shell"` Use string `yaml:"use"` + With map[string]string `yaml:"with"` } func (s Step) Walk(handler func(node interface{})) {