summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorChristopherHX <christopher.homberger@web.de>2023-04-18 15:35:31 +0200
committerGitHub <noreply@github.com>2023-04-18 15:35:31 +0200
commit50dcc57e4babe816692d342307183801ddd78356 (patch)
tree2fd2efa85196d722f20703c617e47c0efe0f03af /cmd
parentbuild(deps): bump codecov/codecov-action from 3.1.1 to 3.1.2 (#1735) (diff)
downloadforgejo-act-50dcc57e4babe816692d342307183801ddd78356.tar.xz
forgejo-act-50dcc57e4babe816692d342307183801ddd78356.zip
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>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/root.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/cmd/root.go b/cmd/root.go
index fc3e43e..02afb50 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -24,6 +24,7 @@ import (
"github.com/nektos/act/pkg/container"
"github.com/nektos/act/pkg/model"
"github.com/nektos/act/pkg/runner"
+ "gopkg.in/yaml.v3"
)
// Execute is the entry point to running the CLI
@@ -281,9 +282,26 @@ func parseEnvs(env []string, envs map[string]string) bool {
return false
}
+func readYamlFile(file string) (map[string]string, error) {
+ content, err := os.ReadFile(file)
+ if err != nil {
+ return nil, err
+ }
+ ret := map[string]string{}
+ if err = yaml.Unmarshal(content, &ret); err != nil {
+ return nil, err
+ }
+ return ret, nil
+}
+
func readEnvs(path string, envs map[string]string) bool {
if _, err := os.Stat(path); err == nil {
- env, err := godotenv.Read(path)
+ var env map[string]string
+ if ext := filepath.Ext(path); ext == ".yml" || ext == ".yaml" {
+ env, err = readYamlFile(path)
+ } else {
+ env, err = godotenv.Read(path)
+ }
if err != nil {
log.Fatalf("Error loading from %s: %v", path, err)
}