// CreateBitriseConfigFromCLIParams ... func CreateBitriseConfigFromCLIParams(bitriseConfigBase64Data, bitriseConfigPath string) (models.BitriseDataModel, []string, error) { bitriseConfig := models.BitriseDataModel{} warnings := []string{} if bitriseConfigBase64Data != "" { config, warns, err := GetBitriseConfigFromBase64Data(bitriseConfigBase64Data) warnings = warns if err != nil { return models.BitriseDataModel{}, warnings, fmt.Errorf("Failed to get config (bitrise.yml) from base 64 data, err: %s", err) } bitriseConfig = config } else { bitriseConfigPath, err := GetBitriseConfigFilePath(bitriseConfigPath) if err != nil { return models.BitriseDataModel{}, []string{}, fmt.Errorf("Failed to get config (bitrise.yml) path: %s", err) } if bitriseConfigPath == "" { return models.BitriseDataModel{}, []string{}, errors.New("Failed to get config (bitrise.yml) path: empty bitriseConfigPath") } config, warns, err := bitrise.ReadBitriseConfig(bitriseConfigPath) warnings = warns if err != nil { return models.BitriseDataModel{}, warnings, fmt.Errorf("Config (path:%s) is not valid: %s", bitriseConfigPath, err) } bitriseConfig = config } isConfigVersionOK, err := versions.IsVersionGreaterOrEqual(models.Version, bitriseConfig.FormatVersion) if err != nil { log.Warn("bitrise CLI model version: ", models.Version) log.Warn("bitrise.yml Format Version: ", bitriseConfig.FormatVersion) return models.BitriseDataModel{}, warnings, fmt.Errorf("Failed to compare bitrise CLI models's version with the bitrise.yml FormatVersion: %s", err) } if !isConfigVersionOK { log.Warnf("The bitrise.yml has a higher Format Version (%s) than the bitrise CLI model's version (%s).", bitriseConfig.FormatVersion, models.Version) return models.BitriseDataModel{}, warnings, errors.New("This bitrise.yml was created with and for a newer version of bitrise CLI, please upgrade your bitrise CLI to use this bitrise.yml!") } return bitriseConfig, warnings, nil }
func doRun(c *cli.Context) { PrintBitriseHeaderASCIIArt() log.Debugln("[BITRISE_CLI] - Run") startTime = time.Now() buildRunResults = models.BuildRunResultsModel{} // Cleanup if err := bitrise.CleanupBitriseWorkPath(); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to cleanup bitrise work dir: " + err.Error())) } // Input validation bitriseConfigPath := c.String(PathKey) if bitriseConfigPath == "" { log.Debugln("[BITRISE_CLI] - Workflow path not defined, searching for " + DefaultBitriseConfigFileName + " in current folder...") bitriseConfigPath = bitrise.CurrentDir + "/" + DefaultBitriseConfigFileName if exist, err := pathutil.IsPathExists(bitriseConfigPath); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to check path:" + err.Error())) } else if !exist { log.Fatalln("[BITRISE_CLI] - No workflow yml found") buildFailedFatal(errors.New("[BITRISE_CLI] - No workflow yml found")) } } inventoryPath = c.String(InventoryKey) if inventoryPath == "" { log.Debugln("[BITRISE_CLI] - Inventory path not defined, searching for " + DefaultSecretsFileName + " in current folder...") inventoryPath = bitrise.CurrentDir + "/" + DefaultSecretsFileName if exist, err := pathutil.IsPathExists(inventoryPath); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to check path: " + err.Error())) } else if !exist { log.Debugln("[BITRISE_CLI] - No inventory yml found") inventoryPath = "" } } else { if exist, err := pathutil.IsPathExists(inventoryPath); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to check path: " + err.Error())) } else if !exist { buildFailedFatal(errors.New("[BITRISE_CLI] - No inventory yml found")) } } if inventoryPath != "" { if err := bitrise.RunEnvmanEnvstoreTest(inventoryPath); err != nil { buildFailedFatal(errors.New("Invalid invetory format: " + err.Error())) } if err := bitrise.RunCopy(inventoryPath, bitrise.EnvstorePath); err != nil { buildFailedFatal(errors.New("Failed to copy inventory: " + err.Error())) } } // Workflow selection workflowToRunName := "" if len(c.Args()) < 1 { log.Infoln("No workfow specified!") } else { workflowToRunName = c.Args()[0] } // Envman setup if err := os.Setenv(bitrise.EnvstorePathEnvKey, bitrise.EnvstorePath); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to add env: " + err.Error())) } if err := os.Setenv(bitrise.FormattedOutputPathEnvKey, bitrise.FormattedOutputPath); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to add env: " + err.Error())) } if inventoryPath == "" { if err := bitrise.RunEnvmanInit(); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to run envman init")) } } // Run work flow bitriseConfig, err := bitrise.ReadBitriseConfig(bitriseConfigPath) if err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to read Workflow: " + err.Error())) } // Check workflow if workflowToRunName == "" { // no workflow specified // list all the available ones and then exit log.Infoln("The following workflows are available:") for wfName := range bitriseConfig.Workflows { log.Infoln(" * " + wfName) } fmt.Println() log.Infoln("You can run a selected workflow with:") log.Infoln("-> bitrise run the-workflow-name") os.Exit(1) } // App level environment if err := exportEnvironmentsList(bitriseConfig.App.Environments); err != nil { buildFailedFatal(errors.New("[BITRISE_CLI] - Failed to export App environments: " + err.Error())) } workflowToRun, exist := bitriseConfig.Workflows[workflowToRunName] if !exist { buildFailedFatal(errors.New("[BITRISE_CLI] - Specified Workflow (" + workflowToRunName + ") does not exist!")) } if workflowToRun.Title == "" { workflowToRun.Title = workflowToRunName } activateAndRunWorkflow(workflowToRun, bitriseConfig) // // Build finished printSummary() if len(buildRunResults.FailedSteps) > 0 { log.Fatal("[BITRISE_CLI] - Workflow FINISHED but a couple of steps failed - Ouch") } else { if len(buildRunResults.FailedNotImportantSteps) > 0 { log.Warn("[BITRISE_CLI] - Workflow FINISHED but a couple of non imporatant steps failed") } } }