47
41

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

fastlaneを使ってiOS開発を楽しくする、しかも応援してもらえる

Last updated at Posted at 2015-10-10

fastlane

【fastlane】今日も休日の予定がないのでfastlaneの中身を見る1
記事には書いてませんが、その後調べていろいろと安全っぽいことがなんとなくわかったので、導入決定!

やりたいこと

  • テストアプリをfabricか内部テスターで飛ばしてSlackに通知を自動化
  • 申請時に使う情報を全部なんかconfファイルとかに書いておいて、リリースノートとかも更新+申請を自動化

どっちもちょっとコマンドた叩いて待っていればできる状態にしたい。

fastlane導入

fastlane/examples
をみてみると実際にiOSのプロジェクトに導入した事例がある。

ちょっとみてみると"fastlane"ってディレクトリがある。
スクリーンショット 2015-10-10 9.44.49.png

導入するとなんかディレクトリができることがわかる。

組み込んでみる

sudo gem install fastlane
fastlane init

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

をみながら答えていく。するとfastlaneフォルダができる。

fastlaneフォルダ

中身はこんな感じだ。
スクリーンショット 2015-10-10 9.56.34.png

このFastfileから明らかに設定ファイル感が出ている。こいつだ

# Customise this file, documentation can be found here:
# https://github.com/KrauseFx/fastlane/tree/master/docs
# All available actions: https://github.com/KrauseFx/fastlane/blob/master/docs/Actions.md
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# By default, fastlane will send which actions are used
# No personal data is shared, more information on https://github.com/fastlane/enhancer
# Uncomment the following line to opt out
# opt_out_usage

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version

fastlane_version "1.32.1"

default_platform :ios


platform :ios do
  before_all do
    ENV["SLACK_URL"] = "https://hooks.slack.com/services/XXXXXXXX"
    cocoapods
    
    # increment_build_number

    #xctool # run the tests of your app
  end

  desc "Runs all the tests"
  lane :test do
    desc "Run Test Command."
    #snapshot
    desc "Run UnitTest"
  end

  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    snapshot
    sigh
    gym # Build your app - more options available
    pilot

    # sh "your_script.sh"
    # You can also use other beta testing services here
  end

  desc "Deploy a new version to the App Store"
  lane :deploy do
    snapshot
  desc "** Full Markdown** Support: `code`"
    sigh
    gym # Build your app - more options available
    deliver(force: true)
    # frameit
  end

  # You can define as many lanes as you want

  # after_all do |lane|
  #  # This block is called, only if the executed lane was successful
  #  
  #  slack(
  #    message: "Successfully deployed new App Update!!"
  #  )
  # end

  # error do |lane, exception|
  #  slack(
  #    message: exception.message,
  #    success: false
  #  )
  end
end

だいたいこんな感じで書かれているのでとりあえずbefore_allの設定をする

  • Slack_urlを設定、Slackのwebhookの設定ページで発行できるURLを入れる
  • increment_build_numberをコメントイン、整数値でビルド番号がfastlane実行毎に上がるようになる、CURRENT_PROJECT_VERSIONがbuild settingに書いてないとダメ
  • after_allとerrorもコメントイン
  • xctestを記述

以下のように変更

  before_all do
    # https://{your_slack_name}-team.slack.com/services/{your_slack_room_name}?added=1
    ENV["SLACK_URL"] = "https://hooks.slack.com/services/XXXXX"
    cocoapods
    
    increment_build_number

    xctest(
        scheme: "Gitrend",
        destination: "platform=iOS Simulator,name=iPhone 6,OS=8.4",
    )
  end

これだけで以下のコマンドを叩けば、とりあえずpod updateしてユニットテストして成功・失敗をslackに投げてくれる。

fastlane test

lane: XXX で定義されているものがfastlaneでの実行ターゲットになる。これをlaneとよぶ。
この場合 lane: testと描かれている処理を実行する、実行後に成功・失敗がSlackに投稿される。

