Skip to content

Commit

Permalink
feat: CI-9438: passing github action with as individual vars (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
devkimittal authored Sep 12, 2023
1 parent b8020a6 commit 9408270
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
21 changes: 18 additions & 3 deletions plugin/github/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,30 @@ func parseOwner(s string) (owner string) {
}

func getWith(envVars map[string]string) (map[string]string, error) {
if val, ok := envVars["PLUGIN_WITH"]; ok {
PLUGIN_WITH := "PLUGIN_WITH"
PLUGIN_WITH_PREFIX := "PLUGIN_WITH_"

_, exists := envVars[PLUGIN_WITH]

// TODO: Remove this once corresponding CI Manager changes are released on prod envs
if exists {
// PLUGIN_WITH is being set in older flow
val := envVars[PLUGIN_WITH]
with, err := strToMap(val)
if err != nil {
return nil, errors.Wrap(err, "with attribute is not of map type with key & value as string")
}

return with, nil
} else {
m := make(map[string]string)
for key := range envVars {
if strings.HasPrefix(key, PLUGIN_WITH_PREFIX) {
k := strings.TrimPrefix(key, PLUGIN_WITH_PREFIX)
m[k] = envVars[key]
}
}
return m, nil
}
return nil, nil
}

func getEnv(envVars map[string]string) map[string]string {
Expand Down
6 changes: 3 additions & 3 deletions plugin/github/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func getWorkflowEvent() string {
func prePostStep(name, envFile string) step {
var cmd string
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
cmd = fmt.Sprintf("python3 -c 'import os; import base64; [print(k+\"=\"+str(base64.b64encode(bytes(v, \"utf-8\")), \"utf-8\")) for k, v in os.environ.items()]' > %s", envFile)
cmd = fmt.Sprintf("python3 -c 'import os; import base64; [print(k+\"=\"+str(base64.b64encode(bytes(v, \"utf-8\")), \"utf-8\")) for k, v in os.environ.items() if not k.startswith(\"PLUGIN_WITH_\")]' > %s", envFile)
} else if runtime.GOOS == "windows" {
script, err := dotenvScript(envFile)
if err != nil {
Expand All @@ -108,7 +108,7 @@ func prePostStep(name, envFile string) step {
}
cmd = fmt.Sprintf("python %s", script)
} else {
cmd = fmt.Sprintf("python -c 'import os; import base64; [print(k+\"=\"+str(base64.b64encode(bytes(v, \"utf-8\")), \"utf-8\")) for k, v in os.environ.items()]' > %s", envFile)
cmd = fmt.Sprintf("python -c 'import os; import base64; [print(k+\"=\"+str(base64.b64encode(bytes(v, \"utf-8\")), \"utf-8\")) for k, v in os.environ.items() if not k.startswith(\"PLUGIN_WITH_\")]' > %s", envFile)
}
s := step{
Name: name,
Expand Down Expand Up @@ -154,7 +154,7 @@ import base64
out = ""
for k, v in os.environ.items():
if "(" not in k and ")" not in k:
if "(" not in k and ")" not in k and not k.startswith("PLUGIN_WITH_"):
out = out + "{}={}\n".format(k, str(base64.urlsafe_b64encode(bytes(v, "utf-8")), "utf-8"))
with open(r"%s", "wb") as text_file:
text_file.write(bytes(out, "UTF-8"))
Expand Down

0 comments on commit 9408270

Please sign in to comment.