feat: add step input support
This commit is contained in:
parent
42dfc12243
commit
40ac4adc63
5 changed files with 38 additions and 2 deletions
|
@ -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
|
||||||
|
|
|
@ -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), " ", "_"))
|
||||||
|
}
|
||||||
|
|
26
internal/actions/act_test.go
Normal file
26
internal/actions/act_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,
|
||||||
|
|
|
@ -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{})) {
|
||||||
|
|
Loading…
Reference in a new issue