LoginSignup
59
49

More than 5 years have passed since last update.

iOSアプリのリリースフロー自動化ツールfastlaneの導入

Last updated at Posted at 2016-02-05

背景

slackやdeploygate、circleciに意識を向けてると関連してよく耳にするfastlane。
名前は知っているが、いまいち何をしてくれるかがよくわかっていなかったので触りながらためしてみることにしました。

作業のゴールとしては、

  • XCテストの実行をfastlaneのコマンドから叩けるようにする
  • IPAファイルをつくってデプロイゲートへアップロードすることができる

これらのゴールはそれ自体でみると大した効率化に見えないかもしれませんが、circleciとslackを組み合わせることで大幅な効率化を見込むことができると思います。
それらについては、後日追記する予定です。

公式ガイド

インストール

前提

Mac OS 10.9 or newer
Ruby 2.0 or newer (ruby -v)
Xcode

作業

fastlineのインストール

sudo gem install fastlane --verbose

Xcodeのコマンドラインツールの最新版をインストール
※もし最新ではないなら

xcode-select --install

上記コマンドをターミナルで入力するとポップアップが表示されるので"インストール"をクリック

fastlaneの実行に時間がかかる場合は以下のコマンド

gem cleanup

セットアップ

  • まずは自分のプロジェクトファイルにcd で移動

  • ターミナルで以下のコマンド入力

fastlane init

実行すると以下を聞かれるので入力

Your Apple ID (e.g. fastlane@krausefx.com): 

→自分のAppleIDを入力

Password (for hogehoge@hmail.com): 

→appleIDのパスワード入力

Multiple teams found, please enter the number of the team you want to use: 
1) XXXXXXXXXX "Takashi Kudo" (Individual)
2) XXXXXXXXXX "hoge, Inc." (Company/Organization)

→ AppleIDが複数のアカウントに紐付いている場合は適切な方を選択 ※今回は1


+----------------+--------------------------------------------------------------------------+
|                                      Detected Values                                      |
+----------------+--------------------------------------------------------------------------+
| Apple ID       | hogehoge@hmail.com                                                       |
| App Name       | SampleProject20160205                                                    |
| App Identifier | tokyo.swift.SampleProject20160205                                        |
| Project        | /Users/tac/Desktop/SampleProject20160205/SampleProject20160205.xcodeproj |
+----------------+--------------------------------------------------------------------------+

[14:35:35]: This app identifier doesn't exist on iTunes Connect yet, it will be created for you
[14:35:35]: This app identifier doesn't exist on the Apple Developer Portal yet, it will be created for you
Please confirm the above values (y/n)

→itune Connectなどの設定がされていない場合は、自動で設定してくれるのでこれをうけいれるかどうかを選択。yesを選択してみる。

※ no を選択するとApp Idendifierを聞かれるので手動で入力します。

[14:36:25]: Created new file './fastlane/Appfile'. Edit it to manage your preferred app metadata information.
[14:36:25]: Creating the app on iTunes Connect and the Apple Developer Portal

+----------------+-----------------------------------+
|             Summary for produce 1.1.1              |
+----------------+-----------------------------------+
| username       | hogehog@gmail.com                 |
| app_identifier | tokyo.swift.SampleProject20160205 |
| app_name       | SampleProject20160205             |
| sku            | 1454650585                        |
| language       | English                           |
| skip_itc       | false                             |
| skip_devcenter | false                             |
| team_id        | 3XL44PTR2S                        |
+----------------+-----------------------------------+

[14:36:28]: Creating new app 'SampleProject20160205' on the Apple Dev Center
[14:36:29]: Created app 336BGKV7DM
[14:36:29]: Finished creating new app 'SampleProject20160205' on the Dev Center
[14:36:31]: Creating new app 'SampleProject20160205' on iTunes Connect
[14:36:33]: Successfully created new app 'SampleProject20160205' on iTunes Connect with ID 1081728442
[14:36:33]: Loading up 'deliver', this might take a few seconds
[14:36:33]: Login to iTunes Connect (hogehog@gmail.com)
[14:36:35]: Login successful

+--------------------+-----------------------------------+
|                 deliver 1.9.0 Summary                  |
+--------------------+-----------------------------------+
| username           | hogehoge@hmail.com                |
| app_identifier     | tokyo.swift.SampleProject20160205 |
| metadata_path      | ./fastlane/metadata               |
| screenshots_path   | ./fastlane/screenshots            |
| skip_binary_upload | false                             |
| skip_screenshots   | false                             |
| skip_metadata      | false                             |
| force              | false                             |
| submit_for_review  | false                             |
| automatic_release  | false                             |
+--------------------+-----------------------------------+

