GitHub Dependabot による依存関係の自動更新管理。
Dependabot は GitHub が提供する依存関係の自動更新ツール。以下の機能を提供する。
| 機能 | 説明 |
|---|---|
| Version Updates | 依存パッケージの新バージョンを検出し、更新PRを自動作成 |
| Security Updates | 脆弱性が発見されたパッケージの修正PRを自動作成 |
| Alerts | 脆弱性のあるパッケージを検出し、通知 |
- 手動での依存関係更新作業が不要
- セキュリティ脆弱性への迅速な対応
- 更新履歴がPRとして記録される
- CI/CDと連携した自動テストが可能
.github/dependabot.yml を作成する。
version: 2
updates:
# npm パッケージの更新
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
timezone: "Asia/Tokyo"
time: "09:00"
target-branch: "main"
open-pull-requests-limit: 10
labels:
- "dependencies"
# GitHub Actions の更新
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
timezone: "Asia/Tokyo"
time: "09:00"
labels:
- "dependencies"
- "github-actions"GitHub リポジトリの Settings → Code security → Dependabot で有効化を確認。
| オプション | 説明 | 例 |
|---|---|---|
version |
設定ファイルのバージョン | 2 |
package-ecosystem |
パッケージマネージャーの種類 | npm, docker, github-actions |
directory |
パッケージ定義ファイルの場所 | /, /packages/app |
schedule.interval |
更新チェックの頻度 | daily, weekly, monthly |
schedule:
interval: "weekly" # daily, weekly, monthly
day: "monday" # 曜日指定(weekly時)
time: "09:00" # 時刻指定
timezone: "Asia/Tokyo" # タイムゾーン# 同時にオープンできるPR数の上限(デフォルト: 5)
open-pull-requests-limit: 10
# PRの対象ブランチ
target-branch: "develop"
# PRに付与するラベル
labels:
- "dependencies"
- "automerge"
# PRのレビュワー
reviewers:
- "username"
- "org/team-name"
# PRのアサイニー
assignees:
- "username"# 特定パッケージを無視
ignore:
- dependency-name: "lodash"
- dependency-name: "aws-sdk"
versions: ["3.x"] # 特定バージョンのみ無視
# 特定パッケージのみ対象
allow:
- dependency-name: "react"
- dependency-name: "next"
# 更新タイプの制限
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-major"] # メジャー更新を無視関連パッケージをまとめて1つのPRにする。
groups:
# React関連をグループ化
react:
patterns:
- "react*"
- "@types/react*"
# ESLint関連をグループ化
eslint:
patterns:
- "eslint*"
- "@typescript-eslint/*"
# テスト関連をグループ化
testing:
patterns:
- "jest*"
- "@testing-library/*"
- "vitest*"commit-message:
prefix: "chore"
prefix-development: "chore"
include: "scope"結果: chore(deps): bump react from 18.2.0 to 18.3.0
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
timezone: "Asia/Tokyo"
time: "09:00"
target-branch: "main"
open-pull-requests-limit: 10
labels:
- "dependencies"
groups:
# 本番依存関係
production:
dependency-type: "production"
# 開発依存関係
development:
dependency-type: "development"
ignore:
# メジャーバージョン更新は手動で対応
- dependency-name: "*"
update-types: ["version-update:semver-major"]GitHub Actions と組み合わせてパッチ・マイナー更新を自動マージする。
# .github/workflows/dependabot-auto-merge.yml
name: Dependabot Auto Merge
on: pull_request
permissions:
contents: write
pull-requests: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto-merge minor and patch updates
if: steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor'
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}セキュリティアップデートは自動的に高優先度で処理される。 Settings → Code security → Dependabot security updates で有効化する。
- CHANGELOG を確認: 破壊的変更がないか確認
- CI テスト結果を確認: 全テストがパスしているか
- 依存関係の互換性: 他のパッケージとの互換性
- セキュリティ修正: セキュリティ関連は優先的にマージ
-
設定ファイルの構文エラー
- YAML の構文が正しいか確認
version: 2が指定されているか確認
-
ディレクトリの指定ミス
package.jsonの場所が正しいか確認
-
PR上限に達している
open-pull-requests-limitを確認- 既存のDependabot PRをマージまたはクローズ
GitHub リポジトリで以下を確認:
- Insights → Dependency graph → Dependabot: 最後の実行状況
- Security → Dependabot alerts: 検出された脆弱性
Settings → Code security → Dependabot → View logs で実行ログを確認できる。