可以通过在Dependabot文件中添加选项来定制dependabot.yml配置以满足您的需求。 例如,可以确保 Dependabot 使用正确的包清单文件,并仅更新要维护的依赖项。
本文整理了可能有用的自定义选项。
为清单文件定义多个位置
如果要为存储在多个位置的清单文件启用 Dependabot version updates,可以使用 directories 代替 directory。 例如,此配置为存储在不同目录中的清单文件设置两个不同的更新计划。
# 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"
# 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"# 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"# 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配置为在打开版本更新和安全更新的拉取请求时忽略这些依赖项。 可使用以下方法之一来执行此操作。
- 配置
ignore选项以用于dependabot.yml文件中的依赖项。 - 对 Dependabot 拉取请求使用
@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" ]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,)" ]ignore: - dependency-name: "sphinx" versions: [ "[1.1,)" ] -
忽略补丁更新
YAML ignore: - dependency-name: "@types/node" # Ignore patch updates for Node update-types: ["version-update:semver-patch"]ignore: - dependency-name: "@types/node" # Ignore patch updates for Node update-types: ["version-update:semver-patch"] -
若要忽略特定版本或一系列版本,请参阅“忽略特定版本或一系列版本”。
如果要取消忽略依赖项或忽略条件,可以从 dependabot.yml 文件中删除忽略条件或重新打开拉取请求。
对于分组更新拉取请求,还可以使用 @dependabot unignore 注释命令。 使用 @dependabot unignore 注释命令,您可以对 Dependabot 拉取请求进行注释以执行以下操作:
- 取消忽略特定条件
- 取消忽略特定依赖项
- 在Dependabot拉取请求中,取消对所有依赖项的忽略条件。
有关详细信息,请参阅“管理依赖项更新的所有拉取请求”。
允许更新特定依赖项
可以使用allow告诉Dependabot您要维护的依赖项。
allow 通常与 ignore 结合使用。
默认情况下, Dependabot 仅为清单(依赖项)direct 中显式定义的依赖项创建版本更新拉取请求。 此配置用于 allow 告知 Dependabot 我们希望它维护 all 依赖项的类型。 也就是说,同时包括 direct 依赖项及其依赖项(也称为间接依赖项、子依赖项或暂时性依赖项)。 此外,配置会告知 Dependabot 忽略名称与模式 org.xwiki.* 匹配的所有依赖项,因为我们有一个不同的过程来维护它们。
提示
Dependabot 检查所有 允许的 依赖项,然后筛选掉所有 忽略的 依赖项。 如果依赖项与 allow 和 ignore 语句匹配,则忽略它。
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
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 结合使用来忽略特定版本或一系列版本。
-
忽略特定版本
YAML ignore: - dependency-name: "django*" # Ignore version 11 versions: [ "11" ]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"]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 和 ignore.
在此示例中, Dependabot 将忽略 Node 的修补程序版本。
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"]
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 将增加与应用和库的新版本匹配的最低版本要求。
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
# Increase the minimum version for all npm dependencies
versioning-strategy: increase
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
# Increase the minimum version for all npm dependencies
versioning-strategy: increase
在此示例中, Dependabot仅 当原始约束不允许新版本时,才会增加最低版本要求。
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
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设置为true用于 Bundler,这意味着Dependabot也会维护存储库中_vendor/cache_目录中 Bundler 的依赖关系。
version: 2
updates:
- package-ecosystem: bundler
directory: "/"
# Vendoring Bundler
vendor: true
schedule:
interval: weekly
day: saturday
open-pull-requests-limit: 10
version: 2
updates:
- package-ecosystem: bundler
directory: "/"
# Vendoring Bundler
vendor: true
schedule:
interval: weekly
day: saturday
open-pull-requests-limit: 10