このlaneの中にはactionと呼ばれる処理を書く。
上のincrement_build_numberやslack()のような部分がそうだ。
使えるactionは以下のように確認できる。

% fastlane actions                                                                                                                                    [10:06:02]
+------------------------------+-------------------------------------------------------------------------------+------------------+
|                                                   Available fastlane actions                                                    |
+------------------------------+-------------------------------------------------------------------------------+------------------+
| Action                       | Description                                                                   | Author           |
+------------------------------+-------------------------------------------------------------------------------+------------------+
| add_git_tag                  | This will add a git tag to the current branch                                 | lmirosevic       |
| appstore                     | Alias for the deliver action                                                  | KrauseFx         |
| artifactory                  | This action uploads an artifact to artifactory                                | koglinjg         |
| backup_file                  | This action backs up your file to "[path].back"                               | gin0606          |
| backup_xcarchive             | Save your [zipped] xcarchive elsewhere from default path                      | dral3x           |
| bundle_install               | This action runs `bundle install` (if available)                              | Multiple         |
| carthage                     | Runs `carthage bootstrap` for your project                                    | Multiple         |
| cert                         | Fetch or generate the latest available code signing identity                  | KrauseFx         |
| chatwork                     | Send a success/error message to ChatWork                                      | ChatWork Inc.    |
| clean_build_artifacts        | Deletes files created as result of running ipa or sigh                        | lmirosevic       |
| clipboard                    | Copies a given string into the clipboard. Works only on Mac OS X computers    | KrauseFx         |
| cocoapods                    | Runs `pod install` for the project                                            | Multiple         |
| commit_version_bump          | Creates a 'Version Bump' commit. Run after `increment_build_number`           | lmirosevic       |
| crashlytics                  | Upload a new build to Crashlytics Beta                                        | Multiple         |
| create_keychain              | Create a new Keychain                                                         | gin0606          |
| debug                        | Print out an overview of the lane context values                              | KrauseFx         |
| default_platform             | Defines a default platform to not have to specify the platform                | KrauseFx         |
| delete_keychain              | Delete keychains and remove them from the search list                         | gin0606          |
| deliver                      | Uses deliver to upload new app metadata and builds to iTunes Connect          | KrauseFx         |
| deploygate                   | Upload a new build to DeployGate                                              | tnj              |
| dotgpg_environment           | Reads in production secrets set in a dotgpg file and puts them in ENV         | simonlevy5       |
| download                     | Download a file from a remote server (e.g. JSON file)                         | KrauseFx         |
| dsym_zip                     | Creates a zipped dSYM in the project root from the .xcarchive                 | lmirosevic       |
| ensure_git_branch            | Raises an exception if not on a specific git branch                           | Multiple         |
| ensure_git_status_clean      | Raises an exception if there are uncommited git changes                       | lmirosevic       |
| ensure_no_debug_code         | Ensures the given text is nowhere in the code base                            | KrauseFx         |
| fastlane_version             | Verifies the minimum fastlane version required                                | KrauseFx         |
| frameit                      | Adds device frames around the screenshots using frameit                       | KrauseFx         |
| gcovr                        | Runs test coverage reports for your Xcode project                             | dtrenz           |
| get_build_number             | Get the build number of your project                                          | Liquidsoul       |
| get_github_release           | This will verify if a given release version is avialable on GitHub            | Multiple         |
| get_info_plist_value         | Returns value from Info.plist of your project as native Ruby data structures  | kohtenko         |
| get_version_number           | Get the version number of your project                                        | Liquidsoul       |
| git_branch                   | Returns the name of the current git branch                                    | KrauseFx         |
| git_commit                   | Directly commit the given file with the given message                         | KrauseFx         |
| git_pull                     | Executes a simple git pull command                                            | KrauseFx         |
| gym                          | Easily build and sign your app using `gym`                                    | KrauseFx         |
| hg_add_tag                   | This will add a hg tag to the current branch                                  | sjrmanning       |
| hg_commit_version_bump       | This will commit a version bump to the hg repo                                | sjrmanning       |
| hg_ensure_clean_status       | Raises an exception if there are uncommited hg changes                        | sjrmanning       |
| hg_push                      | This will push changes to the remote hg repository                            | sjrmanning       |
| hipchat                      | Send a error/success message to HipChat                                       | jingx23          |
| hockey                       | Upload a new build to HockeyApp                                               | KrauseFx         |
| import                       | Import another Fastfile to use its lanes                                      | KrauseFx         |
| import_certificate           | Import certificate from inputfile into a keychain                             | gin0606          |
| import_from_git              | Import another Fastfile from a remote git repository to use its lanes         | Multiple         |
| increment_build_number       | Increment the build number of your project                                    | KrauseFx         |
| increment_version_number     | Increment the version number of your project                                  | serluca          |
| ipa                          | Easily build and sign your app using shenzhen                                 | joshdholtz       |
| is_ci                        | Is the current run being executed on a CI system, like Jenkins or Travis      | KrauseFx         |
| lane_context                 | An alias to `Actions.lane_context`                                            | KrauseFx         |
| last_git_tag                 | Get the most recent git tag                                                   | KrauseFx         |
| lcov                         | Generates coverage data using lcov                                            | thiagolioy       |
| mailgun                      | Send a success/error message to an email group                                | thiagolioy       |
| nexus_upload                 | Upload a file to Sonatype Nexus platform                                      | xfreebird        |
| notify                       | Shows a Mac OS X notification                                                 | champo           |
| oclint                       | Lints implementation files with OCLint                                        | HeEAaD           |
| opt_out_usage                | This will stop uploading the information which actions were run               | KrauseFx         |
| pem                          | Makes sure a valid push profile is active and creates a new one if needed     | KrauseFx         |
| pilot                        | Upload a new binary to iTunes Connect for TestFlight beta testing             | KrauseFx         |
| pod_push                     | Push a Podspec to Trunk or a private repository                               | squarefrog       |
| produce                      | Creates the given application on iTC and the Dev Portal if necessary          | KrauseFx         |
| prompt                       | Ask the user for a value or for confirmation                                  | KrauseFx         |
| push_git_tags                | Push local tags to the remote - this will only push tags                      | vittoriom        |
| push_to_git_remote           | Push local changes to the remote branch                                       | lmirosevic       |
| puts                         | Prints out the given text                                                     | KrauseFx         |
| read_podspec                 | Loads a CocoaPods spec as JSON                                                | czechboy0        |
| register_devices             | Registers new devices to the Apple Dev Portal                                 | lmirosevic       |
| reset_git_repo               | Resets git repo to a clean state by discarding uncommited changes             | lmirosevic       |
| resign                       | Codesign an existing ipa file                                                 | lmirosevic       |
| restore_file                 | This action restore your file that was backuped with the `backup_file` action | gin0606          |
| s3                           | Generates a plist file and uploads all to AWS S3                              | joshdholtz       |
| say                          | This action speaks out loud the given text                                    | KrauseFx         |
| set_build_number_repository  | Set the build number from the current repository                              | pbrooks          |
| set_changelog                | Set the changelog for all languages on iTunes Connect                         | KrauseFx         |
| set_github_release           | This will create a new release on GitHub and upload assets for it             | czechboy0        |
| set_info_plist_value         | Sets value to Info.plist of your project as native Ruby data structures       | kohtenko         |
| sigh                         | Generates a provisioning profile. Stores the profile in the current folder    | KrauseFx         |
| slack                        | Send a success/error message to your Slack group                              | KrauseFx         |
| slather                      | Use slather to generate a code coverage report                                | mattdelves       |
| snapshot                     | Generate new localised screenshots on multiple devices                        | KrauseFx         |
| splunkmint                   | Upload dSYM file to Splunk MINT                                               | xfreebird        |
| team_id                      | Specify the Team ID you want to use for the Apple Developer Portal            | KrauseFx         |
| team_name                    | Set a team to use by its name                                                 | KrauseFx         |
| testflight                   | Alias for the pilot action                                                    | KrauseFx         |
| testmunk                     | Run tests on real devices using Testmunk                                      | Multiple         |
| typetalk                     | Post a message to Typetalk                                                    | Nulab Inc.       |
| unlock_keychain              | Unlock a keychain                                                             | xfreebird        |
| update_app_group_identifiers | This action changes the app group identifiers in the entitlements file        | mathiasAichinger |
| update_fastlane              | Makes sure fastlane-tools are up-to-date when running fastlane                | milch            |
| update_info_plist            | Update a Info.plist file with bundle identifier and display name              | tobiasstrebitzer |
| update_project_code_signing  | Updated code signing settings from 'Automatic' to a specific profile          | KrauseFx         |
| update_project_provisioning  | Update projects code signing settings from your profisioning profile          | Multiple         |
| verify_xcode                 | Verifies that the Xcode installation is properly signed by Apple              | KrauseFx         |
| version_bump_podspec         | Increment or set the version in a podspec file                                | Multiple         |
| version_get_podspec          | Receive the version number from a podspec file                                | Multiple         |
| xcarchive                    | Archives the project using `xcodebuild`                                       | dtrenz           |
| xcbuild                      | Builds the project using `xcodebuild`                                         | dtrenz           |
| xcclean                      | Cleans the project using `xcodebuild`                                         | dtrenz           |
| xcexport                     | Exports the project using `xcodebuild`                                        | dtrenz           |
| xcode_select                 | Change the xcode-path to use. Useful for beta versions of Xcode               | dtrenz           |
| xcode_server_get_assets      | Downloads Xcode Bot assets like the `.xcarchive` and logs                     | czechboy0        |
| xcodebuild                   | Use the `xcodebuild` command to build and sign your app                       | dtrenz           |
| xctest                       | Runs tests on the given simulator                                             | dtrenz           |
| xctool                       | Run tests using xctool                                                        | KrauseFx         |
+------------------------------+-------------------------------------------------------------------------------+------------------+
  Total of 105 actions

