travis-ci - 在 .travis.yml 中定位多个 iOS 版本

标签 travis-ci xcode7 xctool

我是 Travis CI 的新手,已经针对单个项目和环境设置了基本构建和测试。 .travis.yml 如下所示:

language: objective-c
osx_image: xcode7
xcode_project: ./[project]/[project].xcodeproj
xcode_scheme: [project]
xcode_sdk: iphonesimulator9.0

效果很好,但我也想进行测试。其他 iOS 模拟器版本(例如 8.4)。

我意识到我可以从脚本部分使用xctool,就像我的.travis.yml中的那样,这也可以正常工作:

script:      
  xctool -project ./[project]/[project].xcodeproj -scheme [project] -sdk iphonesimulator9.0 build test

但是,我不知道如何运行任何其他 iOS 版本。 Objective-C docs for Travis CI假设有许多模拟器 iOS 版本可用于 osx_image: xcode7,但是当 $ xcodebuild -version -sdk 在 CI 机器上运行时,它只显示 iOS 9 可用。

为了能够针对 XCode 安装测试其他 iOS 版本,我缺少什么?

最佳答案

查找可用模拟器的技巧正在运行:

$ xcrun instruments -s devices

您将看到已安装设备的属性:

Known Devices:
Travis’s Mac (129) [00000000-0000-1000-8000-005056A6DCD8]
iPad 2 (8.1) [22540C0C-46B4-4FF8-9B74-6321081CA975]
iPad 2 (8.2) [03655E8B-725B-4C03-A505-8EEA0BE5A966]
iPad 2 (8.3) [BBC2737B-BE8D-403B-804F-5A36560AD47B]

etc...

然后我用环境变量 ( reference ) 构建了一个矩阵,并为我想要测试的模拟器/操作系统版本组合定义了 UDID。对于定义的每个唯一环境变量/值,脚本部分都会执行一次。我的 .travis.yml 文件如下所示:

language: objective-c
osx_image: xcode7

## Create a build matrix to execute against multiple simulators/iOS versions
## The UDID will be used below to determin the destination to test against
## where the script section will be run once for each definition
## ISO_DEVICE is not used in the script but is useful to know what OS version is tested and will show up in Travis to make it easer to read
env:
  - UDID="FCBB11B4-D7C8-4085-9067-2CEDA2BFC895", IOS_DEVICE="iPhone 6 Plus (9.0)"
  # - UDID="363ADE93-270B-4C2E-9286-C3C1FABE3CDD", IOS_DEVICE="iPhone 4s (8.1)"
  - UDID="BE52C183-B4AF-408D-AE90-278FA4AD89EC", IOS_DEVICE="iPhone 5 (8.3)"
  - UDID="FCBB11B4-D7C8-4085-9067-2CEDA2BFC895", IOS_DEVICE="iPhone 6 Plus (9.0)"
  - UDID="BEEA639C-46EB-48EF-8377-A22B781A7EE2", IOS_DEVICE="iPad Air 2 (8.4)"

### Setting up the simulator for auto-test and running the build via the xcodebuild tool:
script:
  # The xcrun with devices here will print out a list of available devices you can snag the UDIDs for
  - xcrun instruments -s devices
  - echo staring build and test...
  - open -a "simulator" --args -CurrentDeviceUDID $UDID
  - xcodebuild test -project ./MovingHelper/MovingHelper.xcodeproj -scheme MovingHelper -configuration Debug -sdk iphonesimulator -destination "platform=iOS Simulator,id=$UDID"
  - osascript -e 'tell app "Simulator" to quit'

可以看到此构建的示例 here .

关于travis-ci - 在 .travis.yml 中定位多个 iOS 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32788479/

相关文章:

swift - 获取 Swift 运行时错误 (NSException)

ios - Homebrew 软件无法安装 xctool

git-submodules - 如何告诉 Travis 跳过拉入所有 git 子模块?

travis-ci - TravisCI - ERR : Package flute_music_player requires Flutter SDK version ^0. 1.2 但当前 SDK 为 0.0.0-未知

travis-ci - Travis CI 忽略行

c++ - Travis 首次构建矩阵失败

ios - swift:线程1:exc_bad_instruction(code = exc_1386_invop,subcode = 0x0)

ios - xcode 7 警告 : Null passed to a callee that requires a non-null argument

travis-ci - 如何更改 Travis CI 中的 xctool 目的地