Skip to content

Commit 50dcc57

Browse files
feat: support yaml env/secrets/inputs file (#1733)
* support yaml env/secrets/inputs file * Update root.go * read the docs again.. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 6d527bf commit 50dcc57

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cmd/root.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/nektos/act/pkg/container"
2525
"github.com/nektos/act/pkg/model"
2626
"github.com/nektos/act/pkg/runner"
27+
"gopkg.in/yaml.v3"
2728
)
2829

2930
// Execute is the entry point to running the CLI
@@ -281,9 +282,26 @@ func parseEnvs(env []string, envs map[string]string) bool {
281282
return false
282283
}
283284

285+
func readYamlFile(file string) (map[string]string, error) {
286+
content, err := os.ReadFile(file)
287+
if err != nil {
288+
return nil, err
289+
}
290+
ret := map[string]string{}
291+
if err = yaml.Unmarshal(content, &ret); err != nil {
292+
return nil, err
293+
}
294+
return ret, nil
295+
}
296+
284297
func readEnvs(path string, envs map[string]string) bool {
285298
if _, err := os.Stat(path); err == nil {
286-
env, err := godotenv.Read(path)
299+
var env map[string]string
300+
if ext := filepath.Ext(path); ext == ".yml" || ext == ".yaml" {
301+
env, err = readYamlFile(path)
302+
} else {
303+
env, err = godotenv.Read(path)
304+
}
287305
if err != nil {
288306
log.Fatalf("Error loading from %s: %v", path, err)
289307
}

0 commit comments

Comments
 (0)