Skip to main content

依存関係の更新の管理

Copilot Chat を使うと、Dependabot を設定して依存関係の更新を効率化できます。

依存関係の更新を自動化する

シナリオ例

プロジェクトが多数のライブラリとパッケージに依存しているとします。 脆弱な依存関係や古い依存関係は、プロジェクトやそれに依存する他のプロジェクトに影響を与えるようなセキュリティ リスクを生み出します。

Copilot Chat を使うと、Dependabot のセキュリティとバージョンの更新を設定できるため、依存関係を常に最も安全で最新のバージョンに保つことができます。 「Dependabot のセキュリティ アップデート」と「GitHub Dependabot のバージョンアップデートについて」を参照してください。

始める前に、リポジトリの [Settings] で Dependabot が完全に有効になっていることを確認します。

  1. [Code security] 設定で、Dependabot alertsDependabot security updates の両方が [Enabled] に設定されていることを確認します。
  2. 空の .github/dependabot.yml ファイルを作成してリポジトリにコミットします。

プロンプトの例

リポジトリがコンテキストのプロンプトに接続されていることを確認します。

Analyze the codebase and project structure of this repository. Detect all package managers and package ecosystems in use, including their respective locations (e.g., npm, yarn, pip, maven, gradle, composer, github-actions, etc.).

For each detected ecosystem, create a configuration entry in a single, top-level .github/dependabot.yml file that enables security and version updates on a reasonable schedule. Use the recommended best practices for each ecosystem. Clearly specify the directory for each ecosystem detected. If multiple ecosystems or multiple directories are present, include them all in the configuration.

In the output, include any notes on the configuration or best practices, as well as next steps that include how to commit the dependabot.yml file to the repository via the GitHub web browser and how to check that Dependabot version updates and Dependabot security updates are enabled.

出力例

Copilot Chat を使ってリポジトリを分析し、dependabot.yml 構成ファイルの内容を作成します。これにより、スキャンする必要がある依存関係を Dependabot に伝えます。

version: 2
updates:
  # Python (pip)
  - package-ecosystem: "pip"
    directory: "/"                     # Location of requirements.txt
    schedule:
      interval: "weekly"               # Weekly updates are a good balance for libraries
      day: "sunday"
      time: "06:00"
      timezone: "UTC"
    open-pull-requests-limit: 5
    allow:
      - dependency-type: "all"
    commit-message:
      prefix: "pip"
    labels:
      - "dependencies"
      - "python"
    ignore:
      - dependency-name: "pip"         # Ignore pip self-updates

  # GitHub Actions
  - package-ecosystem: "github-actions"
    directory: "/"                     # Looks for workflow files under .github/workflows/
    schedule:
      interval: "weekly"
      day: "sunday"
      time: "06:00"
      timezone: "UTC"
    open-pull-requests-limit: 5
    commit-message:
      prefix: "actions"
    labels:
      - "dependencies"
      - "github-actions"

dependabot.yml ファイルをリポジトリにコミットすると、脆弱な依存関係や古い依存関係が検出されるたびに、Dependabot がリポジトリに対して pull request を開始するようになります。

依存関係管理をカスタマイズする

シナリオ例

シナリオ例

チームが数か月間基本的な Dependabot 構成を使っていて、依存関係の更新の pull request を多数受け取っているとします。 ただし、あなたは次のことがわかっています。

  • 誰も自動的に割り当てられないため、pull request はレビューされないまま残っています。
  • あなたは、Pull request をラベル経由でチームのプロジェクト ボードに自動的に追加したいと考えています。
  • 同時依存関係の pull request が多すぎるため、CI が過負荷になっています。
  • 運用環境に影響しない開発用の依存関係に対して更新プログラムを取得しています。

適切なチーム メンバーに pull request を自動的に割り当てる、pull request をプロジェクト ボードに追加するためのラベルを追加する、未解決の pull request 数を制限する、運用環境の依存関係のみに焦点を当てるなど、チームのワークフローに合わせて Dependabot 構成をカスタマイズする必要があります。

Copilot Chat を使って、チームのニーズにより適した更新版の dependabot.yml を作成できます。

プロンプトの例

I want to customize my pull requests for Dependabot security and version updates, so that:

* Pull requests are automatically assigned to the team "octocat-reviewers."

* The label "security-management" is automatically added to every pull request.

* The number of open Dependabot PRs is limited.

* Development dependencies are ignored.

Draft an update to the dependabot.yml file in my repository that specifies these customization options.

ヒント

出力例

version: 2
updates:
  # Python (pip)
  - package-ecosystem: "pip"
    directory: "/"
    schedule:
      interval: "weekly"
      day: "sunday"
      time: "06:00"
      timezone: "UTC"
    open-pull-requests-limit: 5
    allow:
      - dependency-type: "production"     # Ignore development dependencies
    assignees:
      - "octocat-reviewers"               # Assign PRs to the team
    labels:
      - "dependencies"
      - "security-management"             # Custom label for all PRs
      - "python"
    commit-message:
      prefix: "pip"
    ignore:
      - dependency-name: "pip"