$30 off During Our Annual Pro Sale. View Details »

[potatotips #70] license-list-pluginを使ってOSSライセンス画面を自動生成する / license-list-plugin

[potatotips #70] license-list-pluginを使ってOSSライセンス画面を自動生成する / license-list-plugin

オンライン開催されたpotatotips #70で発表した資料です。
https://potatotips.connpass.com/event/178565/

syarihu

July 10, 2020
Tweet

More Decks by syarihu

Other Decks in Technology

Transcript

  1. license-list-pluginを使って
    OSSライセンス画面を自動生成する
    2020/07/10 (Fri)
    potatotips #70
    @syarihu

    View Slide

  2. Taichi Sato (@syarihu)
    ● Money Forward, Inc.
    ○ Android Engineer
    ● TechBooster

    View Slide

  3. View Slide

  4. OSSライセンス画面を手軽に作るためのツール
    ● oss-licenses-plugin
    ○ Google Play Services
    ● LicenseToolsPlugin
    ○ cookpad
    ● license-list-plugin
    ○ jmatsu

    View Slide

  5. OSSライセンス画面を作るためのツール
    ● oss-licenses-plugin
    ○ Google Play Services
    ● LicenseToolsPlugin
    ○ cookpad
    ● license-list-plugin
    ○ jmatsu

    View Slide

  6. oss-licenses-plugin
    ● Googleが公式で提供している
    ● ライセンスリストを自動生成、特定のActivityを呼び出す
    だけ
    ○ カスタマイズはできない
    ○ UIはちょっと微妙
    ● 一部ライセンスが表示されないなどの問題があった
    ○ 依存関係が多い場合に問題に気づきにくい

    View Slide

  7. View Slide

  8. jmatsu/license-list-plugin
    ● ライセンスリストを自動生成し、yamlに定義ファイルを出

    ○ 人が読みやすい形なので、ライセンスの追加/変更/削
    除も簡単にできる
    ○ oss-license-pluginと違いライセンスリストが隠蔽され
    ていないため、差分も分かりやすい

    View Slide

  9. license-list-plugin
    ● 定義ファイルを元に表示用のhtmlを自動生成したり、カス
    タマイズした画面を提供するために利用可能なjsonの出
    力も可能
    ● ローカルライブラリにも対応

    View Slide

  10. license-list-plugin
    ● ライセンスリストから除外したいライブラリがある場合
    は.artifactignoreに記述することで簡単に除外可能
    ● cookpad/LicenseToolsPluginを使っている場合は
    cookpadのプラグインで利用するlicenses.ymlからの移
    行も可能

    View Slide

  11. RecyclerView HTML

    View Slide

  12. license-list-pluginへの移行
    ● oss-licenses-pluginは便利だが、UIが微妙だったり、一
    部ライセンスが表示されないなどの問題があったことか
    ら、ライセンス定義ファイルを自分で管理できたり、機能
    が充実しているlicense-list-pluginへ移行することにした

    View Slide

  13. license-list-pluginをどうやって使っているか
    ● 定義ファイルからjsonに吐き出して、jsonを元に
    RecyclerViewで画面を構築
    ○ 最初作るのは手間だが、アプリのテーマカラーに合わ
    せられるし、1回作ってしまえばその後は定義ファイル
    を更新するだけでOK

    View Slide

  14. license-list-pluginをどうやって使っているか
    ● 依存関係の更新時にライセンスリストを更新するのを忘
    れてしまう可能性がある
    ○ 依存関係を更新したら自動でライセンス定義ファイル
    を更新するPRを作成

    View Slide

  15. ライセンス定義ファイルを自動で更新するPRを作成
    ● 依存関係をまとめたファイルDep.ktが変更されたかを
    Dangerを使って検知
    ○ 検知したらPRに特定のラベルをつける
    ● GitHub Actionsで特定のラベルがついたときに発火する
    ワークフローを作成
    ○ ライセンスリストを更新して自動でPRを立てるジョブを
    作る

    View Slide

  16. Dangerfile - 依存関係が更新されている場合はラベルをつける
    begin
    target_branch = github.branch_for_base.match(/release|develop/)
    is_dependencies_updated =
    git.modified_files.grep(/.*Dep.kt/).empty?
    if target_branch && !is_dependencies_updated
    pr_number = github.pr_json["number"]
    auto_label.set(pr_number, "Update licenses", "#1d76db")
    end
    end

    View Slide

  17. Dangerfile - 依存関係が更新されている場合はラベルをつける
    begin
    target_branch = github.branch_for_base.match(/release|develop/)
    is_dependencies_updated =
    git.modified_files.grep(/.*Dep.kt/).empty?
    if target_branch && !is_dependencies_updated
    pr_number = github.pr_json["number"]
    auto_label.set(pr_number, "Update licenses", "#1d76db")
    end
    end

    View Slide

  18. Dangerfile - 依存関係が更新されている場合はラベルをつける
    begin
    target_branch = github.branch_for_base.match(/release|develop/)
    is_dependencies_updated =
    git.modified_files.grep(/.*Dep.kt/).empty?
    if target_branch && !is_dependencies_updated
    pr_number = github.pr_json["number"]
    auto_label.set(pr_number, "Update licenses", "#1d76db")
    end
    end

    View Slide

  19. Dangerfile - 依存関係が更新されている場合はラベルをつける
    begin
    target_branch = github.branch_for_base.match(/release|develop/)
    is_dependencies_updated =
    git.modified_files.grep(/.*Dep.kt/).empty?
    if target_branch && !is_dependencies_updated
    pr_number = github.pr_json["number"]
    auto_label.set(pr_number, "Update licenses", "#1d76db")
    end
    end

    View Slide

  20. .github/workflow.yml - ラベルがついたら発火する
    name: Update license list
    on:
    pull_request:
    types:
    - labeled

    View Slide

  21. .github/workflow.yml - 特定のラベルのみジョブを実行する
    jobs:
    build:
    runs-on: ubuntu-latest
    if: github.event.label.name == 'Update licenses'
    steps:
    - uses: actions/checkout@v2
    with:
    ref: ${{ github.head_ref }}
    - name: set up JDK 1.8
    uses: actions/setup-java@v1
    with:
    java-version: 1.8

    View Slide

  22. .github/workflow.yml - 特定のラベルのみジョブを実行する
    jobs:
    build:
    runs-on: ubuntu-latest
    if: github.event.label.name == 'Update licenses'
    steps:
    - uses: actions/checkout@v2
    with:
    ref: ${{ github.head_ref }}
    - name: set up JDK 1.8
    uses: actions/setup-java@v1
    with:
    java-version: 1.8

    View Slide

  23. .github/workflow.yml - ライセンス定義ファイルを更新する
    - name: Update license list
    run: |
    # ライセンス定義ファイルの差分を更新
    ./gradlew mergeReleaseLicenseList
    # 定義ファイルを元にjsonを更新
    ./gradlew visualizeReleaseLicenseList

    View Slide

  24. .github/workflow.yml - ライセンス定義ファイルを更新する
    - name: Update license list
    run: |
    # ライセンス定義ファイルの差分を更新
    ./gradlew mergeReleaseLicenseList
    # 定義ファイルを元にjsonを更新
    ./gradlew visualizeReleaseLicenseList

    View Slide

  25. .github/workflow.yml - ライセンス定義ファイルを更新する
    - name: Update license list
    run: |
    # ライセンス定義ファイルの差分を更新
    ./gradlew mergeReleaseLicenseList
    # 定義ファイルを元にjsonを更新
    ./gradlew visualizeReleaseLicenseList

    View Slide

  26. .github/workflow.yml - 自動でPRを作成する
    - name: Create Pull Request
    uses: peter-evans/create-pull-request@v2
    with:
    token: ${{ secrets.REPO_ACCESS_TOKEN }}
    commit-message: Updated license by license-list-plugin
    committer: syarihu
    author: syarihu
    title: Update license
    body: |
    This PR has been auto-generated
    branch: update-license-list
    branch-suffix: short-commit-hash

    View Slide

  27. .github/workflow.yml - 自動でPRを作成する
    - name: Create Pull Request
    uses: peter-evans/create-pull-request@v2
    with:
    token: ${{ secrets.REPO_ACCESS_TOKEN }}
    commit-message: Updated license by license-list-plugin
    committer: syarihu
    author: syarihu
    title: Update license
    body: |
    This PR has been auto-generated
    branch: update-license-list
    branch-suffix: short-commit-hash

    View Slide

  28. .github/workflow.yml - 自動でPRを作成する
    - name: Create Pull Request
    uses: peter-evans/create-pull-request@v2
    with:
    token: ${{ secrets.REPO_ACCESS_TOKEN }}
    commit-message: Updated license by license-list-plugin
    committer: syarihu
    author: syarihu
    title: Update license
    body: |
    This PR has been auto-generated
    branch: update-license-list
    branch-suffix: short-commit-hash

    View Slide

  29. View Slide

  30. View Slide

  31. ライセンス定義ファイルを自動で更新するPRを作成
    ● これで依存関係を更新したときに自動でPRが作成される
    ようになったので、ライセンスの更新忘れも無くなり人間
    の手間もほとんど無くなった
    ● コミット時に自動でDeployGateにアップロードしてPRに
    QRコードがコメントされるようにしているので、差分に問題
    がない場合はこれで動作確認をするだけでよくなった。最
    高!

    View Slide

  32. まとめ
    ● license-list-pluginを使うと定義ファイルの管理が簡単に
    なる
    ● json出力すればアプリに合ったテーマのOSSライセンス
    画面を構築可能
    ● ライセンス定義ファイルを自動更新、自動PRすれば手間
    も更新忘れも無くなる

    View Slide

  33. 参考資料
    ● jmatsu/license-list-plugin: Gradle plugin to manage licenses of your
    Android app's dependencies.
    ○ https://github.com/jmatsu/license-list-plugin
    ● Including Open Source Notices
    ○ https://developers.google.com/android/guides/opensource
    ● cookpad/LicenseToolsPlugin: Gradle plugin to check library licenses
    and generate license pages for Android
    ○ https://github.com/cookpad/LicenseToolsPlugin

    View Slide

  34. ありがとうございました

    View Slide