From 040dd66e563b7b63866a67b0783b2c46dbbdf69c Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Thu, 7 Oct 2021 18:04:00 +0530 Subject: [PATCH] Added support for env & secrets --- utils/env.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/utils/env.go b/utils/env.go index 38c2369..7a6a89d 100644 --- a/utils/env.go +++ b/utils/env.go @@ -1,36 +1,34 @@ package utils import ( - "fmt" - "io/ioutil" "os" "strings" + "github.com/joho/godotenv" "github.com/pkg/errors" ) func CreateEnvAndSecretFile(envFile, secretFile string, secrets []string) error { envVars := getEnvVars() - envBuf := "" + actionEnvVars := make(map[string]string) for key, val := range envVars { if !strings.HasPrefix(key, "PLUGIN_") && !Exists(secrets, key) { - envBuf += fmt.Sprintf("%s=%s\n", key, val) + actionEnvVars[key] = val } } - secretBuf := "" + secretEnvVars := make(map[string]string) for _, secretName := range secrets { if os.Getenv(secretName) != "" { - secretBuf += fmt.Sprintf("%s=%s\n", secretName, os.Getenv(secretName)) + secretEnvVars[secretName] = os.Getenv(secretName) } } - if err := ioutil.WriteFile(envFile, []byte(envBuf), 0644); err != nil { + if err := godotenv.Write(actionEnvVars, envFile); err != nil { return errors.Wrap(err, "failed to write environment variables file") } - - if err := ioutil.WriteFile(secretFile, []byte(secretBuf), 0644); err != nil { + if err := godotenv.Write(secretEnvVars, secretFile); err != nil { return errors.Wrap(err, "failed to write secret variables file") } return nil