feat: add step input support

This commit is contained in:
Marc 2024-09-02 12:28:23 -04:00
parent 42dfc12243
commit 40ac4adc63
Signed by: marc
GPG key ID: 048E042F22B5DC79
5 changed files with 38 additions and 2 deletions

View file

@ -37,11 +37,11 @@ syntax](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for
- [ ] jobs.<job_id>.steps[*].id - [ ] jobs.<job_id>.steps[*].id
- [ ] jobs.<job_id>.steps[*].if - [ ] jobs.<job_id>.steps[*].if
- [ ] jobs.<job_id>.steps[*].name - [ ] jobs.<job_id>.steps[*].name
- [ ] jobs.<job_id>.steps[*].uses - [ ] jobs.<job_id>.steps[*].use
- [x] jobs.<job_id>.steps[*].run - [x] jobs.<job_id>.steps[*].run
- [x] jobs.<job_id>.steps[*].working-directory - [x] jobs.<job_id>.steps[*].working-directory
- [x] jobs.<job_id>.steps[*].shell - [x] jobs.<job_id>.steps[*].shell
- [ ] jobs.<job_id>.steps[*].with - [x] jobs.<job_id>.steps[*].with
- [x] jobs.<job_id>.steps[*].env - [x] jobs.<job_id>.steps[*].env
- [X] jobs.<job_id>.steps[*].continue-on-error - [X] jobs.<job_id>.steps[*].continue-on-error
- [ ] jobs.<job_id>.steps[*].timeout-minutes - [ ] jobs.<job_id>.steps[*].timeout-minutes

View file

@ -2,6 +2,7 @@
package actions package actions
import ( import (
"fmt"
"strings" "strings"
) )
@ -20,3 +21,7 @@ func GetActionKey(url string) string {
return strings.Join(parts, "__") return strings.Join(parts, "__")
} }
func FormatInputEnvKey(inputKey string) string {
return fmt.Sprintf("INPUT_%s", strings.ReplaceAll(strings.ToUpper(inputKey), " ", "_"))
}

View file

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

View file

@ -165,6 +165,10 @@ func (r *Runner) RunJobInContainer(imageUri string, containerId string, jobConte
} }
stepError = r.RunCommandInContainer(containerId, step.Run, commandOptions) stepError = r.RunCommandInContainer(containerId, step.Run, commandOptions)
} else if step.Use != "" { } else if step.Use != "" {
for key, value := range step.With {
stepEnv[actions.FormatInputEnvKey(key)] = value
}
commandOptions := driver.CommandOptions{ commandOptions := driver.CommandOptions{
Cwd: stepCwd, Cwd: stepCwd,
Env: stepEnv, Env: stepEnv,

View file

@ -54,6 +54,7 @@ type Step struct {
Env map[string]string `yaml:"env"` Env map[string]string `yaml:"env"`
Shell string `yaml:"shell"` Shell string `yaml:"shell"`
Use string `yaml:"use"` Use string `yaml:"use"`
With map[string]string `yaml:"with"`
} }
func (s Step) Walk(handler func(node interface{})) { func (s Step) Walk(handler func(node interface{})) {