Skip to main content

Dependabot で更新する依存関係を制御する

定義した方法で、指定したパッケージが Dependabot で自動的に更新されるように dependabot.yml ファイルを構成する方法について説明します。

この機能を使用できるユーザーについて

Users with write access

          `dependabot.yml` ファイルにオプションを追加することで、ニーズに合わせて Dependabot 構成をカスタマイズできます。 たとえば、Dependabot が正しいパッケージ マニフェスト ファイルを使い、保持する依存関係のみを更新するようにすることができます。

この記事では、便利なカスタマイズ オプションをまとめています。

マニフェスト ファイルの複数の場所を定義する

複数の場所に格納されているマニフェスト ファイルに対して Dependabot version updates を有効にする場合は、directories ではなく directory を使用できます。 たとえば、この構成では、異なるディレクトリに格納されているマニフェスト ファイルに対して 2 つの異なる更新スケジュールを設定しています。

YAML
# Specify the locations of the manifest files to update for each package manager
# using both `directories` and `directory`

version: 2
updates:
  - package-ecosystem: "bundler"
    # Update manifest files stored in these directories weekly
    directories:
      - "/frontend"
      - "/backend"
      - "/admin"
    schedule:
      interval: "weekly"
  - package-ecosystem: "bundler"
    # Update manifest files stored in the root directory daily
    directory: "/"
    schedule:
      interval: "daily"
  • パターンを使ってディレクトリの範囲を指定するには

    YAML
    # Specify the root directory and directories that start with "lib-",
    # using globbing, for locations of manifest files
    
    version: 2
    updates:
      - package-ecosystem: "composer"
        directories:
          - "/"
          - "/lib-*"
        schedule:
          interval: "weekly"
    
  • 現在のディレクトリと再帰的なサブディレクトリ内のマニフェストを指定するには

    YAML
    # Specify all directories from the current layer and below recursively,
    # using globstar, for locations of manifest files
    
    version: 2
    updates:
      - package-ecosystem: "composer"
        directories:
          - "**/*"
        schedule:
          interval: "weekly"
    

特定の依存関係を無視する

プロジェクト内の特定の依存関係からの変更を採用する準備ができていない場合は、Dependabot を構成して、バージョン更新プログラムとセキュリティ更新プログラムのpull request を開いたときにそれらの依存関係を無視できます。 次のいずれかの方法で実行できます:

  •         `ignore` ファイル内の依存関係に `dependabot.yml` オプションを構成します。
    
    * これを使うと、特定の依存関係、バージョン、更新プログラムの種類に対して更新プログラムを無視できます。
    • 詳しくは、「ignore」の を参照してください。
  • バージョン更新プログラムとセキュリティ更新プログラムの Dependabot pull request で @dependabot ignore のコメント コマンドを使用します。 * コメント コマンドを使うと、特定の依存関係やバージョンの更新プログラムを無視できます。

以下に、ignore を使って更新する依存関係をカスタマイズする方法の例をいくつか示します。

  • 特定のバージョンより後の更新プログラムを無視するには

    YAML
    ignore:
      - dependency-name: "lodash:*"
        # Ignore versions of Lodash that are equal to or greater than 1.0.0
        versions: [ ">=1.0.0" ]
    
    YAML
    ignore:
      - dependency-name: "sphinx"
        versions: [ "[1.1,)" ]
    
  • パッチ更新プログラムを無視するには

    YAML
    ignore:
      - dependency-name: "@types/node"
        # Ignore patch updates for Node
        update-types: ["version-update:semver-patch"]
    
  • 特定のバージョンまたはバージョンの範囲を無視するには、「特定のバージョンまたはバージョンの範囲を無視する」を参照してください。

依存関係または無視条件の無視を解除する場合は、dependabot.yml ファイルから無視条件を削除するか、pull request を再度開きます。

グループ化された更新プログラムの pull request については、@dependabot unignore コメント コマンドも使用できます。 @dependabot unignore のコメント コマンドを使用すると、Dependabot pull requestにコメントを付けることで、次のことを行うことができます。

  • 特定の無視条件を無視解除する
  • 特定の依存関係を無視解除する
  • Dependabot の pull request において、すべての依存関係のすべての無視条件を無視解除する

詳しくは、「依存関係の更新に関するPull Requestを管理する」をご覧ください。

特定の依存関係の更新を許可する

          `allow` を使って、保持する依存関係について Dependabot に指示することができます。 通常、`allow` は `ignore` と組み合わせて使います。

詳しくは、「allow」の を参照してください。

