「Travis CIでCIしたい」なのか「TravisでCIしたい」なのか悩みました。
参考
tl;dr
gem install fastlane
- 必要があれば
sudo xcodebuild -license accept
しておく
fastlane init
fastlane test
してみる
- CIサーバのためにschemeをsharedにする
- Travis CI用の設定ファイルを設置
- Travis CIのコンソールでこのレポジトリのCIを有効にする
github.com
ログ
fastlaneをインストール
% gem install fastlane
63 gems installed
% which fastlane
/Users/otiai10/.rbenv/shims/fastlane
% fastlane --help
fastlane
CLI for 'fastlane' - The easiest way to automate beta deployments and releases for your iOS and Android apps
Run using `fastlane [platform] [lane_name]`
To pass values to the lanes use `fastlane [platform] [lane_name] key:value key2:value2`
Commands:
fastlane init
% fastlane init
Appfile Fastfile
fastlane/Appfile
と fastlane/Fastfile
がつくられる
fastlane test してみる
% fastlane test
[13:22:24]: -------------------------------------------------
[13:22:24]: --- Step: Verifying required fastlane version ---
[13:22:24]: -------------------------------------------------
[13:22:24]: Your fastlane version 1.111.0 matches the minimum requirement of 1.111.0 ✅
[13:22:24]: ------------------------------
[13:22:24]: --- Step: default_platform ---
[13:22:24]: ------------------------------
[13:22:24]: Driving the lane 'ios test' 🚀
[13:22:24]: ------------------
[13:22:24]: --- Step: scan ---
[13:22:24]: ------------------
[13:22:24]: $ xcodebuild -list -project ./travis-ci-example.xcodeproj
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
[13:22:24]: Variable Dump:
[13:22:24]: {:DEFAULT_PLATFORM=>:ios, :PLATFORM_NAME=>:ios, :LANE_NAME=>"ios test"}
[13:22:24]: Error parsing xcode file using `xcodebuild -list -project ./travis-ci-example.xcodeproj`
+------+-------------------------------------+-------------+
| fastlane summary |
+------+-------------------------------------+-------------+
| Step | Action | Time (in s) |
+------+-------------------------------------+-------------+
| 1 | Verifying required fastlane version | 0 |
| 2 | default_platform | 0 |
| 💥 | scan | 0 |
+------+-------------------------------------+-------------+
[13:22:24]: fastlane finished with errors
[!] Error parsing xcode file using `xcodebuild -list -project ./travis-ci-example.xcodeproj`
しっぱいする
Error parsing xcode file using xcodebuild -list -project ./travis-ci-example.xcodeproj
xcodebuild
コマンドが失敗しているというエラーなので、おそらく
ここで言及されているxcode-select
、xcodebuild
あたりの操作をすっ飛ばしたことに起因すると思われる。
% sudo xcodebuild -license accept
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
error: tool ‘xcodebuild’ requires Xcode, but active developer directory is a command line tools instance
Xcodeをソースで落としてきてビルドしたことに起因する。Xcode.appをちゃんとApplicationsに配置した。
参考: osx - xcode-select active developer directory error - Stack Overflow
で、あらためて
% sudo xcodebuild -license accept
xcodebuild: error: Scheme travis-ci-example is not currently configured for the clean action.
で、もっかい
% fastlane test
[13:40:55]: $ xcodebuild clean -showBuildSettings -scheme travis-ci-example -project ./travis-ci-example.xcodeproj
xcodebuild: error: Scheme travis-ci-example is not currently configured for the clean action.
しっぱいする。
ビルド可能なschemeが無かった。
これで治った
supported_platforms': [!] undefined method `split' for nil:NilClass (NoMethodError)
なんとなく予想はつくので、Fastfileにて
desc "Runs all the tests"
lane :test do
- scan
+ scan(device: "iPhone 7 (10.1)")
end
とした
fastlane test 成功
% fastlane test
[18:39:51]: ▸ ✓ testPerformanceExample (0.253 seconds)
[18:39:51]: ▸ Executed 4 tests, with 0 failures (0 unexpected) in 0.519 (0.522) seconds
[18:39:51]: ▸
[18:39:51]: ▸ Test Succeeded
+--------------------+-------+
| Test Results |
+--------------------+-------+
| Number of tests | 5 |
| Number of failures | 0 |
+--------------------+-------+
[18:39:51]: Successfully generated report at '/Users/otiai10/proj/ios/travis-ci-example/fastlane/test_output/report.html'
[18:39:52]: Successfully generated report at '/Users/otiai10/proj/ios/travis-ci-example/fastlane/test_output/report.junit'
+------+-------------------------------------+-------------+
| fastlane summary |
+------+-------------------------------------+-------------+
| Step | Action | Time (in s) |
+------+-------------------------------------+-------------+
| 1 | Verifying required fastlane version | 0 |
| 2 | default_platform | 0 |
| 3 | scan | 19 |
+------+-------------------------------------+-------------+
[18:39:52]: fastlane.tools finished successfully 🎉
%
良い感じ!
CIサーバのためにschemeをsharedにする
Product > Scheme > Manage Schemes > sharedのチェックボックス
travis-ci用の設定ファイルを設置
みんなだいすき.travis.yml
language: objective-c
osx_image: xcode8.1
script:
- fastlane test
Travis CIのコンソールでこのレポジトリのCIを有効にする
もちろんアカウントが必要。 https://travis-ci.org/
いざpush
every pushでCIがまわるように設定しているので、この状態でpushすれば発動するはず。
[!] The Fastfile requires a fastlane version of >= 1.111.0. You are on 1.109.0. Please update using sudo gem update fastlane
.
で、しっぱいする。
https://travis-ci.org/otiai10/ios-travis-ci-example/builds/181730714
どうやらローカルにインストールしたfastlaneが1.111.0で、そのfastlaneでinitしたFastfileなのでfastlaneのバージョン指定が1.111.0になっていたっぽい。これを以下のように変えた
-fastlane_version "1.111.0"
+fastlane_version "1.109.0"
default_platform :ios
再度push!
https://travis-ci.org/otiai10/ios-travis-ci-example/builds/181803675
やったー!
雑感
- 参考にしたドキュメントだと、fastlane/travis.shとかいうのを噛ませて、ビルド発動条件をコントロールしてた
- グローバルないしrbenvのlocalにfastlaneをインストールしてしまうと、今回のようにfastlaneのバージョン問題が起こりうる
- Gemfileとbundle execで実行みたいな構成のほうがいいかと思われる
- サードパーティのサーバ上ではiOSのビルドできないからMacにJenkins立てるしかない、みたいな偏見あったけど、気のせいだったのかな?
- fastlane/Appfileやfastlane/certの設定次第ではデプロイもできる(はず、と思っている)ので、やってみたい
DRY