From ff417a1d76a9f8fcd5417fe79c3f46f946a05232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20G=C3=B6drei?= Date: Fri, 17 Mar 2017 10:27:44 +0100 Subject: [PATCH] bitrise-init update (#33) --- deplock.json | 2 +- .../_tests/integration/android_test.go | 26 + .../_tests/integration/mac_test.go | 1 - .../_tests/integration/manual_config_test.go | 1 - .../bitrise-core/bitrise-init/cli/config.go | 9 +- .../bitrise-init/scanners/android/android.go | 5 + .../scanners/fastlane/fastlane.go | 5 + .../bitrise-init/scanners/ios/ios.go | 609 +--------------- .../bitrise-init/scanners/macos/macos.go | 608 +--------------- .../bitrise-init/scanners/scanners.go | 10 +- .../bitrise-init/scanners/xamarin/xamarin.go | 5 + .../bitrise-init/scanners/xcode/xcode.go | 674 ++++++++++++++++++ .../bitrise-core/bitrise-init/steps/steps.go | 18 +- 13 files changed, 766 insertions(+), 1207 deletions(-) create mode 100644 go/src/github.com/bitrise-core/bitrise-init/scanners/xcode/xcode.go diff --git a/deplock.json b/deplock.json index 1f3ce735..8eb0921d 100644 --- a/deplock.json +++ b/deplock.json @@ -2,7 +2,7 @@ "dep_locks": [ { "url": "https://github.com/bitrise-core/bitrise-init.git", - "revision": "39458b2137dbdb31f2bedfb7b5cd6ac3fee3e504" + "revision": "9d8de8306440320cc3f714878c49c5e5b17c6fec" } ] } \ No newline at end of file diff --git a/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/android_test.go b/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/android_test.go index 507cc182..e33bcac6 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/android_test.go +++ b/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/android_test.go @@ -55,8 +55,34 @@ func TestAndroid(t *testing.T) { require.NoError(t, err) require.Equal(t, strings.TrimSpace(androidNonExecutableGradlewResultYML), strings.TrimSpace(result)) } + + t.Log("android-sdk22-no-gradlew") + { + sampleAppDir := filepath.Join(tmpDir, "android-sdk22-no-gradlew") + sampleAppURL := "https://github.com/bitrise-samples/android-sdk22-no-gradlew.git" + require.NoError(t, command.GitClone(sampleAppURL, sampleAppDir)) + + cmd := command.New(binPath(), "--ci", "config", "--dir", sampleAppDir, "--output-dir", sampleAppDir) + out, err := cmd.RunAndReturnTrimmedCombinedOutput() + require.NoError(t, err, out) + + scanResultPth := filepath.Join(sampleAppDir, "result.yml") + + result, err := fileutil.ReadStringFromFile(scanResultPth) + require.NoError(t, err) + require.Equal(t, strings.TrimSpace(sampleAppsSDK22NoGradlewResultYML), strings.TrimSpace(result)) + } } +var sampleAppsSDK22NoGradlewResultYML = `warnings: + android: + - "No Gradle Wrapper (gradlew) found. \nUsing a Gradle Wrapper (gradlew) + is required, as the wrapper is what makes sure\nthat the right Gradle version + is installed and used for the build. More info/guide: https://docs.gradle.org/current/userguide/gradle_wrapper.html" +errors: + general: + - No known platform detected` + var sampleAppsAndroid22Versions = []interface{}{ models.FormatVersion, steps.ActivateSSHKeyVersion, diff --git a/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/mac_test.go b/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/mac_test.go index c7f413bb..bc12fb74 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/mac_test.go +++ b/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/mac_test.go @@ -74,7 +74,6 @@ configs: macos-test-config: | format_version: %s default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git - app: {} trigger_map: - push_branch: '*' workflow: primary diff --git a/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/manual_config_test.go b/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/manual_config_test.go index a36f2196..dd484b1f 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/manual_config_test.go +++ b/go/src/github.com/bitrise-core/bitrise-init/_tests/integration/manual_config_test.go @@ -282,7 +282,6 @@ configs: default-macos-config: | format_version: %s default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git - app: {} trigger_map: - push_branch: '*' workflow: primary diff --git a/go/src/github.com/bitrise-core/bitrise-init/cli/config.go b/go/src/github.com/bitrise-core/bitrise-init/cli/config.go index f00a0b9f..dc61eb70 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/cli/config.go +++ b/go/src/github.com/bitrise-core/bitrise-init/cli/config.go @@ -1,7 +1,6 @@ package cli import ( - "errors" "fmt" "os" "path" @@ -133,14 +132,14 @@ func initConfig(c *cli.Context) error { log.Infoft("Saving outputs:") scanResult.AddError("general", "No known platform detected") + outputPth, err := writeScanResult(scanResult, outputDir, format) if err != nil { - log.Errorf("Failed to write output, error: %s", err) - } else { - log.Printft(" scan result: %s", outputPth) + return fmt.Errorf("Failed to write output, error: %s", err) } - return errors.New("No known platform detected") + log.Printft(" scan result: %s", outputPth) + return nil } // Write output to files diff --git a/go/src/github.com/bitrise-core/bitrise-init/scanners/android/android.go b/go/src/github.com/bitrise-core/bitrise-init/scanners/android/android.go index 3a524ddc..5f5a89a6 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/scanners/android/android.go +++ b/go/src/github.com/bitrise-core/bitrise-init/scanners/android/android.go @@ -128,6 +128,11 @@ type Scanner struct { GradleFiles []string } +// NewScanner ... +func NewScanner() *Scanner { + return &Scanner{} +} + // Name ... func (scanner Scanner) Name() string { return scannerName diff --git a/go/src/github.com/bitrise-core/bitrise-init/scanners/fastlane/fastlane.go b/go/src/github.com/bitrise-core/bitrise-init/scanners/fastlane/fastlane.go index 7e9d7b11..a75532cd 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/scanners/fastlane/fastlane.go +++ b/go/src/github.com/bitrise-core/bitrise-init/scanners/fastlane/fastlane.go @@ -150,6 +150,11 @@ type Scanner struct { Fastfiles []string } +// NewScanner ... +func NewScanner() *Scanner { + return &Scanner{} +} + // Name ... func (scanner Scanner) Name() string { return scannerName diff --git a/go/src/github.com/bitrise-core/bitrise-init/scanners/ios/ios.go b/go/src/github.com/bitrise-core/bitrise-init/scanners/ios/ios.go index be1607ee..2bc83121 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/scanners/ios/ios.go +++ b/go/src/github.com/bitrise-core/bitrise-init/scanners/ios/ios.go @@ -1,622 +1,45 @@ package ios -import ( - "errors" - "fmt" +import "github.com/bitrise-core/bitrise-init/models" +import "github.com/bitrise-core/bitrise-init/scanners/xcode" - "gopkg.in/yaml.v2" - - "path/filepath" - - "github.com/bitrise-core/bitrise-init/models" - "github.com/bitrise-core/bitrise-init/steps" - "github.com/bitrise-core/bitrise-init/utility" - bitriseModels "github.com/bitrise-io/bitrise/models" - envmanModels "github.com/bitrise-io/envman/models" - "github.com/bitrise-io/go-utils/log" - "github.com/bitrise-io/go-utils/pathutil" -) - -const scannerName = "ios" - -const defaultConfigName = "default-ios-config" - -const ( - projectPathKey = "project_path" - projectPathTitle = "Project (or Workspace) path" - projectPathEnvKey = "BITRISE_PROJECT_PATH" - - schemeKey = "scheme" - schemeTitle = "Scheme name" - schemeEnvKey = "BITRISE_SCHEME" - - carthageCommandKey = "carthage_command" - carthageCommandTitle = "Carthage command to run" -) - -// ConfigDescriptor ... -type ConfigDescriptor struct { - HasPodfile bool - CarthageCommand string - HasTest bool - MissingSharedSchemes bool -} - -func (descriptor ConfigDescriptor) String() string { - name := "ios-" - if descriptor.HasPodfile { - name = name + "pod-" - } - if descriptor.CarthageCommand != "" { - name = name + "carthage-" - } - if descriptor.HasTest { - name = name + "test-" - } - if descriptor.MissingSharedSchemes { - name = name + "missing-shared-schemes-" - } - return name + "config" -} +// ScannerName ... +const ScannerName = "ios" // Scanner ... type Scanner struct { - searchDir string - fileList []string - projectFiles []string - configDescriptors []ConfigDescriptor + xcode.Scanner } -// Name ... -func (scanner Scanner) Name() string { - return scannerName +// NewScanner ... +func NewScanner() *Scanner { + return &Scanner{xcode.Scanner{ProjectType: xcode.ProjectTypeIOS}} } +// Name ... +func (scanner *Scanner) Name() string { return ScannerName } + // DetectPlatform ... func (scanner *Scanner) DetectPlatform(searchDir string) (bool, error) { - scanner.searchDir = searchDir - - fileList, err := utility.ListPathInDirSortedByComponents(searchDir, true) - if err != nil { - return false, fmt.Errorf("failed to search for files in (%s), error: %s", searchDir, err) - } - scanner.fileList = fileList - - // Search for xcodeproj - log.Infoft("Searching for Xcode project files") - - xcodeprojectFiles, err := utility.FilterPaths(fileList, utility.AllowXcodeProjExtFilter) - if err != nil { - return false, err - } - - log.Printft("%d Xcode project files found", len(xcodeprojectFiles)) - for _, xcodeprojectFile := range xcodeprojectFiles { - log.Printft("- %s", xcodeprojectFile) - } - - if len(xcodeprojectFiles) == 0 { - log.Printft("platform not detected") - return false, nil - } - - log.Infoft("Filter relevant Xcode project files") - - xcodeprojectFiles, err = utility.FilterPaths(xcodeprojectFiles, - utility.AllowIsDirectoryFilter, - utility.ForbidEmbeddedWorkspaceRegexpFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter, - utility.AllowIphoneosSDKFilter, - ) - if err != nil { - return false, err - } - - log.Printft("%d Xcode iOS project files found", len(xcodeprojectFiles)) - for _, xcodeprojectFile := range xcodeprojectFiles { - log.Printft("- %s", xcodeprojectFile) - } - - if len(xcodeprojectFiles) == 0 { - log.Printft("platform not detected") - return false, nil - } - - scanner.projectFiles = xcodeprojectFiles - - log.Doneft("Platform detected") - - return true, nil + return scanner.CommonDetectPlatform(searchDir) } // Options ... func (scanner *Scanner) Options() (models.OptionModel, models.Warnings, error) { - warnings := models.Warnings{} - - projectFiles := scanner.projectFiles - workspaceFiles, err := utility.FilterPaths(scanner.fileList, - utility.AllowXCWorkspaceExtFilter, - utility.AllowIsDirectoryFilter, - utility.ForbidEmbeddedWorkspaceRegexpFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter, - utility.AllowIphoneosSDKFilter, - ) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - standaloneProjects, workspaces, err := utility.CreateStandaloneProjectsAndWorkspaces(projectFiles, workspaceFiles) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - // - // Create cocoapods workspace-project mapping - log.Infoft("Searching for Podfiles") - - podfiles, err := utility.FilterPaths(scanner.fileList, - utility.AllowPodfileBaseFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - log.Printft("%d Podfiles detected", len(podfiles)) - for _, file := range podfiles { - log.Printft("- %s", file) - } - - for _, podfile := range podfiles { - workspaceProjectMap, err := utility.GetWorkspaceProjectMap(podfile, projectFiles) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - standaloneProjects, workspaces, err = utility.MergePodWorkspaceProjectMap(workspaceProjectMap, standaloneProjects, workspaces) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - } - // --- - - // - // Carthage - log.Infof("Searching for Cartfile") - - cartfiles, err := utility.FilterPaths(scanner.fileList, - utility.AllowCartfileBaseFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - log.Printf("%d Cartfiles detected", len(cartfiles)) - for _, file := range cartfiles { - log.Printft("- %s", file) - } - // ---- - - // - // Analyze projects and workspaces - isXcshareddataGitignored := false - defaultGitignorePth := filepath.Join(scanner.searchDir, ".gitignore") - - if exist, err := pathutil.IsPathExists(defaultGitignorePth); err != nil { - log.Warnf("Failed to check if .gitignore file exists at: %s, error: %s", defaultGitignorePth, err) - } else if exist { - isGitignored, err := utility.FileContains(defaultGitignorePth, "xcshareddata") - if err != nil { - log.Warnf("Failed to check if xcshareddata gitignored, error: %s", err) - } else { - isXcshareddataGitignored = isGitignored - } - } - - for _, project := range standaloneProjects { - log.Infoft("Inspecting standalone project file: %s", project.Pth) - - log.Printft("%d shared schemes detected", len(project.SharedSchemes)) - for _, scheme := range project.SharedSchemes { - log.Printft("- %s", scheme.Name) - } - - if len(project.SharedSchemes) == 0 { - log.Printft("") - log.Errorft("No shared schemes found, adding recreate-user-schemes step...") - log.Errorft("The newly generated schemes may differ from the ones in your project.") - if isXcshareddataGitignored { - log.Errorft("Your gitignore file (%s) contains 'xcshareddata', maybe shared schemes are gitignored?", defaultGitignorePth) - log.Errorft("If not, make sure to share your schemes, to have the expected behaviour.") - } else { - log.Errorft("Make sure to share your schemes, to have the expected behaviour.") - } - log.Printft("") - - message := `No shared schemes found for project: ` + project.Pth + `.` - if isXcshareddataGitignored { - message += ` -Your gitignore file (` + defaultGitignorePth + `) contains 'xcshareddata', maybe shared schemes are gitignored?` - } - message += ` -Automatically generated schemes may differ from the ones in your project. -Make sure to share your schemes for the expected behaviour.` - - warnings = append(warnings, message) - - log.Warnft("%d user schemes will be generated", len(project.Targets)) - for _, target := range project.Targets { - log.Warnft("- %s", target.Name) - } - } - } - - for _, workspace := range workspaces { - log.Infoft("Inspecting workspace file: %s", workspace.Pth) - - sharedSchemes := workspace.GetSharedSchemes() - log.Printft("%d shared schemes detected", len(sharedSchemes)) - for _, scheme := range sharedSchemes { - log.Printft("- %s", scheme.Name) - } - - if len(sharedSchemes) == 0 { - log.Printft("") - log.Errorft("No shared schemes found, adding recreate-user-schemes step...") - log.Errorft("The newly generated schemes may differ from the ones in your project.") - if isXcshareddataGitignored { - log.Errorft("Your gitignore file (%s) contains 'xcshareddata', maybe shared schemes are gitignored?", defaultGitignorePth) - log.Errorft("If not, make sure to share your schemes, to have the expected behaviour.") - } else { - log.Errorft("Make sure to share your schemes, to have the expected behaviour.") - } - log.Printft("") - - message := `No shared schemes found for project: ` + workspace.Pth + `.` - if isXcshareddataGitignored { - message += ` -Your gitignore file (` + defaultGitignorePth + `) (%s) contains 'xcshareddata', maybe shared schemes are gitignored?` - } - message += ` -Automatically generated schemes may differ from the ones in your project. -Make sure to share your schemes for the expected behaviour.` - - warnings = append(warnings, message) - - targets := workspace.GetTargets() - log.Warnft("%d user schemes will be generated", len(targets)) - for _, target := range targets { - log.Warnft("- %s", target.Name) - } - } - } - // ----- - - // - // Create config descriptors - configDescriptors := []ConfigDescriptor{} - projectPathOption := models.NewOptionModel(projectPathTitle, projectPathEnvKey) - - // Add Standalon Project options - for _, project := range standaloneProjects { - schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) - - carthageCommand := "" - if utility.HasCartfileInDirectoryOf(project.Pth) { - if utility.HasCartfileResolvedInDirectoryOf(project.Pth) { - carthageCommand = "bootstrap" - } else { - dir := filepath.Dir(project.Pth) - cartfilePth := filepath.Join(dir, "Cartfile") - - warnings = append(warnings, fmt.Sprintf(`Cartfile found at (%s), but no Cartfile.resolved exists in the same directory. -It is strongly recommended to commit this file to your repository`, cartfilePth)) - - carthageCommand = "update" - } - } - - if len(project.SharedSchemes) == 0 { - for _, target := range project.Targets { - configDescriptor := ConfigDescriptor{ - HasPodfile: false, - CarthageCommand: carthageCommand, - HasTest: target.HasXCTest, - MissingSharedSchemes: true, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[target.Name] = configOption - } - } else { - for _, scheme := range project.SharedSchemes { - configDescriptor := ConfigDescriptor{ - HasPodfile: false, - CarthageCommand: carthageCommand, - HasTest: scheme.HasXCTest, - MissingSharedSchemes: false, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[scheme.Name] = configOption - } - } - - projectPathOption.ValueMap[project.Pth] = schemeOption - } - - // Add Workspace options - for _, workspace := range workspaces { - schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) - - carthageCommand := "" - if utility.HasCartfileInDirectoryOf(workspace.Pth) { - if utility.HasCartfileResolvedInDirectoryOf(workspace.Pth) { - carthageCommand = "bootstrap" - } else { - dir := filepath.Dir(workspace.Pth) - cartfilePth := filepath.Join(dir, "Cartfile") - - warnings = append(warnings, fmt.Sprintf(`Cartfile found at (%s), but no Cartfile.resolved exists in the same directory. -It is strongly recommended to commit this file to your repository`, cartfilePth)) - - carthageCommand = "update" - } - } - - sharedSchemes := workspace.GetSharedSchemes() - if len(sharedSchemes) == 0 { - targets := workspace.GetTargets() - for _, target := range targets { - configDescriptor := ConfigDescriptor{ - HasPodfile: workspace.IsPodWorkspace, - CarthageCommand: carthageCommand, - HasTest: target.HasXCTest, - MissingSharedSchemes: true, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[target.Name] = configOption - } - } else { - for _, scheme := range sharedSchemes { - configDescriptor := ConfigDescriptor{ - HasPodfile: workspace.IsPodWorkspace, - CarthageCommand: carthageCommand, - HasTest: scheme.HasXCTest, - MissingSharedSchemes: false, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[scheme.Name] = configOption - } - } - - projectPathOption.ValueMap[workspace.Pth] = schemeOption - } - // ----- - - if len(configDescriptors) == 0 { - log.Errorft("No valid iOS config found") - return models.OptionModel{}, warnings, errors.New("No valid iOS config found") - } - - scanner.configDescriptors = configDescriptors - - return projectPathOption, warnings, nil + return scanner.CommonOptions() } // DefaultOptions ... func (scanner *Scanner) DefaultOptions() models.OptionModel { - configOption := models.NewEmptyOptionModel() - configOption.Config = defaultConfigName - - projectPathOption := models.NewOptionModel(projectPathTitle, projectPathEnvKey) - schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) - - schemeOption.ValueMap["_"] = configOption - projectPathOption.ValueMap["_"] = schemeOption - - return projectPathOption -} - -func generateConfig(hasPodfile, hasTest, missingSharedSchemes bool, carthageCommand string) bitriseModels.BitriseDataModel { - // - // Prepare steps - prepareSteps := []bitriseModels.StepListItemModel{} - - // ActivateSSHKey - prepareSteps = append(prepareSteps, steps.ActivateSSHKeyStepListItem()) - - // GitClone - prepareSteps = append(prepareSteps, steps.GitCloneStepListItem()) - - // Script - prepareSteps = append(prepareSteps, steps.ScriptSteplistItem(steps.ScriptDefaultTitle)) - - // CertificateAndProfileInstaller - prepareSteps = append(prepareSteps, steps.CertificateAndProfileInstallerStepListItem()) - - // CocoapodsInstall - if hasPodfile { - prepareSteps = append(prepareSteps, steps.CocoapodsInstallStepListItem()) - } - - // Carthage - if carthageCommand != "" { - prepareSteps = append(prepareSteps, steps.CarthageStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{carthageCommandKey: carthageCommand}, - })) - } - - // RecreateUserSchemes - if missingSharedSchemes { - prepareSteps = append(prepareSteps, steps.RecreateUserSchemesStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - })) - } - // ---------- - - // - // CI steps - ciSteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTest - if hasTest { - ciSteps = append(ciSteps, steps.XcodeTestStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - } - - // DeployToBitriseIo - ciSteps = append(ciSteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - // - // Deploy steps - deploySteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTest - if hasTest { - deploySteps = append(deploySteps, steps.XcodeTestStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - } - - // XcodeArchive - deploySteps = append(deploySteps, steps.XcodeArchiveStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // DeployToBitriseIo - deploySteps = append(deploySteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - return models.BitriseDataWithCIAndCDWorkflow([]envmanModels.EnvironmentItemModel{}, ciSteps, deploySteps) + return scanner.CommonDefaultOptions() } // Configs ... func (scanner *Scanner) Configs() (models.BitriseConfigMap, error) { - descriptors := []ConfigDescriptor{} - descritorNameMap := map[string]bool{} - - for _, descriptor := range scanner.configDescriptors { - _, exist := descritorNameMap[descriptor.String()] - if !exist { - descriptors = append(descriptors, descriptor) - } - } - - bitriseDataMap := models.BitriseConfigMap{} - for _, descriptor := range descriptors { - configName := descriptor.String() - bitriseData := generateConfig(descriptor.HasPodfile, descriptor.HasTest, descriptor.MissingSharedSchemes, descriptor.CarthageCommand) - data, err := yaml.Marshal(bitriseData) - if err != nil { - return models.BitriseConfigMap{}, err - } - bitriseDataMap[configName] = string(data) - } - - return bitriseDataMap, nil + return scanner.CommonConfigs() } // DefaultConfigs ... func (scanner *Scanner) DefaultConfigs() (models.BitriseConfigMap, error) { - // - // Prepare steps - prepareSteps := []bitriseModels.StepListItemModel{} - - // ActivateSSHKey - prepareSteps = append(prepareSteps, steps.ActivateSSHKeyStepListItem()) - - // GitClone - prepareSteps = append(prepareSteps, steps.GitCloneStepListItem()) - - // Script - prepareSteps = append(prepareSteps, steps.ScriptSteplistItem(steps.ScriptDefaultTitle)) - - // CertificateAndProfileInstaller - prepareSteps = append(prepareSteps, steps.CertificateAndProfileInstallerStepListItem()) - - // CocoapodsInstall - prepareSteps = append(prepareSteps, steps.CocoapodsInstallStepListItem()) - - // RecreateUserSchemes - prepareSteps = append(prepareSteps, steps.RecreateUserSchemesStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - })) - // ---------- - - // - // CI steps - ciSteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTest - ciSteps = append(ciSteps, steps.XcodeTestStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // DeployToBitriseIo - ciSteps = append(ciSteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - // - // Deploy steps - deploySteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTest - deploySteps = append(deploySteps, steps.XcodeTestStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // XcodeArchive - deploySteps = append(deploySteps, steps.XcodeArchiveStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // DeployToBitriseIo - deploySteps = append(deploySteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - config := models.BitriseDataWithCIAndCDWorkflow([]envmanModels.EnvironmentItemModel{}, ciSteps, deploySteps) - data, err := yaml.Marshal(config) - if err != nil { - return models.BitriseConfigMap{}, err - } - - configName := defaultConfigName - bitriseDataMap := models.BitriseConfigMap{} - bitriseDataMap[configName] = string(data) - - return bitriseDataMap, nil + return scanner.CommonDefaultConfigs() } diff --git a/go/src/github.com/bitrise-core/bitrise-init/scanners/macos/macos.go b/go/src/github.com/bitrise-core/bitrise-init/scanners/macos/macos.go index f38d3275..0a519152 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/scanners/macos/macos.go +++ b/go/src/github.com/bitrise-core/bitrise-init/scanners/macos/macos.go @@ -1,621 +1,45 @@ package macos -import ( - "errors" - "fmt" - "path/filepath" +import "github.com/bitrise-core/bitrise-init/models" +import "github.com/bitrise-core/bitrise-init/scanners/xcode" - yaml "gopkg.in/yaml.v1" - - "github.com/bitrise-core/bitrise-init/models" - "github.com/bitrise-core/bitrise-init/steps" - "github.com/bitrise-core/bitrise-init/utility" - bitriseModels "github.com/bitrise-io/bitrise/models" - "github.com/bitrise-io/depman/pathutil" - envmanModels "github.com/bitrise-io/envman/models" - "github.com/bitrise-io/go-utils/log" -) - -const scannerName = "macos" - -const defaultConfigName = "default-macos-config" - -const ( - projectPathKey = "project_path" - projectPathTitle = "Project (or Workspace) path" - projectPathEnvKey = "BITRISE_PROJECT_PATH" - - schemeKey = "scheme" - schemeTitle = "Scheme name" - schemeEnvKey = "BITRISE_SCHEME" - - carthageCommandKey = "carthage_command" - carthageCommandTitle = "Carthage command to run" -) - -// ConfigDescriptor ... -type ConfigDescriptor struct { - HasPodfile bool - CarthageCommand string - HasTest bool - MissingSharedSchemes bool -} - -func (descriptor ConfigDescriptor) String() string { - name := "macos-" - if descriptor.HasPodfile { - name = name + "pod-" - } - if descriptor.CarthageCommand != "" { - name = name + "carthage-" - } - if descriptor.HasTest { - name = name + "test-" - } - if descriptor.MissingSharedSchemes { - name = name + "missing-shared-schemes-" - } - return name + "config" -} +// ScannerName ... +const ScannerName = "macos" // Scanner ... type Scanner struct { - searchDir string - fileList []string - projectFiles []string - configDescriptors []ConfigDescriptor + xcode.Scanner } -// Name ... -func (scanner Scanner) Name() string { - return scannerName +// NewScanner ... +func NewScanner() *Scanner { + return &Scanner{xcode.Scanner{ProjectType: xcode.ProjectTypeMacOS}} } +// Name ... +func (scanner *Scanner) Name() string { return ScannerName } + // DetectPlatform ... func (scanner *Scanner) DetectPlatform(searchDir string) (bool, error) { - scanner.searchDir = searchDir - - fileList, err := utility.ListPathInDirSortedByComponents(searchDir, true) - if err != nil { - return false, fmt.Errorf("failed to search for files in (%s), error: %s", searchDir, err) - } - scanner.fileList = fileList - - // Search for xcodeproj - log.Infoft("Searching for Xcode project files") - - xcodeprojectFiles, err := utility.FilterPaths(fileList, utility.AllowXcodeProjExtFilter) - if err != nil { - return false, err - } - - log.Printft("%d Xcode project files found", len(xcodeprojectFiles)) - for _, xcodeprojectFile := range xcodeprojectFiles { - log.Printft("- %s", xcodeprojectFile) - } - - if len(xcodeprojectFiles) == 0 { - log.Printft("platform not detected") - return false, nil - } - - log.Infoft("Filter relevant Xcode project files") - - xcodeprojectFiles, err = utility.FilterPaths(xcodeprojectFiles, - utility.AllowIsDirectoryFilter, - utility.ForbidEmbeddedWorkspaceRegexpFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter, - utility.AllowMacosxSDKFilter, - ) - if err != nil { - return false, err - } - - log.Printft("%d Xcode macOS project files found", len(xcodeprojectFiles)) - for _, xcodeprojectFile := range xcodeprojectFiles { - log.Printft("- %s", xcodeprojectFile) - } - - if len(xcodeprojectFiles) == 0 { - log.Printft("platform not detected") - return false, nil - } - - scanner.projectFiles = xcodeprojectFiles - - log.Doneft("Platform detected") - - return true, nil + return scanner.CommonDetectPlatform(searchDir) } // Options ... func (scanner *Scanner) Options() (models.OptionModel, models.Warnings, error) { - warnings := models.Warnings{} - - projectFiles := scanner.projectFiles - workspaceFiles, err := utility.FilterPaths(scanner.fileList, - utility.AllowXCWorkspaceExtFilter, - utility.AllowIsDirectoryFilter, - utility.ForbidEmbeddedWorkspaceRegexpFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter, - utility.AllowMacosxSDKFilter, - ) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - standaloneProjects, workspaces, err := utility.CreateStandaloneProjectsAndWorkspaces(projectFiles, workspaceFiles) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - // - // Create cocoapods workspace-project mapping - log.Infoft("Searching for Podfiles") - - podfiles, err := utility.FilterPaths(scanner.fileList, - utility.AllowPodfileBaseFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - log.Printft("%d Podfiles detected", len(podfiles)) - for _, file := range podfiles { - log.Printft("- %s", file) - } - - for _, podfile := range podfiles { - workspaceProjectMap, err := utility.GetWorkspaceProjectMap(podfile, projectFiles) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - standaloneProjects, workspaces, err = utility.MergePodWorkspaceProjectMap(workspaceProjectMap, standaloneProjects, workspaces) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - } - // --- - - // - // Carthage - log.Infof("Searching for Cartfile") - - cartfiles, err := utility.FilterPaths(scanner.fileList, - utility.AllowCartfileBaseFilter, - utility.ForbidGitDirComponentFilter, - utility.ForbidPodsDirComponentFilter, - utility.ForbidCarthageDirComponentFilter, - utility.ForbidFramworkComponentWithExtensionFilter) - if err != nil { - return models.OptionModel{}, models.Warnings{}, err - } - - log.Printf("%d Cartfiles detected", len(cartfiles)) - for _, file := range cartfiles { - log.Printft("- %s", file) - } - // ---- - - // - // Analyze projects and workspaces - isXcshareddataGitignored := false - defaultGitignorePth := filepath.Join(scanner.searchDir, ".gitignore") - - if exist, err := pathutil.IsPathExists(defaultGitignorePth); err != nil { - log.Warnf("Failed to check if .gitignore file exists at: %s, error: %s", defaultGitignorePth, err) - } else if exist { - isGitignored, err := utility.FileContains(defaultGitignorePth, "xcshareddata") - if err != nil { - log.Warnf("Failed to check if xcshareddata gitignored, error: %s", err) - } else { - isXcshareddataGitignored = isGitignored - } - } - - for _, project := range standaloneProjects { - log.Infoft("Inspecting standalone project file: %s", project.Pth) - - log.Printft("%d shared schemes detected", len(project.SharedSchemes)) - for _, scheme := range project.SharedSchemes { - log.Printft("- %s", scheme.Name) - } - - if len(project.SharedSchemes) == 0 { - log.Printft("") - log.Errorft("No shared schemes found, adding recreate-user-schemes step...") - log.Errorft("The newly generated schemes may differ from the ones in your project.") - if isXcshareddataGitignored { - log.Errorft("Your gitignore file (%s) contains 'xcshareddata', maybe shared schemes are gitignored?", defaultGitignorePth) - log.Errorft("If not, make sure to share your schemes, to have the expected behaviour.") - } else { - log.Errorft("Make sure to share your schemes, to have the expected behaviour.") - } - log.Printft("") - - message := `No shared schemes found for project: ` + project.Pth + `.` - if isXcshareddataGitignored { - message += ` -Your gitignore file (` + defaultGitignorePth + `) (%s) contains 'xcshareddata', maybe shared schemes are gitignored?` - } - message += ` -Automatically generated schemes may differ from the ones in your project. -Make sure to share your schemes for the expected behaviour.` - - warnings = append(warnings, message) - - log.Warnft("%d user schemes will be generated", len(project.Targets)) - for _, target := range project.Targets { - log.Warnft("- %s", target.Name) - } - } - } - - for _, workspace := range workspaces { - log.Infoft("Inspecting workspace file: %s", workspace.Pth) - - sharedSchemes := workspace.GetSharedSchemes() - log.Printft("%d shared schemes detected", len(sharedSchemes)) - for _, scheme := range sharedSchemes { - log.Printft("- %s", scheme.Name) - } - - if len(sharedSchemes) == 0 { - log.Printft("") - log.Errorft("No shared schemes found, adding recreate-user-schemes step...") - log.Errorft("The newly generated schemes may differ from the ones in your project.") - if isXcshareddataGitignored { - log.Errorft("Your gitignore file (%s) contains 'xcshareddata', maybe shared schemes are gitignored?", defaultGitignorePth) - log.Errorft("If not, make sure to share your schemes, to have the expected behaviour.") - } else { - log.Errorft("Make sure to share your schemes, to have the expected behaviour.") - } - log.Printft("") - - message := `No shared schemes found for project: ` + workspace.Pth + `.` - if isXcshareddataGitignored { - message += ` -Your gitignore file (` + defaultGitignorePth + `) contains 'xcshareddata', maybe shared schemes are gitignored?` - } - message += ` -Automatically generated schemes may differ from the ones in your project. -Make sure to share your schemes for the expected behaviour.` - - warnings = append(warnings, message) - - targets := workspace.GetTargets() - log.Warnft("%d user schemes will be generated", len(targets)) - for _, target := range targets { - log.Warnft("- %s", target.Name) - } - } - } - // ----- - - // - // Create config descriptors - configDescriptors := []ConfigDescriptor{} - projectPathOption := models.NewOptionModel(projectPathTitle, projectPathEnvKey) - - // Add Standalon Project options - for _, project := range standaloneProjects { - schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) - - carthageCommand := "" - if utility.HasCartfileInDirectoryOf(project.Pth) { - if utility.HasCartfileResolvedInDirectoryOf(project.Pth) { - carthageCommand = "bootstrap" - } else { - dir := filepath.Dir(project.Pth) - cartfilePth := filepath.Join(dir, "Cartfile") - - warnings = append(warnings, fmt.Sprintf(`Cartfile found at (%s), but no Cartfile.resolved exists in the same directory. -It is strongly recommended to commit this file to your repository`, cartfilePth)) - - carthageCommand = "update" - } - } - - if len(project.SharedSchemes) == 0 { - for _, target := range project.Targets { - configDescriptor := ConfigDescriptor{ - HasPodfile: false, - CarthageCommand: carthageCommand, - HasTest: target.HasXCTest, - MissingSharedSchemes: true, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[target.Name] = configOption - } - } else { - for _, scheme := range project.SharedSchemes { - configDescriptor := ConfigDescriptor{ - HasPodfile: false, - CarthageCommand: carthageCommand, - HasTest: scheme.HasXCTest, - MissingSharedSchemes: false, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[scheme.Name] = configOption - } - } - - projectPathOption.ValueMap[project.Pth] = schemeOption - } - - // Add Workspace options - for _, workspace := range workspaces { - schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) - - carthageCommand := "" - if utility.HasCartfileInDirectoryOf(workspace.Pth) { - if utility.HasCartfileResolvedInDirectoryOf(workspace.Pth) { - carthageCommand = "bootstrap" - } else { - dir := filepath.Dir(workspace.Pth) - cartfilePth := filepath.Join(dir, "Cartfile") - - warnings = append(warnings, fmt.Sprintf(`Cartfile found at (%s), but no Cartfile.resolved exists in the same directory. -It is strongly recommended to commit this file to your repository`, cartfilePth)) - - carthageCommand = "update" - } - } - - sharedSchemes := workspace.GetSharedSchemes() - if len(sharedSchemes) == 0 { - targets := workspace.GetTargets() - for _, target := range targets { - configDescriptor := ConfigDescriptor{ - HasPodfile: workspace.IsPodWorkspace, - CarthageCommand: carthageCommand, - HasTest: target.HasXCTest, - MissingSharedSchemes: true, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[target.Name] = configOption - } - } else { - for _, scheme := range sharedSchemes { - configDescriptor := ConfigDescriptor{ - HasPodfile: workspace.IsPodWorkspace, - CarthageCommand: carthageCommand, - HasTest: scheme.HasXCTest, - MissingSharedSchemes: false, - } - configDescriptors = append(configDescriptors, configDescriptor) - - configOption := models.NewEmptyOptionModel() - configOption.Config = configDescriptor.String() - - schemeOption.ValueMap[scheme.Name] = configOption - } - } - - projectPathOption.ValueMap[workspace.Pth] = schemeOption - } - // ----- - - if len(configDescriptors) == 0 { - log.Errorft("No valid macOS config found") - return models.OptionModel{}, warnings, errors.New("No valid macOS config found") - } - - scanner.configDescriptors = configDescriptors - - return projectPathOption, warnings, nil + return scanner.CommonOptions() } // DefaultOptions ... func (scanner *Scanner) DefaultOptions() models.OptionModel { - configOption := models.NewEmptyOptionModel() - configOption.Config = defaultConfigName - - projectPathOption := models.NewOptionModel(projectPathTitle, projectPathEnvKey) - schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) - - schemeOption.ValueMap["_"] = configOption - projectPathOption.ValueMap["_"] = schemeOption - - return projectPathOption -} - -func generateConfig(hasPodfile, hasTest, missingSharedSchemes bool, carthageCommand string) bitriseModels.BitriseDataModel { - // - // Prepare steps - prepareSteps := []bitriseModels.StepListItemModel{} - - // ActivateSSHKey - prepareSteps = append(prepareSteps, steps.ActivateSSHKeyStepListItem()) - - // GitClone - prepareSteps = append(prepareSteps, steps.GitCloneStepListItem()) - - // Script - prepareSteps = append(prepareSteps, steps.ScriptSteplistItem(steps.ScriptDefaultTitle)) - - // CertificateAndProfileInstaller - prepareSteps = append(prepareSteps, steps.CertificateAndProfileInstallerStepListItem()) - - // CocoapodsInstall - if hasPodfile { - prepareSteps = append(prepareSteps, steps.CocoapodsInstallStepListItem()) - } - - // Carthage - if carthageCommand != "" { - prepareSteps = append(prepareSteps, steps.CarthageStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{carthageCommandKey: carthageCommand}, - })) - } - - // RecreateUserSchemes - if missingSharedSchemes { - prepareSteps = append(prepareSteps, steps.RecreateUserSchemesStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - })) - } - // ---------- - - // - // CI steps - ciSteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTestMac - if hasTest { - ciSteps = append(ciSteps, steps.XcodeTestMacStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - } - - // DeployToBitriseIo - ciSteps = append(ciSteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - // - // Deploy steps - deploySteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTestMac - if hasTest { - deploySteps = append(deploySteps, steps.XcodeTestMacStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - } - - // XcodeArchiveMac - deploySteps = append(deploySteps, steps.XcodeArchiveMacStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // DeployToBitriseIo - deploySteps = append(deploySteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - return models.BitriseDataWithCIAndCDWorkflow([]envmanModels.EnvironmentItemModel{}, ciSteps, deploySteps) + return scanner.CommonDefaultOptions() } // Configs ... func (scanner *Scanner) Configs() (models.BitriseConfigMap, error) { - descriptors := []ConfigDescriptor{} - descritorNameMap := map[string]bool{} - - for _, descriptor := range scanner.configDescriptors { - _, exist := descritorNameMap[descriptor.String()] - if !exist { - descriptors = append(descriptors, descriptor) - } - } - - bitriseDataMap := models.BitriseConfigMap{} - for _, descriptor := range descriptors { - configName := descriptor.String() - bitriseData := generateConfig(descriptor.HasPodfile, descriptor.HasTest, descriptor.MissingSharedSchemes, descriptor.CarthageCommand) - data, err := yaml.Marshal(bitriseData) - if err != nil { - return models.BitriseConfigMap{}, err - } - bitriseDataMap[configName] = string(data) - } - - return bitriseDataMap, nil + return scanner.CommonConfigs() } // DefaultConfigs ... func (scanner *Scanner) DefaultConfigs() (models.BitriseConfigMap, error) { - // - // Prepare steps - prepareSteps := []bitriseModels.StepListItemModel{} - - // ActivateSSHKey - prepareSteps = append(prepareSteps, steps.ActivateSSHKeyStepListItem()) - - // GitClone - prepareSteps = append(prepareSteps, steps.GitCloneStepListItem()) - - // Script - prepareSteps = append(prepareSteps, steps.ScriptSteplistItem(steps.ScriptDefaultTitle)) - - // CertificateAndProfileInstaller - prepareSteps = append(prepareSteps, steps.CertificateAndProfileInstallerStepListItem()) - - // CocoapodsInstall - prepareSteps = append(prepareSteps, steps.CocoapodsInstallStepListItem()) - - // RecreateUserSchemes - prepareSteps = append(prepareSteps, steps.RecreateUserSchemesStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - })) - // ---------- - - // - // CI steps - ciSteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTestMac - ciSteps = append(ciSteps, steps.XcodeTestMacStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // DeployToBitriseIo - ciSteps = append(ciSteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - // - // Deploy steps - deploySteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) - - // XcodeTestMac - deploySteps = append(deploySteps, steps.XcodeTestMacStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // XcodeArchiveMac - deploySteps = append(deploySteps, steps.XcodeArchiveMacStepListItem([]envmanModels.EnvironmentItemModel{ - envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, - envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, - })) - - // DeployToBitriseIo - deploySteps = append(deploySteps, steps.DeployToBitriseIoStepListItem()) - // ---------- - - config := models.BitriseDataWithCIAndCDWorkflow([]envmanModels.EnvironmentItemModel{}, ciSteps, deploySteps) - data, err := yaml.Marshal(config) - if err != nil { - return models.BitriseConfigMap{}, err - } - - configName := defaultConfigName - bitriseDataMap := models.BitriseConfigMap{} - bitriseDataMap[configName] = string(data) - - return bitriseDataMap, nil + return scanner.CommonDefaultConfigs() } diff --git a/go/src/github.com/bitrise-core/bitrise-init/scanners/scanners.go b/go/src/github.com/bitrise-core/bitrise-init/scanners/scanners.go index ac6ceaab..00fa8575 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/scanners/scanners.go +++ b/go/src/github.com/bitrise-core/bitrise-init/scanners/scanners.go @@ -58,11 +58,11 @@ type ScannerInterface interface { // ActiveScanners ... var ActiveScanners = []ScannerInterface{ - new(ios.Scanner), - new(macos.Scanner), - new(android.Scanner), - new(xamarin.Scanner), - new(fastlane.Scanner), + ios.NewScanner(), + macos.NewScanner(), + android.NewScanner(), + xamarin.NewScanner(), + fastlane.NewScanner(), } func customConfigName() string { diff --git a/go/src/github.com/bitrise-core/bitrise-init/scanners/xamarin/xamarin.go b/go/src/github.com/bitrise-core/bitrise-init/scanners/xamarin/xamarin.go index 871cd98a..6381bda3 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/scanners/xamarin/xamarin.go +++ b/go/src/github.com/bitrise-core/bitrise-init/scanners/xamarin/xamarin.go @@ -292,6 +292,11 @@ type Scanner struct { HasTVOSProject bool } +// NewScanner ... +func NewScanner() *Scanner { + return &Scanner{} +} + // Name ... func (scanner Scanner) Name() string { return scannerName diff --git a/go/src/github.com/bitrise-core/bitrise-init/scanners/xcode/xcode.go b/go/src/github.com/bitrise-core/bitrise-init/scanners/xcode/xcode.go new file mode 100644 index 00000000..1dc01737 --- /dev/null +++ b/go/src/github.com/bitrise-core/bitrise-init/scanners/xcode/xcode.go @@ -0,0 +1,674 @@ +package xcode + +import ( + "fmt" + + "gopkg.in/yaml.v2" + + "path/filepath" + + "github.com/bitrise-core/bitrise-init/models" + "github.com/bitrise-core/bitrise-init/steps" + "github.com/bitrise-core/bitrise-init/utility" + bitriseModels "github.com/bitrise-io/bitrise/models" + envmanModels "github.com/bitrise-io/envman/models" + "github.com/bitrise-io/go-utils/log" + "github.com/bitrise-io/go-utils/pathutil" +) + +const defaultConfigNameFormat = "default-%s-config" + +const ( + projectPathKey = "project_path" + projectPathTitle = "Project (or Workspace) path" + projectPathEnvKey = "BITRISE_PROJECT_PATH" + + schemeKey = "scheme" + schemeTitle = "Scheme name" + schemeEnvKey = "BITRISE_SCHEME" + + carthageCommandKey = "carthage_command" + carthageCommandTitle = "Carthage command to run" +) + +// ProjectType ... +type ProjectType string + +const ( + // ProjectTypeIOS ... + ProjectTypeIOS ProjectType = "ios" + // ProjectTypeMacOS ... + ProjectTypeMacOS ProjectType = "macos" +) + +// ConfigDescriptor ... +type ConfigDescriptor struct { + HasPodfile bool + CarthageCommand string + HasTest bool + MissingSharedSchemes bool + ScannerName string +} + +func (descriptor ConfigDescriptor) String() string { + name := descriptor.ScannerName + "-" + if descriptor.HasPodfile { + name = name + "pod-" + } + if descriptor.CarthageCommand != "" { + name = name + "carthage-" + } + if descriptor.HasTest { + name = name + "test-" + } + if descriptor.MissingSharedSchemes { + name = name + "missing-shared-schemes-" + } + return name + "config" +} + +// Scanner ... +type Scanner struct { + searchDir string + fileList []string + projectFiles []string + configDescriptors []ConfigDescriptor + ProjectType ProjectType +} + +// CommonName ... +func (scanner Scanner) CommonName() string { + return string(scanner.ProjectType) +} + +// CommonDetectPlatform ... +func (scanner *Scanner) CommonDetectPlatform(searchDir string) (bool, error) { + scanner.searchDir = searchDir + + fileList, err := utility.ListPathInDirSortedByComponents(searchDir, true) + if err != nil { + return false, fmt.Errorf("failed to search for files in (%s), error: %s", searchDir, err) + } + scanner.fileList = fileList + + // Search for xcodeproj + log.Infoft("Searching for Xcode project files") + + xcodeprojectFiles, err := utility.FilterPaths(fileList, utility.AllowXcodeProjExtFilter) + if err != nil { + return false, err + } + + log.Printft("%d Xcode project files found", len(xcodeprojectFiles)) + for _, xcodeprojectFile := range xcodeprojectFiles { + log.Printft("- %s", xcodeprojectFile) + } + + if len(xcodeprojectFiles) == 0 { + log.Printft("platform not detected") + return false, nil + } + + log.Infoft("Filter relevant Xcode project files") + + filters := []utility.FilterFunc{ + utility.AllowIsDirectoryFilter, + utility.ForbidEmbeddedWorkspaceRegexpFilter, + utility.ForbidGitDirComponentFilter, + utility.ForbidPodsDirComponentFilter, + utility.ForbidCarthageDirComponentFilter, + utility.ForbidFramworkComponentWithExtensionFilter, + } + + switch scanner.ProjectType { + case ProjectTypeIOS: + filters = append(filters, utility.AllowIphoneosSDKFilter) + case ProjectTypeMacOS: + filters = append(filters, utility.AllowMacosxSDKFilter) + } + + xcodeprojectFiles, err = utility.FilterPaths(xcodeprojectFiles, filters...) + if err != nil { + return false, err + } + + log.Printft("%d Xcode %s project files found", len(xcodeprojectFiles), scanner.CommonName()) + for _, xcodeprojectFile := range xcodeprojectFiles { + log.Printft("- %s", xcodeprojectFile) + } + + if len(xcodeprojectFiles) == 0 { + log.Printft("platform not detected") + return false, nil + } + + scanner.projectFiles = xcodeprojectFiles + + log.Doneft("Platform detected") + + return true, nil +} + +// CommonOptions ... +func (scanner *Scanner) CommonOptions() (models.OptionModel, models.Warnings, error) { + warnings := models.Warnings{} + + projectFiles := scanner.projectFiles + + filters := []utility.FilterFunc{ + utility.AllowIsDirectoryFilter, + utility.ForbidEmbeddedWorkspaceRegexpFilter, + utility.ForbidGitDirComponentFilter, + utility.ForbidPodsDirComponentFilter, + utility.ForbidCarthageDirComponentFilter, + utility.ForbidFramworkComponentWithExtensionFilter, + utility.AllowXCWorkspaceExtFilter, + } + + switch scanner.ProjectType { + case ProjectTypeIOS: + filters = append(filters, utility.AllowIphoneosSDKFilter) + case ProjectTypeMacOS: + filters = append(filters, utility.AllowMacosxSDKFilter) + } + + workspaceFiles, err := utility.FilterPaths(scanner.fileList, filters...) + if err != nil { + return models.OptionModel{}, models.Warnings{}, err + } + + standaloneProjects, workspaces, err := utility.CreateStandaloneProjectsAndWorkspaces(projectFiles, workspaceFiles) + if err != nil { + return models.OptionModel{}, models.Warnings{}, err + } + + // + // Create cocoapods workspace-project mapping + log.Infoft("Searching for Podfiles") + + podfiles, err := utility.FilterPaths(scanner.fileList, + utility.AllowPodfileBaseFilter, + utility.ForbidGitDirComponentFilter, + utility.ForbidPodsDirComponentFilter, + utility.ForbidCarthageDirComponentFilter, + utility.ForbidFramworkComponentWithExtensionFilter) + if err != nil { + return models.OptionModel{}, models.Warnings{}, err + } + + log.Printft("%d Podfiles detected", len(podfiles)) + for _, file := range podfiles { + log.Printft("- %s", file) + } + + for _, podfile := range podfiles { + workspaceProjectMap, err := utility.GetWorkspaceProjectMap(podfile, projectFiles) + if err != nil { + return models.OptionModel{}, models.Warnings{}, err + } + + standaloneProjects, workspaces, err = utility.MergePodWorkspaceProjectMap(workspaceProjectMap, standaloneProjects, workspaces) + if err != nil { + return models.OptionModel{}, models.Warnings{}, err + } + } + // --- + + // + // Carthage + log.Infof("Searching for Cartfile") + + cartfiles, err := utility.FilterPaths(scanner.fileList, + utility.AllowCartfileBaseFilter, + utility.ForbidGitDirComponentFilter, + utility.ForbidPodsDirComponentFilter, + utility.ForbidCarthageDirComponentFilter, + utility.ForbidFramworkComponentWithExtensionFilter) + if err != nil { + return models.OptionModel{}, models.Warnings{}, err + } + + log.Printf("%d Cartfiles detected", len(cartfiles)) + for _, file := range cartfiles { + log.Printft("- %s", file) + } + // ---- + + // + // Analyze projects and workspaces + isXcshareddataGitignored := false + defaultGitignorePth := filepath.Join(scanner.searchDir, ".gitignore") + + if exist, err := pathutil.IsPathExists(defaultGitignorePth); err != nil { + log.Warnf("Failed to check if .gitignore file exists at: %s, error: %s", defaultGitignorePth, err) + } else if exist { + isGitignored, err := utility.FileContains(defaultGitignorePth, "xcshareddata") + if err != nil { + log.Warnf("Failed to check if xcshareddata gitignored, error: %s", err) + } else { + isXcshareddataGitignored = isGitignored + } + } + + for _, project := range standaloneProjects { + log.Infoft("Inspecting standalone project file: %s", project.Pth) + + log.Printft("%d shared schemes detected", len(project.SharedSchemes)) + for _, scheme := range project.SharedSchemes { + log.Printft("- %s", scheme.Name) + } + + if len(project.SharedSchemes) == 0 { + log.Printft("") + log.Errorft("No shared schemes found, adding recreate-user-schemes step...") + log.Errorft("The newly generated schemes may differ from the ones in your project.") + if isXcshareddataGitignored { + log.Errorft("Your gitignore file (%s) contains 'xcshareddata', maybe shared schemes are gitignored?", defaultGitignorePth) + log.Errorft("If not, make sure to share your schemes, to have the expected behaviour.") + } else { + log.Errorft("Make sure to share your schemes, to have the expected behaviour.") + } + log.Printft("") + + message := `No shared schemes found for project: ` + project.Pth + `.` + if isXcshareddataGitignored { + message += ` +Your gitignore file (` + defaultGitignorePth + `) contains 'xcshareddata', maybe shared schemes are gitignored?` + } + message += ` +Automatically generated schemes may differ from the ones in your project. +Make sure to share your schemes for the expected behaviour.` + + warnings = append(warnings, message) + + log.Warnft("%d user schemes will be generated", len(project.Targets)) + for _, target := range project.Targets { + log.Warnft("- %s", target.Name) + } + } + } + + for _, workspace := range workspaces { + log.Infoft("Inspecting workspace file: %s", workspace.Pth) + + sharedSchemes := workspace.GetSharedSchemes() + log.Printft("%d shared schemes detected", len(sharedSchemes)) + for _, scheme := range sharedSchemes { + log.Printft("- %s", scheme.Name) + } + + if len(sharedSchemes) == 0 { + log.Printft("") + log.Errorft("No shared schemes found, adding recreate-user-schemes step...") + log.Errorft("The newly generated schemes may differ from the ones in your project.") + if isXcshareddataGitignored { + log.Errorft("Your gitignore file (%s) contains 'xcshareddata', maybe shared schemes are gitignored?", defaultGitignorePth) + log.Errorft("If not, make sure to share your schemes, to have the expected behaviour.") + } else { + log.Errorft("Make sure to share your schemes, to have the expected behaviour.") + } + log.Printft("") + + message := `No shared schemes found for project: ` + workspace.Pth + `.` + if isXcshareddataGitignored { + message += ` +Your gitignore file (` + defaultGitignorePth + `) (%s) contains 'xcshareddata', maybe shared schemes are gitignored?` + } + message += ` +Automatically generated schemes may differ from the ones in your project. +Make sure to share your schemes for the expected behaviour.` + + warnings = append(warnings, message) + + targets := workspace.GetTargets() + log.Warnft("%d user schemes will be generated", len(targets)) + for _, target := range targets { + log.Warnft("- %s", target.Name) + } + } + } + // ----- + + // + // Create config descriptors + configDescriptors := []ConfigDescriptor{} + projectPathOption := models.NewOptionModel(projectPathTitle, projectPathEnvKey) + + // Add Standalon Project options + for _, project := range standaloneProjects { + schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) + + carthageCommand := "" + if utility.HasCartfileInDirectoryOf(project.Pth) { + if utility.HasCartfileResolvedInDirectoryOf(project.Pth) { + carthageCommand = "bootstrap" + } else { + dir := filepath.Dir(project.Pth) + cartfilePth := filepath.Join(dir, "Cartfile") + + warnings = append(warnings, fmt.Sprintf(`Cartfile found at (%s), but no Cartfile.resolved exists in the same directory. +It is strongly recommended to commit this file to your repository`, cartfilePth)) + + carthageCommand = "update" + } + } + + if len(project.SharedSchemes) == 0 { + for _, target := range project.Targets { + configDescriptor := ConfigDescriptor{ + HasPodfile: false, + CarthageCommand: carthageCommand, + HasTest: target.HasXCTest, + MissingSharedSchemes: true, + ScannerName: scanner.CommonName(), + } + configDescriptors = append(configDescriptors, configDescriptor) + + configOption := models.NewEmptyOptionModel() + configOption.Config = configDescriptor.String() + + schemeOption.ValueMap[target.Name] = configOption + } + } else { + for _, scheme := range project.SharedSchemes { + configDescriptor := ConfigDescriptor{ + HasPodfile: false, + CarthageCommand: carthageCommand, + HasTest: scheme.HasXCTest, + MissingSharedSchemes: false, + ScannerName: scanner.CommonName(), + } + configDescriptors = append(configDescriptors, configDescriptor) + + configOption := models.NewEmptyOptionModel() + configOption.Config = configDescriptor.String() + + schemeOption.ValueMap[scheme.Name] = configOption + } + } + + projectPathOption.ValueMap[project.Pth] = schemeOption + } + + // Add Workspace options + for _, workspace := range workspaces { + schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) + + carthageCommand := "" + if utility.HasCartfileInDirectoryOf(workspace.Pth) { + if utility.HasCartfileResolvedInDirectoryOf(workspace.Pth) { + carthageCommand = "bootstrap" + } else { + dir := filepath.Dir(workspace.Pth) + cartfilePth := filepath.Join(dir, "Cartfile") + + warnings = append(warnings, fmt.Sprintf(`Cartfile found at (%s), but no Cartfile.resolved exists in the same directory. +It is strongly recommended to commit this file to your repository`, cartfilePth)) + + carthageCommand = "update" + } + } + + sharedSchemes := workspace.GetSharedSchemes() + if len(sharedSchemes) == 0 { + targets := workspace.GetTargets() + for _, target := range targets { + configDescriptor := ConfigDescriptor{ + HasPodfile: workspace.IsPodWorkspace, + CarthageCommand: carthageCommand, + HasTest: target.HasXCTest, + MissingSharedSchemes: true, + ScannerName: scanner.CommonName(), + } + configDescriptors = append(configDescriptors, configDescriptor) + + configOption := models.NewEmptyOptionModel() + configOption.Config = configDescriptor.String() + + schemeOption.ValueMap[target.Name] = configOption + } + } else { + for _, scheme := range sharedSchemes { + configDescriptor := ConfigDescriptor{ + HasPodfile: workspace.IsPodWorkspace, + CarthageCommand: carthageCommand, + HasTest: scheme.HasXCTest, + MissingSharedSchemes: false, + ScannerName: scanner.CommonName(), + } + configDescriptors = append(configDescriptors, configDescriptor) + + configOption := models.NewEmptyOptionModel() + configOption.Config = configDescriptor.String() + + schemeOption.ValueMap[scheme.Name] = configOption + } + } + + projectPathOption.ValueMap[workspace.Pth] = schemeOption + } + // ----- + + if len(configDescriptors) == 0 { + log.Errorft("No valid %s config found", scanner.CommonName()) + return models.OptionModel{}, warnings, fmt.Errorf("No valid %s config found", scanner.CommonName()) + } + + scanner.configDescriptors = configDescriptors + + return projectPathOption, warnings, nil +} + +// CommonDefaultOptions ... +func (scanner *Scanner) CommonDefaultOptions() models.OptionModel { + configOption := models.NewEmptyOptionModel() + configOption.Config = fmt.Sprintf(defaultConfigNameFormat, scanner.CommonName()) + + projectPathOption := models.NewOptionModel(projectPathTitle, projectPathEnvKey) + schemeOption := models.NewOptionModel(schemeTitle, schemeEnvKey) + + schemeOption.ValueMap["_"] = configOption + projectPathOption.ValueMap["_"] = schemeOption + + return projectPathOption +} + +func (scanner *Scanner) generateConfig(hasPodfile, hasTest, missingSharedSchemes bool, carthageCommand string) bitriseModels.BitriseDataModel { + // + // Prepare steps + prepareSteps := []bitriseModels.StepListItemModel{} + + // ActivateSSHKey + prepareSteps = append(prepareSteps, steps.ActivateSSHKeyStepListItem()) + + // GitClone + prepareSteps = append(prepareSteps, steps.GitCloneStepListItem()) + + // Script + prepareSteps = append(prepareSteps, steps.ScriptSteplistItem(steps.ScriptDefaultTitle)) + + // CertificateAndProfileInstaller + prepareSteps = append(prepareSteps, steps.CertificateAndProfileInstallerStepListItem()) + + // CocoapodsInstall + if hasPodfile { + prepareSteps = append(prepareSteps, steps.CocoapodsInstallStepListItem()) + } + + // Carthage + if carthageCommand != "" { + prepareSteps = append(prepareSteps, steps.CarthageStepListItem([]envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{carthageCommandKey: carthageCommand}, + })) + } + + // RecreateUserSchemes + if missingSharedSchemes { + prepareSteps = append(prepareSteps, steps.RecreateUserSchemesStepListItem([]envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, + })) + } + // ---------- + + xcodeTestAndArchiveStepInputModels := []envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, + envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, + } + + // + // CI steps + ciSteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) + + // XcodeTest + if hasTest { + switch scanner.ProjectType { + case ProjectTypeIOS: + ciSteps = append(ciSteps, steps.XcodeTestStepListItem(xcodeTestAndArchiveStepInputModels)) + case ProjectTypeMacOS: + ciSteps = append(ciSteps, steps.XcodeTestMacStepListItem(xcodeTestAndArchiveStepInputModels)) + } + } + + // DeployToBitriseIo + ciSteps = append(ciSteps, steps.DeployToBitriseIoStepListItem()) + // ---------- + + // + // Deploy steps + deploySteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) + + // XcodeTest + if hasTest { + switch scanner.ProjectType { + case ProjectTypeIOS: + deploySteps = append(deploySteps, steps.XcodeTestStepListItem(xcodeTestAndArchiveStepInputModels)) + case ProjectTypeMacOS: + deploySteps = append(deploySteps, steps.XcodeTestMacStepListItem(xcodeTestAndArchiveStepInputModels)) + } + } + + // XcodeArchive + switch scanner.ProjectType { + case ProjectTypeIOS: + deploySteps = append(deploySteps, steps.XcodeArchiveStepListItem(xcodeTestAndArchiveStepInputModels)) + case ProjectTypeMacOS: + deploySteps = append(deploySteps, steps.XcodeArchiveMacStepListItem(xcodeTestAndArchiveStepInputModels)) + } + + // DeployToBitriseIo + deploySteps = append(deploySteps, steps.DeployToBitriseIoStepListItem()) + // ---------- + + return models.BitriseDataWithCIAndCDWorkflow([]envmanModels.EnvironmentItemModel{}, ciSteps, deploySteps) +} + +// CommonConfigs ... +func (scanner *Scanner) CommonConfigs() (models.BitriseConfigMap, error) { + descriptors := []ConfigDescriptor{} + descritorNameMap := map[string]bool{} + + for _, descriptor := range scanner.configDescriptors { + _, exist := descritorNameMap[descriptor.String()] + if !exist { + descriptors = append(descriptors, descriptor) + } + } + + bitriseDataMap := models.BitriseConfigMap{} + for _, descriptor := range descriptors { + configName := descriptor.String() + bitriseData := scanner.generateConfig(descriptor.HasPodfile, descriptor.HasTest, descriptor.MissingSharedSchemes, descriptor.CarthageCommand) + data, err := yaml.Marshal(bitriseData) + if err != nil { + return models.BitriseConfigMap{}, err + } + bitriseDataMap[configName] = string(data) + } + + return bitriseDataMap, nil +} + +// CommonDefaultConfigs ... +func (scanner *Scanner) CommonDefaultConfigs() (models.BitriseConfigMap, error) { + // + // Prepare steps + prepareSteps := []bitriseModels.StepListItemModel{} + + // ActivateSSHKey + prepareSteps = append(prepareSteps, steps.ActivateSSHKeyStepListItem()) + + // GitClone + prepareSteps = append(prepareSteps, steps.GitCloneStepListItem()) + + // Script + prepareSteps = append(prepareSteps, steps.ScriptSteplistItem(steps.ScriptDefaultTitle)) + + // CertificateAndProfileInstaller + prepareSteps = append(prepareSteps, steps.CertificateAndProfileInstallerStepListItem()) + + // CocoapodsInstall + prepareSteps = append(prepareSteps, steps.CocoapodsInstallStepListItem()) + + // RecreateUserSchemes + prepareSteps = append(prepareSteps, steps.RecreateUserSchemesStepListItem([]envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, + })) + // ---------- + + // + // CI steps + ciSteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) + + xcodeTestAndArchiveStepInputModels := []envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{projectPathKey: "$" + projectPathEnvKey}, + envmanModels.EnvironmentItemModel{schemeKey: "$" + schemeEnvKey}, + } + + // XcodeTest + switch scanner.ProjectType { + case ProjectTypeIOS: + ciSteps = append(ciSteps, steps.XcodeTestStepListItem(xcodeTestAndArchiveStepInputModels)) + case ProjectTypeMacOS: + ciSteps = append(ciSteps, steps.XcodeTestMacStepListItem(xcodeTestAndArchiveStepInputModels)) + } + + // DeployToBitriseIo + ciSteps = append(ciSteps, steps.DeployToBitriseIoStepListItem()) + // ---------- + + // + // Deploy steps + deploySteps := append([]bitriseModels.StepListItemModel{}, prepareSteps...) + + // XcodeTest + switch scanner.ProjectType { + case ProjectTypeIOS: + deploySteps = append(deploySteps, steps.XcodeTestStepListItem(xcodeTestAndArchiveStepInputModels)) + case ProjectTypeMacOS: + deploySteps = append(deploySteps, steps.XcodeTestMacStepListItem(xcodeTestAndArchiveStepInputModels)) + } + + // XcodeArchive + switch scanner.ProjectType { + case ProjectTypeIOS: + deploySteps = append(deploySteps, steps.XcodeArchiveStepListItem(xcodeTestAndArchiveStepInputModels)) + case ProjectTypeMacOS: + deploySteps = append(deploySteps, steps.XcodeArchiveMacStepListItem(xcodeTestAndArchiveStepInputModels)) + } + + // DeployToBitriseIo + deploySteps = append(deploySteps, steps.DeployToBitriseIoStepListItem()) + // ---------- + + config := models.BitriseDataWithCIAndCDWorkflow([]envmanModels.EnvironmentItemModel{}, ciSteps, deploySteps) + data, err := yaml.Marshal(config) + if err != nil { + return models.BitriseConfigMap{}, err + } + + configName := fmt.Sprintf(defaultConfigNameFormat, scanner.CommonName()) + bitriseDataMap := models.BitriseConfigMap{} + bitriseDataMap[configName] = string(data) + + return bitriseDataMap, nil +} diff --git a/go/src/github.com/bitrise-core/bitrise-init/steps/steps.go b/go/src/github.com/bitrise-core/bitrise-init/steps/steps.go index 3cb925ed..e4876255 100644 --- a/go/src/github.com/bitrise-core/bitrise-init/steps/steps.go +++ b/go/src/github.com/bitrise-core/bitrise-init/steps/steps.go @@ -18,17 +18,17 @@ const ( // GitCloneID ... GitCloneID = "git-clone" // GitCloneVersion ... - GitCloneVersion = "3.4.1" + GitCloneVersion = "3.4.2" // CertificateAndProfileInstallerID ... CertificateAndProfileInstallerID = "certificate-and-profile-installer" // CertificateAndProfileInstallerVersion ... - CertificateAndProfileInstallerVersion = "1.8.2" + CertificateAndProfileInstallerVersion = "1.8.4" // DeployToBitriseIoID ... DeployToBitriseIoID = "deploy-to-bitrise-io" // DeployToBitriseIoVersion ... - DeployToBitriseIoVersion = "1.2.7" + DeployToBitriseIoVersion = "1.2.9" // ScriptID ... ScriptID = "script" @@ -54,7 +54,7 @@ const ( // FastlaneID ... FastlaneID = "fastlane" // FastlaneVersion ... - FastlaneVersion = "2.3.3" + FastlaneVersion = "2.3.7" // iOS Steps @@ -66,7 +66,7 @@ const ( // CarthageID ... CarthageID = "carthage" // CarthageVersion ... - CarthageVersion = "3.0.5" + CarthageVersion = "3.0.6" // RecreateUserSchemesID ... RecreateUserSchemesID = "recreate-user-schemes" @@ -76,7 +76,7 @@ const ( // XcodeArchiveID ... XcodeArchiveID = "xcode-archive" // XcodeArchiveVersion ... - XcodeArchiveVersion = "2.0.4" + XcodeArchiveVersion = "2.0.5" // XcodeTestID ... XcodeTestID = "xcode-test" @@ -103,19 +103,19 @@ const ( // XamarinArchiveID ... XamarinArchiveID = "xamarin-archive" // XamarinArchiveVersion ... - XamarinArchiveVersion = "1.3.1" + XamarinArchiveVersion = "1.3.2" // macOS Setps // XcodeArchiveMacID ... XcodeArchiveMacID = "xcode-archive-mac" // XcodeArchiveMacVersion ... - XcodeArchiveMacVersion = "1.3.3" + XcodeArchiveMacVersion = "1.4.0" // XcodeTestMacID ... XcodeTestMacID = "xcode-test-mac" // XcodeTestMacVersion ... - XcodeTestMacVersion = "1.0.6" + XcodeTestMacVersion = "1.1.0" ) func stepIDComposite(ID, version string) string {