9
0

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.

CarthageやCocoaPodsの最新バージョン情報をSlackへ通知するfastlaneプラグインを作成しました

Last updated at Posted at 2019-04-03

 二番煎じ、もしくは車輪の再発明かも知れないですが、自分の(狭い)観測範囲で見当たらなかったのと、ちょっとしたツール作成にちょうど良さそうな規模感だったので作ってみました。

 機能としてはCocoaPodsCarthageでインストールしているライブラリの最新バージョンのリリース状況を取得して、必要なら結果をSlackへ通知するものです。

 プロジェクトで利用しているライブラリのアップデートはリグレッションテスト(回帰テスト)が必要となったりとなかなか腰が重い作業ですが、とりあえず新しいバージョンがリリースされていることだけでも気付けるようにして、多少プレッシャーを与えられるような状況を作れればいいかなと思いました。
 JenkinsなどのCIツールに設定して定期的にSlackへ通知するだけでもいいかなと、そんなゆるふわな使い方を想定しています。

 また、実行した最新バージョンの結果を出力変数にセットしているので、他のアクションで利用することも可能です。
 例えばこちらの記事のように、GitHubのissueやPRを作るCIフローでも利用できるかなと思います。

 cocoapods_outdatedアクションの方はlane_context[SharedValues::COCOAPODS_OUTDATED_LIST]

[{:name=>"SDWebImage", :current=>"4.4.5", :available=>"4.4.6", :latest=>"5.0.0-beta6"}, {:name=>"SVProgressHUD", :current=>"2.2.4", :available=>"2.2.4", :latest=>"2.2.5"}]

この様な感じで値がセットされており、carthage_outdatedアクションの方にもlane_context[SharedValues::CARTHAGE_OUTDATED_LIST]にこれと同じ構造で値がセットされています。

注意点

 現状はまだ作成したばかりであるのと、他のソースコードを調べながら実装していて、利用できそうなロジックをパクって参考にした部分も多く、実際に挙動を確認できていない箇所が多いです。特にSlackのオプション周り。
 

Actions

  • cocoapods_outdated

    CocoaPodsの最新バージョンのリリース状況を取得して、必要ならSlackへ通知する。
    内部的にはpod outdatedを実行しているだけ。

  • carthage_outdated

    Carthageの最新バージョンのリリース状況を取得して、必要ならSlackへ通知
    内部的にはcarthage outdatedを実行しているだけ。

  • dependency_manager_outdated

    上記2つを実行

Slackへの通知

fastlane-plugin-dependency_manager_outdated.png

インストール

$ fastlane add_plugin dependency_manager_outdated

アクションの実行

$ bundle exec fastlane run cocoapods_outdated
$ bundle exec fastlane run carthage_outdated

Fastlaneへの組み込み

lane :test_cocoapods do |options|
  cocoapods_outdated(
    no_repo_update: true,
    slack_url: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
  )
end
lane :test_carthage do |options|
  carthage_outdated(
    project_directory: "path/to/xcode/project",
  )
end

プラグインのヘルプ

+-----------------------------------------+---------+------------------------------+
|                                   Used plugins                                   |
+-----------------------------------------+---------+------------------------------+
| Plugin                                  | Version | Action                       |
+-----------------------------------------+---------+------------------------------+
| fastlane-plugin-dependency_manager_out  | 0.2.1   | cocoapods_outdated           |
| dated                                   |         | dependency_manager_outdated  |
|                                         |         | carthage_outdated            |
+-----------------------------------------+---------+------------------------------+

+-----------------------------------------+-----------------------------------------+------------------+
|                                      Available fastlane actions                                      |
+-----------------------------------------+-----------------------------------------+------------------+
| Action                                  | Description                             | Author           |
+-----------------------------------------+-----------------------------------------+------------------+
|                                            ...                                                       |
| carthage_outdated                       | Check outdated Carthage dependencies    | matsuda          |
|                                            ...                                                       |
| cocoapods_outdated                      | Check outdated CocoaPods dependencies   | matsuda          |
|                                            ...                                                       |
+-----------------------------------------+-----------------------------------------+------------------+

cocoapods_outdatedアクション

$ bundle exec fastlane action cocoapods_outdated

############################ 省略 ##############################

