LoginSignup
4

More than 1 year has passed since last update.

DangerでAndroidのビルドワーニングをレポートするプラグインを作ったよ

Last updated at Posted at 2022-06-11

Androidプロジェクトで

  • Dangerを活用したPullRequestの静的解析
  • Ktlintと連携したコードフォーマットのチェック
  • AndroidLintのワーニングレポート

を実践している方は多いのではないでしょうか?

しかし、ビルドワーニングは放置されていませんか?

そこで、ビルドワーニング・エラーをDangerでインラインコメントするプラグインを作りました。
この記事では、このプラグインの使い方をご紹介します。

danger-chikuwa

今回作成したDanger-pluginはこちらです。
https://github.com/watanavex/chikuwa

gemで公開しています。
https://rubygems.org/gems/danger-chikuwa

使い方 (GitHub Actions)

サンプルAndroidプロジェクト
https://github.com/watanavex/android-check-for-chikuwa

GitHub Actionsのワークフロー

全体のサンプルはこちらです
https://github.com/watanavex/android-check-for-chikuwa/blob/main/.github/workflows/pr-check.yaml

重要な部分を抜粋しますと

      - name: Build
        run: ./gradlew assembleDebug 2>&1 | tee build.log
        continue-on-error: true
      - name: Run Danger
        run: danger --remove-previous-comments
        env:
          DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  1. Androidビルドを走らせ ./gradlew assembleDebug
  2. ビルドエラーの出力も対象とするため 2>&1 を付与し
  3. コンソールに出力しつつファイルにリダイレクト tee build.log
  4. Dangerを実行

Dangerfile

全体のサンプルはこちらです
https://github.com/watanavex/android-check-for-chikuwa/blob/main/Dangerfile

重要な部分を抜粋しますと

chikuwa.inline_mode = true
chikuwa.report "build.log"
  1. (option) インラインコメントにしたい場合は inline_mode = true
  2. report にビルド時の出力したファイルを与える

以上です。

動作した様子

スクリーンショット 2022-06-11 21.13.40.png

なぜ chikuwa

深い理由はありません。
我が家の癒し担当の名前を頂きました。

↓ こちらが ちくわです
img.png

最後に

Dangerプラグインchikuwaが、みなさんのプロジェクトでお役に立てたら嬉しいです。
コントリビュートもお待ちしています。

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
4