[GitHub] Dependabot Grouped version updates で Production と Development の依存関係を分けてグループ化する機能が追加されました

2023.08.14

こんにちは、CX 事業本部 Delivery 部の若槻です。

以前のアップデートで、Dependabot version updates によりオープンされる Pull Request をグループ化する機能(Grouped version updates)が公開ベータで利用可能となりました。

これにより、複数の依存関係を更新する Pull Request をグループ化して、レビューの負荷を軽減することができます。

そしてさらに直近のアップデートで、Grouped version updates で Production と Development の依存関係を分けてグループ化する機能が追加されました。

試してみた

dependabot.yml の設定

Grouped version updates のドキュメントは下記となります。

Use to specify a dependency type to be included in the group. dependency-type can be development or production

dependency-typeオプションでdevelopmentproductionのいずれかを指定することで、グループ化する依存関係を分けることができます。

.github/dependabot.yml

version: 2
updates:
  - package-ecosystem: npm
    directory: /
    schedule:
      interval: daily
    groups:
      prod-dependency:
        dependency-type: production
      dev-dependency:
        dependency-type: development

動作確認

package.jsonで最新でない依存関係をdependenciesdevDependenciesにそれぞれ指定します。

package.json

{
  "devDependencies": {
    "eslint": "8.46.0",
    "typescript": "4.1.6"
  },
  "dependencies": {
    "@aws-sdk/client-athena": "3.387.0",
    "constructs": "10.2.68"
  }
}

コミットを push すると、下記のようにdev-dependencyprod-dependencyの 2 つのグループに分けられて Pull Request が作成されました。

それぞれの Pull Request の変更を確認すると、dependenciesdevDependenciesでグルーピングされていることがわかります。

patterns および exclude-patterns と組み合わせて使用する

dependency-typeはさらにpatternsまたはexclude-patternsオプションと組み合わせて使用することができます。

dependabot.ymlを次のように変更します。

.github/dependabot.yml

version: 2
updates:
  - package-ecosystem: npm
    directory: /
    schedule:
      interval: daily
    groups:
      prod-dependency:
        dependency-type: production
        patterns:
          - '@aws-sdk/*'
      dev-dependency:
        dependency-type: development
        exclude-patterns:
          - esbuild

package.jsondevDependenciesおよびdependenciesに最新でないバージョンで依存関係を追加します。それぞれpatternsおよびexclude-patternsにマッチするものを 1 つずつ追加しています。

package.json

{
  "devDependencies": {
    "esbuild": "0.19.0",
    "husky": "7.0.4"
  },
  "dependencies": {
    "@aws-sdk/client-s3": "3.387.0",
    "dayjs": "1.11.8"
  }
}

変更を push すると、patternsにマッチしexclude-patternsにマッチしない依存関係がグループ化されて Pull Request が作成されました。またそれ以外の依存関係のアップデートは個別に Pull Request が作成されています。

おわりに

Dependabot Grouped version updates で Production と Development の依存関係を分けてグループ化する機能が追加されたのでご紹介しました。

Production と Development で依存関係のアップデートのライフサイクルを分けたい場合に役に立ちそうですね。

以上