diff --git a/test/converters/xcresult3/xcresulttool.go b/test/converters/xcresult3/xcresulttool.go index f75c21c9..792b49b1 100644 --- a/test/converters/xcresult3/xcresulttool.go +++ b/test/converters/xcresult3/xcresulttool.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "os/exec" + "regexp" + "strconv" "github.com/bitrise-io/go-utils/command" "github.com/bitrise-io/go-utils/errorutil" @@ -16,6 +18,32 @@ func isXcresulttoolAvailable() bool { return command.New("xcrun", "--find", "xcresulttool").Run() == nil } +func isLegacyFlagNeededForXcresulttoolVersion() (bool, error) { + args := []string{"xcresulttool", "version"} + cmd := command.New("xcrun", args...) + out, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + if errorutil.IsExitStatusError(err) { + return true, fmt.Errorf("%s failed: %s", cmd.PrintableCommandArgs(), out) + } + return true, fmt.Errorf("%s failed: %s", cmd.PrintableCommandArgs(), err) + } + // xcresulttool version 23025, format version 3.53 (current) + versionRegexp := regexp.MustCompile("xcresulttool version ([0-9]+)") + + matches := versionRegexp.FindStringSubmatch(out) + if len(matches) < 2 { + return true, fmt.Errorf("no version matches found in output: %s", out) + } + + version, err := strconv.Atoi(matches[1]) + if err != nil { + return true, fmt.Errorf("failed to convert version: %s", matches[1]) + } + + return version >= 23_021, nil // Xcode 16 beta3 has version 23021 +} + // xcresulttoolGet performs xcrun xcresulttool get with --id flag defined if id provided and marshals the output into v. func xcresulttoolGet(xcresultPth, id string, v interface{}) error { args := []string{"xcresulttool", "get", "--format", "json", "--path", xcresultPth} @@ -23,6 +51,14 @@ func xcresulttoolGet(xcresultPth, id string, v interface{}) error { args = append(args, "--id", id) } + isLegacyFlag, err := isLegacyFlagNeededForXcresulttoolVersion() + if err != nil { + return err + } + if isLegacyFlag { + args = append(args, "--legacy") + } + cmd := command.New("xcrun", args...) out, err := cmd.RunAndReturnTrimmedCombinedOutput() if err != nil { @@ -40,6 +76,14 @@ func xcresulttoolGet(xcresultPth, id string, v interface{}) error { // xcresulttoolExport exports a file with the given id at the given output path. func xcresulttoolExport(xcresultPth, id, outputPth string) error { args := []string{"xcresulttool", "export", "--path", xcresultPth, "--id", id, "--output-path", outputPth, "--type", "file"} + isLegacyFlag, err := isLegacyFlagNeededForXcresulttoolVersion() + if err != nil { + return err + } + if isLegacyFlag { + args = append(args, "--legacy") + } + cmd := command.New("xcrun", args...) out, err := cmd.RunAndReturnTrimmedCombinedOutput() if err != nil {