開発はどんどん自動化さています。コードをコミットしたら自動的にテストが行われて、問題なければデプロイしたり、アプリをビルドして関係者に配布するような仕組みができあがっています。 今夏はその一つ、アプリのビルドやテストを自動化し、さらに配布やAppleへの申請まで自動で行ってくれるfastlaneを紹介します。

fastlaneの使い方

fastlaneはRubygemsでインストールします。

$ gem install fastlane

インストール後、まずiOSプロジェクトのリポジトリで初期化を行います。質問が色々と出るので順番に答えていきます。

$ fastlane init
[06:38:15]: This setup will help you get up and running in no time.
[06:38:15]: First, it will move the config files from `deliver` and `snapshot`
[06:38:15]: into the subfolder `fastlane`.

[06:38:15]: fastlane will check what tools you're already using and set up
[06:38:15]: the tool automatically for you. Have fun! 
Do you want to get started? This will move your Deliverfile and Snapfile (if they exist) (y/n)
y
 Do you have everything commited in version control? If not please do so! (y/n)
y
 [06:38:26]: Created new folder './fastlane'.
[06:38:26]: ------------------------------
[06:38:26]: To not re-enter your username and app identifier every time you run one of the fastlane tools or fastlane, these will be stored from now on.
App Identifier (com.krausefx.app): com.example
Your Apple ID (fastlane@krausefx.com): info@moongift.jp
[06:39:02]: Created new file './fastlane/Appfile'. Edit it to manage your preferred app metadata information.
Do you want to setup 'deliver', which is used to upload app screenshots, app metadata and app updates to the App Store or Apple TestFlight?
(y/n)
n
 Do you want to setup 'snapshot', which will help you to automatically take screenshots of your iOS app in all languages/devices? (y/n)
n
 Do you want to use 'sigh', which will maintain and download the provisioning profile for your app? (y/n)
n
 Optional: The scheme name of your app. If you don't need one, just click enter: 
[06:39:33]: 'deliver' not enabled.
[06:39:33]: 'snapshot' not enabled.
[06:39:33]: 'xctool' not enabled.
[06:39:33]: 'cocoapods' enabled.
[06:39:33]: 'sigh' not enabled.
[06:39:33]: Created new file './fastlane/Fastfile'. Edit it to manage your own deployment lanes.
[06:39:33]: fastlane will send the number of errors for each action to
[06:39:33]: https://github.com/fastlane/enhancer to detect integration issues
[06:39:33]: No sensitive/private information will be uploaded
[06:39:33]: You can disable this by adding `opt_out_usage` to your Fastfile
[06:39:33]: Successfully finished setting up fastlane

これで準備は完了です。fastlaneはテストを実行したり、その結果をうけてbeta配布(DeployGateやTestflight)したり、さらにApp Storeに申請ができるようになっています。一つ一つの設定はRubyスクリプトで定義しています。例えば以下のような感じです。

desc "Deploy a new version to the App Store"
desc "** Full Markdown** Support: `code`"
lane :deploy do
  # snapshot
  # sigh
  # deliver(skip_deploy: true, force: true)
  # frameit
end

設定できるアクションはincrement_build_number、cocoapods、xctool、snapshot、sigh、slackなど数多くあります。独自のスクリプト実行も可能です。

実際に配信する際には証明書が必要であったり、下準備も必要です。ただ、一旦設定してしまえばテストから配布までスムーズに完結できるようになるのがfastlaneの魅力でしょう。

fastlaneはRuby製、MIT Licenseのオープンソース・ソフトウェアです

iOSアプリの継続的デリバリーに便利なfastlaneのご紹介 - Qiita KrauseFx/fastlane