[14:36:36]: Writing to 'fastlane/metadata/en-US/description.txt'
[14:36:36]: Writing to 'fastlane/metadata/en-US/keywords.txt'
[14:36:36]: Writing to 'fastlane/metadata/en-US/release_notes.txt'
[14:36:36]: Writing to 'fastlane/metadata/en-US/support_url.txt'
[14:36:36]: Writing to 'fastlane/metadata/en-US/marketing_url.txt'
[14:36:36]: Writing to 'fastlane/metadata/en-US/name.txt'
[14:36:36]: Writing to 'fastlane/metadata/en-US/privacy_url.txt'
[14:36:36]: Writing to 'fastlane/metadata/copyright.txt'
[14:36:36]: Writing to 'fastlane/metadata/primary_category.txt'
[14:36:36]: Writing to 'fastlane/metadata/secondary_category.txt'
[14:36:36]: Writing to 'fastlane/metadata/primary_first_sub_category.txt'
[14:36:36]: Writing to 'fastlane/metadata/primary_second_sub_category.txt'
[14:36:36]: Writing to 'fastlane/metadata/secondary_first_sub_category.txt'
[14:36:36]: Writing to 'fastlane/metadata/secondary_second_sub_category.txt'
Successfully created new configuration files.
[14:36:36]: Downloading all existing screenshots...
[14:36:37]: Successfully downloaded all existing screenshots
[14:36:37]: Successfully created new Deliverfile at path 'fastlane/Deliverfile'
[14:36:37]: xcrun xcodebuild -list -project './SampleProject20160205.xcodeproj'
[14:36:37]: 'snapshot' not enabled.
[14:36:37]: 'cocoapods' not enabled.
[14:36:37]: 'carthage' not enabled.
[14:36:37]: Created new file './fastlane/Fastfile'. Edit it to manage your own deployment lanes.
[14:36:37]: fastlane will send the number of errors for each action to
[14:36:37]: https://github.com/fastlane/enhancer to detect integration issues
[14:36:37]: No sensitive/private information will be uploaded
[14:36:37]: You can disable this by adding `opt_out_usage` to your Fastfile
[14:36:37]: Successfully finished setting up fastlane

セットアップ完了!

実行

以下の項目は具体的には、Fastfileに処理を書いた上でline で定義したコマンドをたたくことで実行されます。

XCTestの自動化

  • Fastfileに書く内容(簡易版)
 desc "XCTestのを実行します。"
    lane :test do
      xctest(
        scheme: "SampleProject2016020_2",
        destination: "platform=iOS Simulator,name=iPhone 5s,OS=9.2",
      )
  end
  • コマンド
fastlane test

プロジェクトフォルダ > fastlane > test_output > report.html をクリックするとこんな感じでXCTestの実行結果が表示されます。

Test_Results___xcpretty.png

より詳細に記載する例

  # Run tests in given simulator
  xctest(
    destination: "name=iPhone 5s,OS=8.1",
    destination_timeout: 120, # increase device/simulator timeout, usually used on slow CI boxes
    reports: [{
      report: 'html',
      output: './build-dir/test-report.html',  # will use XCODE_BUILD_PATH/report, if output is not provided
      screenshots: 1
    },
    {
      report: 'junit',
      output: './build-dir/test-report.xml'
    }]
  )

IPAファイルをつくってデプロイゲートへアップロード

DeployGateのAPIの情報はこちら

念のためですが、以下だと失敗します。

  • Fastfileに書く内容(失敗版)
desc "社内向け配信"
   lane :for_inhouse do
    sigh(
      adhoc: true
    )
    ipa(
      scheme: 'SampleProject2016020_2',
      configuration: 'Debug'
    )
    deploygate(
      user: 'hogehoge',
      api_token: 'hogehoge'
    )
  end

[18:24:58]: A build error occured. You are using legacy `shenzhen` for building
[18:24:58]: it is recommended to upgrade to `gym`: 
[18:24:58]: https://github.com/fastlane/gym
[18:24:58]: krausefx-ipa build -s "SampleProject2016020_2" -c "AdHoc" -m "/Users/tac/Desktop/SampleProject2016020_2/AdHoc_tokyo.swift.SampleProject2016020-2.mobileprovision" --verbose | xcpretty
[18:24:58]: -------------------------------------------------------
[18:24:58]: Variable Dump:
[18:24:58]: {:DEFAULT_PLATFORM=>:i

上のipaコマンドはshenzhenをビルドにつかってるんですが、それがうまくいっていないので、
https://github.com/fastlane/gym
からgymをインストール

sudo gem install gym

先ほどのをipaからgymに変更

  • Fastfileに書く内容(簡易版)
desc "社内向け配信"
   lane :for_inhouse do
    sigh(
      adhoc: true
    )
    ipa(
      scheme: 'SampleProject2016020_2',
      configuration: 'Debug'
    )
    deploygate(
      user: 'hogehoge',
      api_token: 'hogehoge'
    )
  end

これで、deploygateにipaファイルがアップデートされます。
ちなみに、api_tokenはdeploygateのサイトにログインして確認することができます。

fastlane の設定tips

ここにfastlaneのアクションとして、Fastfileに書く内容はまとまっています。

参考文献

59
49
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
59
49