+-------------------+------------------------------+------------------------------+------------------------------+
|                                           cocoapods_outdated Options                                           |
+-------------------+------------------------------+------------------------------+------------------------------+
| Key               | Description                  | Env Var                      | Default                      |
+-------------------+------------------------------+------------------------------+------------------------------+
| project_directory | The path to the root of the  | DEPENDENCY_MANAGER_PROJECT_  |                              |
|                   | project directory            | DIRECTORY                    |                              |
| use_bundle_exec   | Use bundle exec when there   | DEPENDENCY_MANAGER_COCOAPOD  | true                         |
|                   | is a Gemfile presented       | S_USE_BUNDLE_EXEC            |                              |
| no_repo_update    | Skip running `pod repo       | COCOAPODS_OUTDATED_REPO_UPD  |                              |
|                   | update` before install       | ATE                          |                              |
| slack_url         | Create an Incoming WebHook   | DEPENDENCY_MANAGER_SLACK_UR  |                              |
|                   | for your Slack group to      | L                            |                              |
|                   | post results there           |                              |                              |
| slack_channel     | #channel or @username        | DEPENDENCY_MANAGER_SLACK_CH  |                              |
|                   |                              | ANNEL                        |                              |
| slack_username    | Overrides the webhook's      | DEPENDENCY_MANAGER_SLACK_US  | fastlane                     |
|                   | username property if         | ERNAME                       |                              |
|                   | slack_use_webhook_configure  |                              |                              |
|                   | d_username_and_icon is       |                              |                              |
|                   | false                        |                              |                              |
| slack_icon_url    | Overrides the webhook's      | DEPENDENCY_MANAGER_SLACK_IC  | https://s3-eu-west-1.amazon  |
|                   | image property if            | ON_URL                       | aws.com/fastlane.tools/fast  |
|                   | slack_use_webhook_configure  |                              | lane.png                     |
|                   | d_username_and_icon is       |                              |                              |
|                   | false                        |                              |                              |
| skip_slack        | Don't publish to slack,      | DEPENDENCY_MANAGER_SKIP_SLA  | false                        |
|                   | even when an URL is given    | CK                           |                              |
+-------------------+------------------------------+------------------------------+------------------------------+
* = default value is dependent on the user's system

+-------------------------+-------------------------------------------------------+
|                       cocoapods_outdated Output Variables                       |
+-------------------------+-------------------------------------------------------+
| Key                     | Description                                           |
+-------------------------+-------------------------------------------------------+
| COCOAPODS_OUTDATED_LIST | List of the outdated pods in the current Podfile.lock |
+-------------------------+-------------------------------------------------------+

############################ 省略 ##############################

carthage_outdatedアクション

$ bundle exec fastlane action carthage_outdated

############################ 省略 ##############################

+-------------------+------------------------------+------------------------------+------------------------------+
|                                           carthage_outdated Options                                            |
+-------------------+------------------------------+------------------------------+------------------------------+
| Key               | Description                  | Env Var                      | Default                      |
+-------------------+------------------------------+------------------------------+------------------------------+
| project_directory | The path to the root of the  | DEPENDENCY_MANAGER_PROJECT_  |                              |
|                   | project directory            | DIRECTORY                    |                              |
| use_ssh           | Use SSH for downloading      | DEPENDENCY_MANAGER_CARTHAGE  |                              |
|                   | GitHub repositories          | _USE_SSH                     |                              |
| slack_url         | Create an Incoming WebHook   | DEPENDENCY_MANAGER_SLACK_UR  |                              |
|                   | for your Slack group to      | L                            |                              |
|                   | post results there           |                              |                              |
| slack_channel     | #channel or @username        | DEPENDENCY_MANAGER_SLACK_CH  |                              |
|                   |                              | ANNEL                        |                              |
| slack_username    | Overrides the webhook's      | DEPENDENCY_MANAGER_SLACK_US  | fastlane                     |
|                   | username property if         | ERNAME                       |                              |
|                   | slack_use_webhook_configure  |                              |                              |
|                   | d_username_and_icon is       |                              |                              |
|                   | false                        |                              |                              |
| slack_icon_url    | Overrides the webhook's      | DEPENDENCY_MANAGER_SLACK_IC  | https://s3-eu-west-1.amazon  |
|                   | image property if            | ON_URL                       | aws.com/fastlane.tools/fast  |
|                   | slack_use_webhook_configure  |                              | lane.png                     |
|                   | d_username_and_icon is       |                              |                              |
|                   | false                        |                              |                              |
| skip_slack        | Don't publish to slack,      | DEPENDENCY_MANAGER_SKIP_SLA  | false                        |
|                   | even when an URL is given    | CK                           |                              |
+-------------------+------------------------------+------------------------------+------------------------------+
* = default value is dependent on the user's system

+--------------------------+-------------------------------------------------------+
|                        carthage_outdated Output Variables                        |
+--------------------------+-------------------------------------------------------+
| Key                      | Description                                           |
+--------------------------+-------------------------------------------------------+
| CARTHAGE_OUTDATED_LIST   | List of the outdated dependencies in the current      |
|                          | Cartfile.resolved                                     |
| CARTHAGE_REPOSITORY_LIST | List of dependencies in the current Cartfile.resolved |
+--------------------------+-------------------------------------------------------+

############################ 省略 ##############################

dependency_manager_outdated

省略

9
0
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
9
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?