Get more information for one specific action using `fastlane action [name]`

超いっぱいある。嬉しい。
つまりfastlaneはこのFastfileにactionで構成されるlaneを書いて処理を実行する便利ツールなわけだ。面白い。

おや・・・・

これは・・・

| say       | This action speaks out loud the given text                                   | KrauseFx         |

・・・

% fastlane actions say                                                                                                                                [10:07:47]
Loading documentation for say:

+--------------------------------------------+
|                    say                     |
+--------------------------------------------+
| This action speaks out loud the given text |
|                                            |
| Created by KrauseFx                        |
+--------------------------------------------+

No available options

More information can be found on https://github.com/KrauseFx/fastlane/blob/master/docs/Actions.md

何言ってんだクラウス・・・iOSの自動化とかCI/CDのフェーズでどこで喋る必要があるっていうんだ・・・

しかし試さざるを得ない。

  before_all do
    say ["がんばれ"]
    # https://{your_slack_name}-team.slack.com/services/{your_slack_room_name}?added=1
    ENV["SLACK_URL"] = "https://hooks.slack.com/services/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"
    #cocoapods
    
    #increment_build_number

    #xctool # run the tests of your app

  end

しゃべったあああああああああああああああああああ

中身でsayコマンドを叩いてるんですね。
これでいつでもfastlane実行毎に応援してもらえます。よかったよかった。

次回はちゃんと書きます

ちゃんともっと便利なの書きます、あとクラウスは結構遊びゴコロのある人らしく愉快なプルリクも優しくマージしてくるそうです。なんか送ってみよう

47
41
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
47
41

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?