func exportEnvironmentsList(envsList []models.EnvironmentItemModel) error { log.Info("[BITRISE_CLI] - Exporting workflow environments") for _, env := range envsList { envKey, envValue, err := env.GetKeyValue() if err != nil { log.Errorln("[BITRISE_CLI] - Failed to get environment key-value pair from env:", env) return err } if envValue != "" { expand := true if env["is_expand"] != "" { boolValue, err := goinp.ParseBool(env["is_expand"]) if err != nil { log.Error("Failed to parse bool:", err) return err } expand = boolValue } if err := bitrise.RunEnvmanAdd(envKey, envValue, expand); err != nil { log.Errorln("[BITRISE_CLI] - Failed to run envman add") return err } } } return nil }
// EvaluateTemplateToBool ... func EvaluateTemplateToBool(expStr string, isCI, isPR bool, buildResults models.BuildRunResultsModel, envList envmanModels.EnvsJSONListModel) (bool, error) { resString, err := EvaluateTemplateToString(expStr, isCI, isPR, buildResults, envList) if err != nil { return false, err } return goinp.ParseBool(resString) }
func runStep(step models.StepModel, stepIDData StepIDData) error { log.Infof("[BITRISE_CLI] - Running step: %s (%s)", stepIDData.ID, stepIDData.Version) // Add step envs for _, input := range step.Inputs { envKey, envValue, err := input.GetKeyValue() if err != nil { return err } if envValue != "" { expand := true if input["is_expand"] != "" { boolValue, err := goinp.ParseBool(input["is_expand"]) if err != nil { log.Error("Failed to parse bool:", err) return err } expand = boolValue } if err := bitrise.RunEnvmanAdd(envKey, envValue, expand); err != nil { log.Errorln("[BITRISE_CLI] - Failed to run envman add") return err } } } stepDir := "./steps/" + stepIDData.ID + "/" + stepIDData.Version + "/" //stepCmd := fmt.Sprintf("%sstep.sh", stepDir) stepCmd := "step.sh" cmd := []string{"bash", stepCmd} if err := bitrise.RunEnvmanRunInDir(stepDir, cmd); err != nil { log.Errorln("[BITRISE_CLI] - Failed to run envman run") return err } log.Infof("[BITRISE_CLI] - Step executed: %s (%s)", stepIDData.ID, stepIDData.Version) return nil }
// EvaluateStepTemplateToBool ... func EvaluateStepTemplateToBool(expStr string, buildResults models.BuildRunResultsModel, isCI bool) (bool, error) { if expStr == "" { return false, errors.New("EvaluateStepTemplateToBool: Invalid, empty input: expStr") } if !strings.Contains(expStr, "{{") { expStr = "{{" + expStr + "}}" } tmpl := template.New("EvaluateStepTemplateToBool").Funcs(templateFuncMap) tmpl, err := tmpl.Parse(expStr) if err != nil { return false, err } templateData := createTemplateDataModel(buildResults, isCI) var resBuffer bytes.Buffer if err := tmpl.Execute(&resBuffer, templateData); err != nil { return false, err } resString := resBuffer.String() return goinp.ParseBool(resString) }