Dependabot の既定では、マニフェストに明示的に定義されている依存関係 (direct の依存関係) に対してのみバージョン更新プログラムの pull request が作成されます。 この構成は、allow を使って、種類が all の依存関係を保持するように Dependabot に指示します。 つまり、direct 依存関係とその依存関係 (間接依存関係、サブ依存関係、または一時依存関係とも呼ばれます) の両方です。 さらに、この構成では、パターン org.xwiki.* と一致する名前を持つすべての依存関係を無視するように Dependabot に指示します。これは、保持するプロセスは別にあるためです。

ヒント

Dependabot により、すべての許可された依存関係がチェックされ、無視された依存関係は除外されます。 依存関係が allowignore のステートメントと一致する場合は、無視されます。

YAML
version: 2
registries:
  # Helps find updates for non Maven Central dependencies
  maven-xwiki-public:
    type: maven-repository
    url: https://nexus.xwiki.org/nexus/content/groups/public/
    username: ""
    password: ""
  # Required to resolve xwiki-common SNAPSHOT parent pom
  maven-xwiki-snapshots:
    type: maven-repository
    url: https://maven.xwiki.org/snapshots
    username: ""
    password: ""
updates:
  - package-ecosystem: "maven"
    directory: "/"
    registries:
      - maven-xwiki-public
      - maven-xwiki-snapshots
    schedule:
      interval: "weekly"
    allow:
      # Allow both direct and indirect updates for all packages.
      - dependency-type: "all"
    ignore:
      # Ignore XWiki dependencies. We have a separate process for updating them
      - dependency-name: "org.xwiki.*"
    open-pull-requests-limit: 15

特定のバージョンまたはバージョンの範囲を無視する

          `versions` を `ignore` と組み合わせて使うと、特定のバージョンまたはバージョンの範囲を無視できます。

詳しくは、「versions」の を参照してください。

  • 特定のバージョンを無視するには

    YAML
    ignore:
      - dependency-name: "django*"
        # Ignore version 11
        versions: [ "11" ]
    
  • バージョンの範囲を無視するには

    YAML
        ignore:
          - dependency-name: "@types/node"
            versions: ["15.x", "14.x", "13.x"]
          - dependency-name: "xdg-basedir"
            # 5.0.0 has breaking changes as they switch to named exports
            # and convert the module to ESM
            # We can't use it until we switch to ESM across the project
            versions: ["5.x"]
          - dependency-name: "limiter"
            # 2.0.0 has breaking changes
            # so we want to delay updating.
            versions: ["2.x"]
    

無視するセマンティック バージョニング レベルを指定する

          `update-types` を使って、無視する 1 つ以上のセマンティック バージョニング (SemVer) レベルを指定できます。

詳しくは、「update-types」の を参照してください。

この例では、Dependabot はノードのパッチ バージョンを無視します。

YAML
version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "daily"
    ignore:
      - dependency-name: "express"
        # For Express, ignore all updates for version 4 and 5
        versions: ["4.x", "5.x"]
        # For Lodash, ignore all updates
      - dependency-name: "lodash"
      - dependency-name: "@types/node"
        # For Node types, ignore any patch versions
        update-types: ["version-update:semver-patch"]

バージョン管理戦略を定義する

Dependabot の既定では、アプリとして特定された依存関係の最小バージョン要件の引き上げが試行されます。また、ライブラリとして特定された依存関係の新しいバージョンと以前のバージョンの両方を含むように、許可されるバージョン要件は拡大されます。

この既定の戦略は変更できます。 詳しくは、「versioning-strategy」の を参照してください。

この例では、Dependabot により、アプリとライブラリの両方の新しいバージョンと一致するように最小バージョン要件が引き上げられます。

YAML
version: 2
updates:
  - package-ecosystem: npm
    directory: "/"
    schedule:
      interval: daily
    # Increase the minimum version for all npm dependencies
    versioning-strategy: increase

この例では、元の制約で新しいバージョンが許可されない場合、Dependabot により、最小バージョン要件をのみが引き上げられます。

YAML
version: 2
updates:
- package-ecosystem: pip
  directory: "/"
  schedule:
    interval: daily
  open-pull-requests-limit: 20
  rebase-strategy: "disabled"
  # Increase the version requirements for pip
  # only when required
  versioning-strategy: increase-if-necessary

ベンダリングされた依存関係を更新する

更新時に固有の依存関係をベンダリングするように Dependabot に指示できます。

Dependabot により、Go モジュールのベンダリングされた依存関係は自動的に保持されます。また、ベンダリングされた依存関係も更新するように Bundler を構成できます。

詳しくは、「vendor」の を参照してください。

この例では、Bundler の vendortrue に設定されています。つまり、Dependabot により、リポジトリの vendor/cache ディレクトリに格納されている Bundler の依存関係も保持されます。

YAML
version: 2
updates:
- package-ecosystem: bundler
  directory: "/"
  # Vendoring Bundler
  vendor: true
  schedule:
    interval: weekly
    day: saturday
  open-pull-requests-limit: 10