From f7a6d87a10e5e529be99dec9830e2fc2cff85901 Mon Sep 17 00:00:00 2001 From: lpusok <7979773+lpusok@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:19:40 +0200 Subject: [PATCH] [SWAT-784] Workaround for iTMSTransporter 3.0+fastlane (#126) * Workaround for iTMSTransporter 3.0+fastlane * Check Xcode version, do not add Transporter params on Xcode 14 --- main.go | 18 +++++-- .../bitrise-io/go-xcode/models/models.go | 8 +++ .../bitrise-io/go-xcode/utility/path.go | 39 ++++++++++++++ .../bitrise-io/go-xcode/utility/utility.go | 51 +++++++++++++++++++ vendor/modules.txt | 2 + 5 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 vendor/github.com/bitrise-io/go-xcode/models/models.go create mode 100644 vendor/github.com/bitrise-io/go-xcode/utility/path.go create mode 100644 vendor/github.com/bitrise-io/go-xcode/utility/utility.go diff --git a/main.go b/main.go index 307af33..e5f1670 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ import ( "github.com/bitrise-io/go-utils/retry" "github.com/bitrise-io/go-xcode/appleauth" "github.com/bitrise-io/go-xcode/devportalservice" + "github.com/bitrise-io/go-xcode/utility" "github.com/kballard/go-shellquote" ) @@ -385,15 +386,22 @@ alphanumeric characters.`) options = opts } - envs := []string{} - if cfg.ITMSParameters != "" { - envs = append(envs, "DELIVER_ITMSTRANSPORTER_ADDITIONAL_UPLOAD_PARAMETERS="+cfg.ITMSParameters) + version, err := utility.GetXcodeVersion() + if err != nil { + fail("Failed to read Xcode version: %w", err) } - args := []string{ - "deliver", + envs := []string{} + // Xcode 14 and above fastlane uses altool to upload + if version.MajorVersion < 14 { + envs = append(envs, "ITMSTRANSPORTER_FORCE_ITMS_PACKAGE_UPLOAD=true") + if cfg.ITMSParameters != "" { + envs = append(envs, "DELIVER_ITMSTRANSPORTER_ADDITIONAL_UPLOAD_PARAMETERS="+cfg.ITMSParameters) + } } + args := []string{"deliver"} + authParams, err := FastlaneAuthParams(authConfig) if err != nil { fail("Failed to set up Fastlane authentication paramteres: %v", err) diff --git a/vendor/github.com/bitrise-io/go-xcode/models/models.go b/vendor/github.com/bitrise-io/go-xcode/models/models.go new file mode 100644 index 0000000..42ea372 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-xcode/models/models.go @@ -0,0 +1,8 @@ +package models + +// XcodebuildVersionModel ... +type XcodebuildVersionModel struct { + Version string + BuildVersion string + MajorVersion int64 +} diff --git a/vendor/github.com/bitrise-io/go-xcode/utility/path.go b/vendor/github.com/bitrise-io/go-xcode/utility/path.go new file mode 100644 index 0000000..99db913 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-xcode/utility/path.go @@ -0,0 +1,39 @@ +package utility + +import ( + "fmt" + "path/filepath" + + "github.com/bitrise-io/go-utils/pathutil" +) + +// FindFileInAppDir ... +func FindFileInAppDir(appDir, fileName string) (string, error) { + filePth := filepath.Join(appDir, fileName) + if exist, err := pathutil.IsPathExists(filePth); err != nil { + return "", err + } else if exist { + return filePth, nil + } + // --- + + // It's somewhere else - let's find it! + apps, err := pathutil.ListEntries(appDir, pathutil.ExtensionFilter(".app", true)) + if err != nil { + return "", err + } + + for _, app := range apps { + pths, err := pathutil.ListEntries(app, pathutil.BaseFilter(fileName, true)) + if err != nil { + return "", err + } + + if len(pths) > 0 { + return pths[0], nil + } + } + // --- + + return "", fmt.Errorf("failed to find %s", fileName) +} diff --git a/vendor/github.com/bitrise-io/go-xcode/utility/utility.go b/vendor/github.com/bitrise-io/go-xcode/utility/utility.go new file mode 100644 index 0000000..5d605c5 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-xcode/utility/utility.go @@ -0,0 +1,51 @@ +package utility + +import ( + "fmt" + "strconv" + "strings" + + "github.com/bitrise-io/go-utils/command" + "github.com/bitrise-io/go-xcode/models" +) + +func getXcodeVersionFromXcodebuildOutput(outStr string) (models.XcodebuildVersionModel, error) { + split := strings.Split(outStr, "\n") + if len(split) == 0 { + return models.XcodebuildVersionModel{}, fmt.Errorf("failed to parse xcodebuild version output (%s)", outStr) + } + + xcodebuildVersion := split[0] + buildVersion := split[1] + + split = strings.Split(xcodebuildVersion, " ") + if len(split) != 2 { + return models.XcodebuildVersionModel{}, fmt.Errorf("failed to parse xcodebuild version output (%s)", outStr) + } + + version := split[1] + + split = strings.Split(version, ".") + majorVersionStr := split[0] + + majorVersion, err := strconv.ParseInt(majorVersionStr, 10, 32) + if err != nil { + return models.XcodebuildVersionModel{}, fmt.Errorf("failed to parse xcodebuild version output (%s), error: %s", outStr, err) + } + + return models.XcodebuildVersionModel{ + Version: xcodebuildVersion, + BuildVersion: buildVersion, + MajorVersion: majorVersion, + }, nil +} + +// GetXcodeVersion ... +func GetXcodeVersion() (models.XcodebuildVersionModel, error) { + cmd := command.New("xcodebuild", "-version") + outStr, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + return models.XcodebuildVersionModel{}, fmt.Errorf("xcodebuild -version failed, err: %s, details: %s", err, outStr) + } + return getXcodeVersionFromXcodebuildOutput(outStr) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8aff1e2..e6ad710 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -19,6 +19,8 @@ github.com/bitrise-io/go-utils/retry ## explicit github.com/bitrise-io/go-xcode/appleauth github.com/bitrise-io/go-xcode/devportalservice +github.com/bitrise-io/go-xcode/models +github.com/bitrise-io/go-xcode/utility # github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew/spew # github.com/hashicorp/go-cleanhttp v0.5.2