Skip to content

Commit

Permalink
Remove pre-Xcode-13 code (#251)
Browse files Browse the repository at this point in the history
* Remove pre-Xcode-13 code

* *

* Cleanup tests

* Remove unused code

* Remove should_retry_test_on_fail input

* Remove failing Rosetta tests

* Update readme
  • Loading branch information
ofalvai authored Nov 12, 2024
1 parent c0241be commit 78e2150
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 258 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Run tests with custom xcconfig file path:
| `test_repetition_mode` | Determines how the tests will repeat. Available options: - `none`: Tests will never repeat. - `until_failure`: Tests will repeat until failure or up to maximum repetitions. - `retry_on_failure`: Only failed tests will repeat up to maximum repetitions. - `up_until_maximum_repetitions`: Tests will repeat up until maximum repetitions. The input value together with Maximum Test Repetitions (`maximum_test_repetitions`) input sets xcodebuild's `-run-tests-until-failure` / `-retry-tests-on-failure` or `-test-iterations` option. | | `none` |
| `maximum_test_repetitions` | The maximum number of times a test repeats based on the Test Repetition Mode (`test_repetition_mode`). Should be more than 1 if the Test Repetition Mode is other than `none`. The input value sets xcodebuild's `-test-iterations` option. | required | `3` |
| `relaunch_tests_for_each_repetition` | If this input is set, tests will launch in a new process for each repetition. By default, tests launch in the same process for each repetition. The input value sets xcodebuild's `-test-repetition-relaunch-enabled` option. | | `no` |
| `should_retry_test_on_fail` | If this input is set, the Step will rerun the tests in the case of failed tests. Note that all the tests will be rerun, not just the ones that failed. This input is not available if you are using Xcode 13+. In that case, we recommend using the `retry_on_failure` Test Repetition Mode (`test_repetition_mode`). | required | `no` |
| `xcconfig_content` | Build settings to override the project's build settings, using xcodebuild's `-xcconfig` option. You can't define `-xcconfig` option in `Additional options for the xcodebuild command` if this input is set. If empty, no setting is changed. When set it can be either: 1. Existing `.xcconfig` file path. Example: `./ios-sample/ios-sample/Configurations/Dev.xcconfig` 2. The contents of a newly created temporary `.xcconfig` file. (This is the default.) Build settings must be separated by newline character (`\n`). Example: ``` COMPILER_INDEX_STORE_ENABLE = NO ONLY_ACTIVE_ARCH[config=Debug][sdk=*][arch=*] = YES ``` | | `COMPILER_INDEX_STORE_ENABLE = NO` |
| `perform_clean_action` | If this input is set, `clean` xcodebuild action will be performed besides the `test` action. | required | `no` |
| `xcodebuild_options` | Additional options to be added to the executed xcodebuild command. Prefer using `Build settings (xcconfig)` input for specifying `-xcconfig` option. You can't use both. | | |
Expand Down
85 changes: 0 additions & 85 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,12 @@ workflows:
- TEST_PLAN: ""
- DESTINATION: platform=iOS Simulator,name=Bitrise iOS default,OS=latest
- LOG_FORMATTER: xcbeautify
- RETRY_ON_FAILURE: "no"
- EXPECT_TEST_FAILURE: "false"
- CACHE_LEVEL: swift_packages
after_run:
- _run
- _check_outputs

test_rosetta_simulator:
description: Rosetta Simulator requires Xcode 14.3+.
steps:
- bitrise-run:
run_if: |-
{{ or (enveq "IS_LATEST_STACK_XCODE" "true") (not .IsCI) }}
inputs:
- workflow_id: utility_test_rosetta_simulator
- bitrise_config_path: ./e2e/bitrise.yml

utility_test_rosetta_simulator:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/Bitrise-iOS-x86-Framework-Sample.git
- TEST_APP_BRANCH: main
- BITRISE_PROJECT_PATH: Bitrise-iOS-x86-Framework-Sample.xcworkspace
- BITRISE_SCHEME: Bitrise-iOS-x86-Framework-Sample
- TEST_PLAN: ""
- DESTINATION: platform=iOS Simulator,name=iPhone 11,OS=latest,arch=x86_64
- LOG_FORMATTER: xcbeautify
- RETRY_ON_FAILURE: "no"
- EXPECT_TEST_FAILURE: "false"
- CACHE_LEVEL: none
- COLLECT_SIM_DIAGNOSTICS: never
after_run:
- _run
- _check_outputs

test_rosetta_simulator_failure:
description: Rosetta Simulator requires Xcode 14.3+.
steps:
- bitrise-run:
run_if: |-
{{ or (enveq "IS_LATEST_STACK_XCODE" "true") (not .IsCI) }}
is_skippable: true
inputs:
- workflow_id: utility_test_rosetta_simulator_failure
- bitrise_config_path: ./e2e/bitrise.yml

utility_test_rosetta_simulator_failure:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/Bitrise-iOS-x86-Framework-Sample.git
- TEST_APP_BRANCH: main
- BITRISE_PROJECT_PATH: Bitrise-iOS-x86-Framework-Sample.xcworkspace
- BITRISE_SCHEME: Bitrise-iOS-x86-Framework-Sample
- TEST_PLAN: ""
- DESTINATION: platform=iOS Simulator,name=iPhone 11,OS=latest
- LOG_FORMATTER: xcbeautify
- RETRY_ON_FAILURE: "no"
- EXPECT_TEST_FAILURE: "true"
- CACHE_LEVEL: none
- COLLECT_SIM_DIAGNOSTICS: never
after_run:
- _run
- _check_outputs

test_objc_xcpretty:
envs:
- TEST_APP_URL: https://github.com/bitrise-io/sample-apps-ios-simple-objc-with-uitest.git
Expand All @@ -82,7 +26,6 @@ workflows:
- TEST_PLAN: ""
- DESTINATION: platform=iOS Simulator,name=Bitrise iOS default,OS=latest
- LOG_FORMATTER: xcpretty
- RETRY_ON_FAILURE: "no"
- EXPECT_TEST_FAILURE: "false"
- CACHE_LEVEL: none
after_run:
Expand All @@ -101,7 +44,6 @@ workflows:
- TEST_PLAN: UnitTests
- DESTINATION: platform=iOS Simulator,name=iPhone 12,OS=latest
- LOG_FORMATTER: xcbeautify
- RETRY_ON_FAILURE: "no"
- EXPECT_TEST_FAILURE: "false"
- CACHE_LEVEL: swift_packages
after_run:
Expand All @@ -118,7 +60,6 @@ workflows:
- TEST_PLAN: ""
- DESTINATION: platform=iOS Simulator,name=Bitrise iOS default,OS=latest
- LOG_FORMATTER: xcodebuild
- RETRY_ON_FAILURE: "no"
- EXPECT_TEST_FAILURE: "false"
- CACHE_LEVEL: none
- XCCONFIG_CONTENT: ./_tmp2/p.xcconfig
Expand Down Expand Up @@ -202,35 +143,9 @@ workflows:
- perform_clean_action: "yes"
- xcodebuild_options: -verbose
- verbose_log: "yes"
- should_retry_test_on_fail: $RETRY_ON_FAILURE
- cache_level: $CACHE_LEVEL
- collect_simulator_diagnostics: $COLLECT_SIM_DIAGNOSTICS

_expose_xcode_version:
steps:
- script:
title: Expose Xcode major version
inputs:
- content: |-
#!/bin/env bash
set -e
if [[ ! -z "$XCODE_MAJOR_VERSION" ]]; then
echo "Xcode major version already exposed: $XCODE_MAJOR_VERSION"
exit 0
fi
version=`xcodebuild -version`
regex="Xcode ([0-9]*)."
if [[ ! $version =~ $regex ]]; then
echo "Failed to determine Xcode major version"
exit 1
fi
xcode_major_version=${BASH_REMATCH[1]}
echo "Xcode major version: $xcode_major_version"
envman add --key XCODE_MAJOR_VERSION --value $xcode_major_version
_clear_outputs:
steps:
- script:
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func createConfigParser(logger log.Logger) step.XcodeTestConfigParser {
deviceFinder := destination.NewDeviceFinder(logger, commandFactory, xcodeVersion)
utils := step.NewUtils(logger)

return step.NewXcodeTestConfigParser(inputParser, logger, xcodeVersion, deviceFinder, pathModifier, utils)
return step.NewXcodeTestConfigParser(inputParser, logger, deviceFinder, pathModifier, utils)
}

func createStep(logger log.Logger, logFormatter string) (step.XcodeTestRunner, error) {
Expand Down
22 changes: 3 additions & 19 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ inputs:
- test_repetition_mode: none
opts:
category: Test Repetition
title: Test Repetition Mode (Available in Xcode 13+)
title: Test Repetition Mode
summary: Determines how the tests will repeat.
description: |-
Determines how the tests will repeat.
Expand All @@ -114,7 +114,7 @@ inputs:
- maximum_test_repetitions: 3
opts:
category: Test Repetition
title: Maximum Test Repetitions (Available in Xcode 13+)
title: Maximum Test Repetitions
summary: The maximum number of times a test repeats based on the Test Repetition Mode (`test_repetition_mode`).
description: |-
The maximum number of times a test repeats based on the Test Repetition Mode (`test_repetition_mode`).
Expand All @@ -126,7 +126,7 @@ inputs:

- relaunch_tests_for_each_repetition: "no"
opts:
title: Relaunch Tests for Each Repetition (Available in Xcode 13+)
title: Relaunch Tests for Each Repetition
category: Test Repetition
summary: If this input is set, tests will launch in a new process for each repetition.
description: |-
Expand All @@ -139,22 +139,6 @@ inputs:
- "yes"
- "no"

- should_retry_test_on_fail: "no"
opts:
category: Test Repetition
title: Should retry tests on failure? (Not available in Xcode 13+)
summary: If set, the Step will rerun the tests in the case of failed tests.
description: |-
If this input is set, the Step will rerun the tests in the case of failed tests.
Note that all the tests will be rerun, not just the ones that failed.
This input is not available if you are using Xcode 13+. In that case, we recommend using the `retry_on_failure` Test Repetition Mode (`test_repetition_mode`).
value_options:
- "yes"
- "no"
is_required: true

# xcodebuild configuration

- xcconfig_content: COMPILER_INDEX_STORE_ENABLE = NO
Expand Down
42 changes: 2 additions & 40 deletions step/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/bitrise-io/go-xcode/v2/simulator"
cache "github.com/bitrise-io/go-xcode/v2/xcodecache"
"github.com/bitrise-io/go-xcode/v2/xcodecommand"
"github.com/bitrise-io/go-xcode/v2/xcodeversion"
"github.com/bitrise-steplib/steps-xcode-test/output"
"github.com/bitrise-steplib/steps-xcode-test/xcodebuild"
"github.com/kballard/go-shellquote"
Expand All @@ -37,7 +36,6 @@ type Input struct {
TestRepetitionMode string `env:"test_repetition_mode,opt[none,until_failure,retry_on_failure,up_until_maximum_repetitions]"`
MaximumTestRepetitions int `env:"maximum_test_repetitions,required"`
RelaunchTestsForEachRepetition bool `env:"relaunch_tests_for_each_repetition,opt[yes,no]"`
RetryTestsOnFailure bool `env:"should_retry_test_on_fail,opt[yes,no]"`

// xcodebuild configuration
XCConfigContent string `env:"xcconfig_content"`
Expand Down Expand Up @@ -76,7 +74,6 @@ const (
XcprettyTool = "xcpretty"
)

// Config ...
type Config struct {
ProjectPath string
Scheme string
Expand All @@ -85,12 +82,9 @@ type Config struct {
Simulator destination.Device
IsSimulatorBooted bool

XcodeMajorVersion int

TestRepetitionMode string
MaximumTestRepetitions int
RelaunchTestForEachRepetition bool
RetryTestsOnFailure bool

XCConfigContent string
PerformCleanAction bool
Expand All @@ -110,24 +104,21 @@ type Config struct {
type XcodeTestConfigParser struct {
logger log.Logger
inputParser stepconf.InputParser
xcodeVersion xcodeversion.Version
deviceFinder destination.DeviceFinder
pathModifier pathutil.PathModifier
utils Utils
}

func NewXcodeTestConfigParser(inputParser stepconf.InputParser, logger log.Logger, xcodeVersion xcodeversion.Version, deviceFinder destination.DeviceFinder, pathModifier pathutil.PathModifier, utils Utils) XcodeTestConfigParser {
func NewXcodeTestConfigParser(inputParser stepconf.InputParser, logger log.Logger, deviceFinder destination.DeviceFinder, pathModifier pathutil.PathModifier, utils Utils) XcodeTestConfigParser {
return XcodeTestConfigParser{
logger: logger,
inputParser: inputParser,
xcodeVersion: xcodeVersion,
deviceFinder: deviceFinder,
pathModifier: pathModifier,
utils: utils,
}
}

// XcodeTestRunner ...
type XcodeTestRunner struct {
logger log.Logger
commandFactory command.Factory
Expand All @@ -140,7 +131,6 @@ type XcodeTestRunner struct {
utils Utils
}

// NewXcodeTestRunner ...
func NewXcodeTestRunner(logger log.Logger, commandFactory command.Factory, xcodebuild xcodebuild.Xcodebuild, simulatorManager simulator.Manager, cache cache.SwiftPackageCache, outputExporter output.Exporter, pathModifier pathutil.PathModifier, pathProvider pathutil.PathProvider, utils Utils) XcodeTestRunner {
return XcodeTestRunner{
logger: logger,
Expand All @@ -155,7 +145,6 @@ func NewXcodeTestRunner(logger log.Logger, commandFactory command.Factory, xcode
}
}

// ProcessConfig ...
func (s XcodeTestConfigParser) ProcessConfig() (Config, error) {
var input Input
err := s.inputParser.Parse(&input)
Expand All @@ -166,12 +155,6 @@ func (s XcodeTestConfigParser) ProcessConfig() (Config, error) {
stepconf.Print(input)
s.logger.EnableDebugLog(input.VerboseLog)

s.logger.Printf("- xcodebuild_version: %s (%s)", s.xcodeVersion.Version, s.xcodeVersion.BuildVersion)
s.logger.Println()
if err := s.validateXcodeVersion(&input, int(s.xcodeVersion.MajorVersion)); err != nil {
return Config{}, err
}

// validate project path
projectPath, err := s.pathModifier.AbsPath(input.ProjectPath)
if err != nil {
Expand Down Expand Up @@ -214,10 +197,9 @@ func (s XcodeTestConfigParser) ProcessConfig() (Config, error) {
return Config{}, fmt.Errorf("`-xcconfig` option found in 'Additional options for the xcodebuild command' (xcodebuild_options), please clear 'Build settings (xcconfig)' (`xcconfig_content`) input as only one can be set")
}

return s.utils.CreateConfig(input, projectPath, int(s.xcodeVersion.MajorVersion), sim, additionalOptions, additionalLogFormatterOptions), nil
return s.utils.CreateConfig(input, projectPath, sim, additionalOptions, additionalLogFormatterOptions), nil
}

// InstallDeps ...
func (s XcodeTestRunner) InstallDeps() {
logFormatterVersion, err := s.xcodebuild.GetXcodeCommadRunner().CheckInstall()
if err != nil {
Expand All @@ -233,7 +215,6 @@ func (s XcodeTestRunner) InstallDeps() {
}
}

// Result ...
type Result struct {
Scheme string
DeployDir string
Expand All @@ -244,7 +225,6 @@ type Result struct {
SimulatorDiagnosticsPath string
}

// Run ...
func (s XcodeTestRunner) Run(cfg Config) (Result, error) {
enableSimulatorVerboseLog := cfg.CollectSimulatorDiagnostics != never
launchSimulator := !cfg.IsSimulatorBooted && !cfg.HeadlessMode
Expand Down Expand Up @@ -287,7 +267,6 @@ func (s XcodeTestRunner) Run(cfg Config) (Result, error) {
return result, nil
}

// Export ...
func (s XcodeTestRunner) Export(result Result, testFailed bool) error {
// export test run status
s.outputExporter.ExportTestRunResult(testFailed)
Expand Down Expand Up @@ -345,23 +324,6 @@ func (s XcodeTestConfigParser) parseAdditionalLogFormatterOptions(logFormatter,
}
}

func (s XcodeTestConfigParser) validateXcodeVersion(input *Input, xcodeMajorVersion int) error {
if xcodeMajorVersion == 0 {
s.logger.Printf("Skipping Xcode major version check as it is not available.")
return nil
}

if input.TestRepetitionMode != xcodebuild.TestRepetitionNone && xcodeMajorVersion < 13 {
return errors.New("Test Repetition Mode (test_repetition_mode) is not available below Xcode 13")
}

if input.RetryTestsOnFailure && xcodeMajorVersion > 12 {
return errors.New("Should retry tests on failure? (should_retry_test_on_fail) is not available above Xcode 12; use test_repetition_mode=retry_on_failure instead")
}

return nil
}

func (s XcodeTestConfigParser) getSimulatorForDestination(destinationSpecifier string) (destination.Device, error) {
simulatorDestination, err := destination.NewSimulator(destinationSpecifier)
if err != nil {
Expand Down
Loading

0 comments on commit 78e2150

Please sign in to comment.