mirror of
https://github.com/drone-plugins/github-actions
synced 2024-11-15 02:56:25 +01:00
Added support for env & secrets
This commit is contained in:
parent
b127585fad
commit
040dd66e56
16
utils/env.go
16
utils/env.go
@ -1,36 +1,34 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateEnvAndSecretFile(envFile, secretFile string, secrets []string) error {
|
func CreateEnvAndSecretFile(envFile, secretFile string, secrets []string) error {
|
||||||
envVars := getEnvVars()
|
envVars := getEnvVars()
|
||||||
|
|
||||||
envBuf := ""
|
actionEnvVars := make(map[string]string)
|
||||||
for key, val := range envVars {
|
for key, val := range envVars {
|
||||||
if !strings.HasPrefix(key, "PLUGIN_") && !Exists(secrets, key) {
|
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 {
|
for _, secretName := range secrets {
|
||||||
if os.Getenv(secretName) != "" {
|
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")
|
return errors.Wrap(err, "failed to write environment variables file")
|
||||||
}
|
}
|
||||||
|
if err := godotenv.Write(secretEnvVars, secretFile); err != nil {
|
||||||
if err := ioutil.WriteFile(secretFile, []byte(secretBuf), 0644); err != nil {
|
|
||||||
return errors.Wrap(err, "failed to write secret variables file")
|
return errors.Wrap(err, "failed to write secret variables file")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user