codemagic-ci-cd / cli-tools

Various utilities to managing Android and iOS app builds, code signing, and deployment.
https://codemagic.io/start/
GNU General Public License v3.0
245 stars 42 forks source link

Handle `xcresulttool` failures #390

Closed priitlatt closed 9 months ago

priitlatt commented 9 months ago

It is possible that xcresult files that contain Xcode test results are corrupted (either by erroneous user interaction or Xcode generated them as such). For example if Info.plist is missing from the xcresult bundle, then applying any xcrun xcresulttool command to this bundle will fail and exits with error code 1.

For example:

$ xcrun xcresulttool get --format json --path /Users/priit/Library/Developer/Xcode/DerivedData/App-eyutjqzsoxkgpcbycmzihsrczspl/Logs/Test/Test-App-2024.01.10_09-07-42-+0000.xcresult
error: Info.plist at /Users/priit/Library/Developer/Xcode/DerivedData/App-eyutjqzsoxkgpcbycmzihsrczspl/Logs/Test/Test-App-2024.01.10_09-07-42-+0000.xcresult does not exist, the result bundle might be corrupted or the provided path is not a result bundle

As it is now, xcode-project actions which use xcresulttool under the hood do not handle such errors in any way and as a result the action invocation can fail unexpectedly.

Example error log of xcode-project run-tests ```shell Running tests on simulators: - iOS 17.0 iPhone 15 (E473C396-11F5-426D-8A60-FCAD55546926) Run tests for App.xcworkspace Execute "xcodebuild -workspace App.xcworkspace -scheme App -sdk iphonesimulator -enableCodeCoverage YES -destination id=E473C396-11F5-426D-8A60-FCAD55546926 test" Test run failed Found test results at - /Users/priit/Library/Developer/Xcode/DerivedData/App-eyutjqzsoxkgpcbycmzihsrczspl/Logs/Test/Test-App-2024.01.10_09-07-42-+0000.xcresult Executing "xcode-project run-tests" failed unexpectedly. Detailed logs are available at "/var/folders/w2/rrf5p87d1bbfyphxc7jdnyvh0000gn/T/codemagic-10-01-24.log". To see more details about the error, add "--verbose" command line option. No valid test result files matching "build/ios/test/*." were found. Test results are not displayed. Build failed :| Step 2 script `iOS test` exited with status code 9 ```

Capture the errors that happen during xcresulttool runs, log out the error reason and fail the action gracefully with descriptive message in case the main goal of the action could not be completed.

Updated actions: