fix: don't export from within function
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

Also, don't explode on command function which has "export" in the name!

See coop-cloud/organising#498
This commit is contained in:
decentral1se 2023-10-04 02:29:59 +02:00
parent 970ae0fc4e
commit 2fcebe8309
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 27 additions and 1 deletions

View File

@ -153,7 +153,11 @@ func ReadAbraShEnvVars(abraSh string) (map[string]string, error) {
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "export") {
if strings.Contains(line, "export ") {
if len(strings.TrimLeft(line, " ")) < len(line) {
// NOTE(d1): indented lines are exports within functions
continue
}
splitVals := strings.Split(line, "export ")
envVarDef := splitVals[len(splitVals)-1]
keyVal := strings.Split(envVarDef, "=")

View File

@ -87,3 +87,25 @@ func TestReadEnv(t *testing.T) {
)
}
}
func TestReadAbraShEnvVars(t *testing.T) {
if err := catalogue.EnsureCatalogue(); err != nil {
t.Fatal(err)
}
offline := true
r, err := recipe.Get("abra-integration-test-recipe", offline)
if err != nil {
t.Fatal(err)
}
abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh")
abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
if err != nil {
t.Fatal(err)
}
if _, ok := abraShEnv["INNER_FOO"]; ok {
t.Error("INNER_FOO should not be exported")
}
}