awesome-copilot Dependabot 配置与管理完全指南:dependabot.yml、更新策略与供应链安全
【免费下载链接】awesome-copilotCommunity-contributed instructions, agents, skills, and configurations to help you make the most of GitHub Copilot.项目地址: https://gitcode.com/GitHub_Trending/aw/awesome-copilot
GitHub Dependabot 是内置在 GitHub 中的依赖管理工具,通过一份dependabot.yml即可覆盖漏洞告警、安全更新与版本更新三类能力。本指南以本仓库(GitHub 推荐项目精选 aw / awesome-copilot)社区贡献的 dependabot 技能 为骨架,结合其完整的 YAML 选项参考、实战配置示例 与 PR 评论命令参考,系统讲解配置文件编写、Monorepo 覆盖、依赖分组、调度优化、安全更新以及 AI 编码代理中的预提交漏洞扫描,读完即可在自己的仓库中落地一套可运行、可维护、可裁剪的 Dependabot 方案。
一、Dependabot 是什么:三大核心能力与单一配置文件
Dependabot 是 GitHub 内置的依赖管理工具,围绕软件供应链安全提供三项核心能力:
- Dependabot Alerts(依赖告警)——当依赖存在已知漏洞(CVE)时通知仓库所有者;
- Dependabot Security Updates(安全更新)——自动创建 PR 修复存在漏洞的依赖;
- Dependabot Version Updates(版本更新)——自动创建 PR 将依赖保持在新版本。
所有配置都集中存放在同一个文件:默认分支上的.github/dependabot.yml。GitHub不支持一个仓库存在多个dependabot.yml文件(详见 SKILL.md)。因此多生态、多目录的覆盖只能通过该文件内的多个updates条目实现,这是理解后续所有配置技巧的前提。
二、配置工作流:四步从零到上线
创建或优化dependabot.yml时,建议遵循以下四步流程(对应 SKILL.md 中的 Configuration Workflow)。
Step 1:识别仓库中的全部依赖生态
扫描仓库中的依赖清单(manifest)文件,确定需要启用哪些生态:
| 生态 | YAML 值 | Manifest 文件 |
|---|---|---|
| npm/pnpm/yarn | npm | package.json、package-lock.json、pnpm-lock.yaml、yarn.lock |
| pip/pipenv/poetry | pip | requirements.txt、Pipfile、pyproject.toml、setup.py |
| uv | uv | pyproject.toml、uv.lock |
| Docker | docker | Dockerfile |
| Docker Compose | docker-compose | docker-compose.yml |
| GitHub Actions | github-actions | .github/workflows/*.yml |
| Go modules | gomod | go.mod |
| Bundler (Ruby) | bundler | Gemfile |
| Cargo (Rust) | cargo | Cargo.toml |
| Composer (PHP) | composer | composer.json |
| NuGet (.NET) | nuget | *.csproj、packages.config |
| .NET SDK | dotnet-sdk | global.json |
| Maven (Java) | maven | pom.xml |
| Gradle (Java) | gradle | build.gradle、build.gradle.kts |
| Terraform | terraform | *.tf |
| OpenTofu | opentofu | *.tf |
| Helm | helm | Chart.yaml |
| Hex (Elixir) | mix | mix.exs |
| Swift | swift | Package.swift |
| Pub (Dart) | pub | pubspec.yaml |
| Bun | bun | bun.lockb |
| Dev Containers | devcontainers | devcontainer.json |
| Git Submodules | gitsubmodule | .gitmodules |
| Pre-commit | pre-commit | .pre-commit-config.yaml |
两点注意事项:
- pnpm 与 yarn 都使用
npm生态值,Dependabot 会自动检测pnpm-lock.yaml/yarn.lock; - Python 项目在存在
uv.lock时优先使用uv生态值,否则使用pip。
如需更完整的生态清单(含 Bazel、Conda、Elm、Julia、Rust Toolchain、vcpkg 等),可查阅 dependabot-yml-reference.md 中的package-ecosystem完整对照表。
Step 2:映射 manifest 的目录位置
对每个生态,找出 manifest 所在的目录。在 Monorepo 场景下,使用directories(复数)配合 Glob 模式一次性覆盖多个目录:
directories: - "/" # 根目录 - "/apps/*" # 所有 app 子目录 - "/packages/*" # 所有 package 子目录 - "/lib-*" # 以 lib- 开头的目录 - "**/*" # 递归(所有子目录)关键差异:directory(单数)不支持 Glob 通配符;只有directories(复数)支持通配符。单目录配置用directory,多目录批量覆盖必须用directories。
Step 3:配置每个生态条目
每个updates条目至少需要三个必填键——package-ecosystem、directory(或directories)与schedule:
- package-ecosystem: "npm" directory: "/" schedule: interval: "weekly"其中顶层version: 2是必填且恒为2。以 example-configs.md 中最基础的单生态配置为例,最小可运行文件长这样:
version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "weekly"Step 4:用分组、标签与调度做优化
在基础条目之上叠加分组(groups)、标签(labels)、提交信息(commit-message)、冷却期(cooldown)等优化手段,具体见下文各节。
三、Monorepo 策略
用 Glob 模式覆盖整个工作区
对于包含大量包的 Monorepo,用 Glob 模式可以避免逐一列出每个目录:
- package-ecosystem: "npm" directories: - "/" - "/apps/*" - "/packages/*" - "/services/*" schedule: interval: "weekly"跨目录分组:group-by: dependency-name
当同一个依赖在多个目录中都有更新时,用group-by: dependency-name可以把它们合并成一个 PR:
groups: monorepo-deps: group-by: dependency-name这会在所有指定目录之间为每个依赖创建一条 PR,显著降低 CI 成本与审查负担。使用限制:
- 所有目录必须使用相同的包生态;
- 仅适用于版本更新(version updates);
- 版本约束不兼容的依赖会拆分成独立 PR。
example-configs.md 中给出了一个典型场景:当lodash在/frontend、/admin-panel、/mobile-app三个目录中同时更新时,group-by: dependency-name会生成单一 PR。
工作区之外的独立包
如果某个目录拥有自己的 lockfile 且不属于工作区(例如.github/下的脚本),需要为它单独创建一个生态条目,指向该目录。
四、依赖分组:减少 PR 噪音
分组(groups)是减少 Dependabot PR 噪音最有效的机制,支持按类型、按名称模式、按 SemVer 级别以及按更新类型(版本/安全)组合过滤。
按依赖类型分组
groups: dev-dependencies: dependency-type: "development" update-types: ["minor", "patch"] production-dependencies: dependency-type: "production" update-types: ["minor", "patch"]把开发依赖与生产依赖分开成组,可以优先审查生产依赖变更。
按名称模式分组
groups: angular: patterns: ["@angular*"] update-types: ["minor", "patch"] testing: patterns: ["jest*", "@testing-library*", "ts-jest"]patterns支持*通配符;如需排除组内特定包,可用exclude-patterns(例如["@angular/cdk"])。
安全更新的分组
groups: security-patches: applies-to: security-updates patterns: ["*"] update-types: ["patch", "minor"]分组的关键行为
- 同时匹配多个组的依赖,进入最先匹配的组;
applies-to缺省时为version-updates(版本更新);- 未被任何组覆盖的依赖,仍然各自生成独立 PR。
groups的完整参数对照(IDENTIFIER、applies-to、dependency-type、patterns、exclude-patterns、update-types、group-by)见 dependabot-yml-reference.md。
五、多生态分组:跨生态合并 PR
multi-ecosystem-groups(顶层键)可以把不同包生态的更新合并进同一条 PR,例如把 Docker 镜像与 Terraform Provider 的更新统一成一个"基础设施" PR:
version: 2 multi-ecosystem-groups: infrastructure: schedule: interval: "weekly" labels: ["infrastructure", "dependencies"] assignees: ["@platform-team"] updates: - package-ecosystem: "docker" directory: "/" patterns: ["nginx", "redis"] multi-ecosystem-group: "infrastructure" - package-ecosystem: "terraform" directory: "/" patterns: ["aws*"] multi-ecosystem-group: "infrastructure"注意:使用multi-ecosystem-group时,每个生态条目中的patterns键是必填的。此外,multi-ecosystem-groups顶层块同样支持schedule、labels、assignees等配置。
六、PR 定制
标签(labels)
labels: - "dependencies" - "npm"- 设为
labels: []可禁用包括默认标签在内的所有标签; - 仓库中存在的 SemVer 标签(
major、minor、patch)始终会被自动应用。
提交信息(commit-message)
commit-message: prefix: "deps" prefix-development: "deps-dev" include: "scope" # 在 prefix 后附加 deps/deps-dev 作用域prefix最长 50 个字符;如果以字母或数字结尾,会自动追加冒号。include: "scope"会把deps/deps-dev作为 scope 拼接到 prefix 之后。
指派人(assignees)与里程碑(milestone)
assignees: ["security-team-lead"] milestone: 4 # 取自里程碑 URL 中的数字 ID指派人需要具备写权限(组织仓库可放宽为读权限)。
分支名分隔符
pull-request-branch-name: separator: "-" # 可选值:"-", "_", "/";默认是 /目标分支(target-branch)
target-branch: "develop" # PR 指向该分支而非默认分支注意:设置target-branch后,安全更新仍然始终指向默认分支;生态配置仅对版本更新生效。
七、调度优化
调度间隔(interval)
支持的值:daily、weekly、monthly、quarterly、semiannually、yearly、cron。
schedule: interval: "weekly" day: "monday" # 仅 weekly 可用 time: "09:00" # HH:MM 格式 timezone: "America/New_York"参数对照(来自 dependabot-yml-reference.md):
| 参数 | 取值 | 说明 |
|---|---|---|
interval | 上述 7 种 | 必填 |
day | monday–sunday | 仅 weekly |
time | HH:MM | 默认 UTC |
timezone | IANA 时区名 | 如America/New_York |
cronjob | Cron 表达式 | interval: "cron"时必填 |
Cron 表达式
schedule: interval: "cron" cronjob: "0 9 * * 1" # 每周一早上 9 点冷却期(cooldown)
延迟新发布版本的更新,避免过早踩坑:
cooldown: default-days: 5 semver-major-days: 30 semver-minor-days: 7 semver-patch-days: 3 include: ["*"] exclude: ["critical-lib"]参数说明:
default-days:默认冷却天数(1–90 天);semver-major-days/semver-minor-days/semver-patch-days:分别针对大/中/小版本的冷却天数;include:应用冷却的依赖(最多 150 个,支持*);exclude:豁免冷却的依赖(最多 150 个,优先级更高)。
冷却期只作用于版本更新,不作用于安全更新——这是设计上刻意为之,安全修复不应被延迟。
八、安全更新与自动分诊
在仓库设置中启用
路径:仓库Settings → Advanced Security,分别开启 Dependabot alerts、security updates 以及 grouped security updates。
在 YAML 中分组安全更新
groups: security-patches: applies-to: security-updates patterns: ["*"] update-types: ["patch", "minor"]禁用版本更新(仅保留安全能力)
open-pull-requests-limit: 0 # 禁用版本更新 PR配合groups中的applies-to: security-updates,可以实现"只修漏洞、不追新版本"的保守策略。安全更新有独立的内部上限(10 条),与版本更新的open-pull-requests-limit互不影响。
自动分诊规则(Auto-Triage Rules)
GitHub 提供了自动分诊预设:自动忽略开发依赖中的低影响告警。也可以按严重级别、包名、CWE 等条件配置自定义规则,入口在Settings → Advanced Security。
九、Dependabot PR 评论命令
在 Dependabot 创建的 PR 上评论@dependabot <command>即可与之交互,Dependabot 会用 👍 表情确认收到命令。完整命令列表见 pr-commands.md。
弃用提示(2026 年 1 月起):
@dependabot merge、@dependabot squash and merge、@dependabot cancel merge、@dependabot close、@dependabot reopen已被移除。请改用 GitHub 原生 UI、CLI(gh pr merge)或 auto-merge 功能。
单个 PR 的命令
| 命令 | 效果 |
|---|---|
@dependabot rebase | 基于目标分支 rebase 该 PR |
@dependabot recreate | 从头重建 PR,覆盖任何手动编辑 |
@dependabot ignore this dependency | 关闭 PR 并永久停止该依赖的更新 |
@dependabot ignore this major version | 忽略该大版本 |
@dependabot ignore this minor version | 忽略该中版本 |
@dependabot ignore this patch version | 忽略该小版本 |
@dependabot show DEPENDENCY_NAME ignore conditions | 展示该依赖当前所有 ignore 条件 |
分组更新(grouped updates)的命令
| 命令 | 效果 |
|---|---|
@dependabot ignore DEPENDENCY_NAME | 关闭 PR 并停止组内该依赖的更新 |
@dependabot ignore DEPENDENCY_NAME major/minor/patch version | 停止该依赖对应版本的更新 |
@dependabot unignore * | 关闭当前 PR,清除组内所有依赖的全部 ignore 条件,重新开 PR |
@dependabot unignore DEPENDENCY_NAME | 关闭当前 PR,清除该依赖的全部 ignore 条件,重新开 PR |
@dependabot unignore DEPENDENCY_NAME IGNORE_CONDITION | 只清除指定的一条 ignore 条件 |
典型使用场景
CI 通过后自动合并(替代已弃用的 merge 命令):
gh pr merge <PR_NUMBER> --auto --squash忽略一个大版本升级(例如 Express 5 破坏性变更暂未规划迁移):
@dependabot ignore this major version查看某依赖的当前 ignore 条件:
@dependabot show express ignore conditions分组 PR 中取消忽略某个依赖:
@dependabot unignore lodash只清除指定版本区间的 ignore:
@dependabot unignore express [< 1.9, > 1.8.0]使用技巧
- rebase 与 recreate 的选择:需要保留审查状态时用
rebase解决冲突;PR 偏离过大时用recreate重新开始; - 强制推送覆盖额外提交:如果你往 Dependabot 分支推过提交,并在提交信息中包含
[dependabot skip],Dependabot 即可在其上继续 rebase; - 持久化 ignore 的透明性:通过 PR 评论设置的 ignore 是集中存储的,对团队仓库而言,更推荐在
dependabot.yml的ignore中显式声明,便于审查与追溯; - unignore 行为:对分组 PR 执行
@dependabot unignore时,Dependabot 会关闭当前 PR 并用更新后的依赖集合重新开一个。
十、忽略、允许与排除规则
ignore:忽略指定依赖或版本
ignore: - dependency-name: "lodash" - dependency-name: "@types/node" update-types: ["version-update:semver-patch"] - dependency-name: "express" versions: ["5.x"]dependency-name支持*通配符;versions支持具体版本或范围(如["5.x"]、[">=2.0.0"]);update-types可选version-update:semver-major、version-update:semver-minor、version-update:semver-patch。
allow:仅允许特定类型
allow: - dependency-type: "production" - dependency-name: "express"dependency-name支持*通配符;dependency-type支持direct、indirect、all、production、development。
优先级规则:如果某个依赖同时命中allow与ignore,则结果按ignored(忽略)处理。
exclude-paths:排除扫描路径
exclude-paths: - "vendor/**" - "test/fixtures/**" - "*.lock"支持 Glob 模式:*(单段)、**(递归)、以及具体文件路径。
十一、高级选项
versioning-strategy:控制版本约束的编辑方式
| 值 | 行为 |
|---|---|
auto | 默认——应用类提升最小版本,库类放宽范围 |
increase | 总是提升最小版本 |
increase-if-necessary | 仅当当前范围不包含新版本时才改动 |
lockfile-only | 只更新 lockfile,不改 manifest |
widen | 放宽范围以同时包含新旧版本 |
该选项支持的生态包括:bundler、cargo、composer、mix、npm、pip、pub、uv。
rebase-strategy
rebase-strategy: "disabled" # 关闭自动 rebase默认行为:Dependabot 会在冲突时自动 rebase PR,并在 PR 打开 30 天后停止 rebase。在提交信息中包含[dependabot skip]可允许其强制推送覆盖额外提交。
open-pull-requests-limit
open-pull-requests-limit: 10 # 版本更新默认 5,安全更新默认 10设为0可完全禁用版本更新。
vendor(供应商依赖)
支持生态:bundler、gomod。Go modules 会自动检测 vendored 依赖:
vendor: true # 维护 vendored 依赖insecure-external-code-execution
支持生态:bundler、mix、pip:
insecure-external-code-execution: "allow"允许 Dependabot 在更新过程中执行 manifest 中的代码——部分生态在版本解析时需要运行代码,必须开启此项。
十二、私有源(Private Registries)
通过顶层registries定义私有源,再在updates条目中引用:
registries: npm-private: type: npm-registry url: https://npm.example.com token: ${{secrets.NPM_TOKEN}} maven-central: type: maven-repository url: https://repo.maven.apache.org/maven2 username: "" password: "" docker-ghcr: type: docker-registry url: https://ghcr.io username: ${{secrets.GHCR_USER}} password: ${{secrets.GHCR_TOKEN}} python-private: type: python-index url: https://pypi.example.com/simple token: ${{secrets.PYPI_TOKEN}} updates: - package-ecosystem: "npm" directory: "/" registries: - npm-private schedule: interval: "weekly"- 凭据一律通过仓库 Secrets 引用(
${{secrets.XXX}}),不要硬编码; - 使用
registries: "*"可允许访问所有已定义源(详见 dependabot-yml-reference.md)。
十三、实战配置示例合集
以下示例摘选自 example-configs.md,可直接按需裁剪使用。
1. Monorepo:Glob 覆盖 + 开发/生产分组
version: 2 updates: - package-ecosystem: "npm" directories: - "/" - "/apps/*" - "/packages/*" - "/services/*" schedule: interval: "weekly" day: "monday" groups: dev-dependencies: dependency-type: "development" update-types: ["minor", "patch"] production-dependencies: dependency-type: "production" update-types: ["minor", "patch"] labels: - "dependencies" - "npm" commit-message: prefix: "deps" include: "scope"2. 开发/生产分组 + 独立 linting 组
version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "weekly" groups: production-deps: dependency-type: "production" dev-deps: dependency-type: "development" exclude-patterns: - "eslint*" linting: patterns: - "eslint*" - "prettier*" - "@typescript-eslint*"3. 仅安全更新(禁用版本更新)
version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "daily" open-pull-requests-limit: 0 # 禁用版本更新 PR groups: security-all: applies-to: security-updates patterns: ["*"] update-types: ["patch", "minor"] - package-ecosystem: "pip" directory: "/" schedule: interval: "daily" open-pull-requests-limit: 04. 冷却期配置
version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "weekly" cooldown: default-days: 5 semver-major-days: 30 semver-minor-days: 14 semver-patch-days: 3 include: ["*"] exclude: - "security-critical-lib" - "@company/internal-*"5. Cron 调度(npm + GitHub Actions)
version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "cron" cronjob: "0 9 * * 1" # 每周一 9:00 timezone: "America/New_York" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "cron" cronjob: "0 6 1 * *" # 每月 1 日 6:006. ignore 模式与版本策略
version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "daily" versioning-strategy: "increase" ignore: # 永不自动升级到 Express 5.x(破坏性变更) - dependency-name: "express" versions: ["5.x"] # 跳过类型定义的 patch 更新 - dependency-name: "@types/*" update-types: ["version-update:semver-patch"] # 忽略 vendored 包的全部更新 - dependency-name: "legacy-internal-lib" allow: - dependency-type: "all" exclude-paths: - "vendor/**" - "test/fixtures/**"7. 指向非默认分支
version: 2 updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "weekly" target-branch: "develop" labels: - "dependencies" - "staging"再次强调:无论
target-branch如何设置,安全更新始终指向默认分支。
8. 全功能综合配置(推荐参考模板)
example-configs.md 的第 10 个示例是集大成的综合配置:覆盖 npm Monorepo 工作区(含私有源、分组、ignore、cooldown、标签、提交信息、指派人、PR 上限)、GitHub Actions、Docker、pip 与 Terraform 五个生态。该示例同时展示了"不同生态采用不同调度频率与标签体系"的工程化做法(例如 pip 用monthly低频 +versioning-strategy: "increase-if-necessary",Terraform 用infra前缀),建议直接以它为起点按需删减。
十四、AI 编码代理中的预提交依赖扫描
本技能还覆盖了将 Dependabot 能力接入 AI 编码代理的用法(详见 SKILL.md 的 Pre-Commit Dependency Scanning 章节):
- 在提交前,可通过GitHub MCP Server 的
dependabot工具集将新增依赖与 GitHub Advisory Database 比对,返回受影响包、严重级别与推荐修复版本等结构化结果; - 需要更彻底的后置检查时,可在本地运行Dependabot CLI,对改动前后的依赖图做 diff;
- 安装Advanced Security 插件可获得专门的依赖扫描工具与
/dependency-scanning技能。
GitHub Copilot CLI(shell):
# 为 GitHub MCP Server 启用 dependabot 工具集 copilot --add-github-mcp-toolset dependabotGitHub Copilot CLI(进入copilot交互后):
> /plugin install advanced-security@copilot-pluginsVisual Studio Code:
- 在 GitHub MCP Server 的 headers 中加入
"X-MCP-Toolsets": "dependabot",或在 Copilot Chat 的 toolset 选择器中选择Dependabot; - 安装
advanced-security插件后,在 Copilot Chat 中使用/dependency-scanning。
示例提示词:
Scan the dependencies I added on this branch for known vulnerabilities and tell me which versions to upgrade to before I commit.
十五、常见问题 FAQ
可以在一个仓库里放多个dependabot.yml吗?不可以。GitHub 只支持默认分支上的.github/dependabot.yml一个文件。不同生态和目录通过该文件内的多个updates条目覆盖。
Dependabot 支持 pnpm 吗?支持。使用package-ecosystem: "npm",Dependabot 会自动检测pnpm-lock.yaml。
Monorepo 中如何减少 PR 噪音?用groups批量合并更新、用带 Glob 的directories扩大覆盖、用group-by: dependency-name做跨目录分组;对低优先级生态可考虑monthly或quarterly调度。
工作区之外的依赖怎么处理?为它单独创建一个生态条目,用directory指向对应位置即可。
十六、仓库中的参考资源
本技能在 awesome-copilot 仓库中附带三份深度参考文档,建议配套阅读:
- SKILL.md——本指南的核心骨架,含完整配置工作流、Monorepo 策略、分组、调度、安全更新与 AI 代理扫描章节;
- dependabot-yml-reference.md——
dependabot.yml全部选项的完整参考(文件结构、必填键、分组、过滤、PR 定制、调度限流、高级选项、私有源); - example-configs.md——12 个真实场景配置示例,从单生态最小配置到多生态全功能配置;
- pr-commands.md——全部 PR 评论命令与使用示例。
安装该技能到本地(需要 GitHub CLI v2.90.0+,详见 docs/README.skills.md):
gh skills install github/awesome-copilot dependabot也可以将本仓库克隆到本地后直接查看技能目录:git clone https://gitcode.com/GitHub_Trending/aw/awesome-copilot,技能文件位于 skills/dependabot 下。仓库还提供了 github-actions-expert 代理 与 github-actions-ci-cd-best-practices 指令,可作为 CI 与供应链安全实践的补充。
【免费下载链接】awesome-copilotCommunity-contributed instructions, agents, skills, and configurations to help you make the most of GitHub Copilot.项目地址: https://gitcode.com/GitHub_Trending/aw/awesome-copilot
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考