{"meta":{"title":"配置 Dependabot 版本更新","intro":"您可以配置仓库，以便 Dependabot 自动更新您使用的包。","product":"安全性和代码质量","breadcrumbs":[{"href":"/zh/code-security","title":"安全性和代码质量"},{"href":"/zh/code-security/how-tos","title":"How-tos"},{"href":"/zh/code-security/how-tos/secure-your-supply-chain","title":"保护供应链"},{"href":"/zh/code-security/how-tos/secure-your-supply-chain/secure-your-dependencies","title":"保护依赖项"},{"href":"/zh/code-security/how-tos/secure-your-supply-chain/secure-your-dependencies/configuring-dependabot-version-updates","title":"配置版本更新"}],"documentType":"article"},"body":"# 配置 Dependabot 版本更新\n\n您可以配置仓库，以便 Dependabot 自动更新您使用的包。\n\n<!--Marketing-LINK: From /features/security/software-supply-chain page \"About version updates for dependencies\".-->\n\n## 启用 Dependabot version updates\n\n通过将 `dependabot.yml` 配置文件提交到存储库，可启用 Dependabot version updates。\n如果在设置页中启用该功能，GitHub 会创建一个你可以编辑的基本文件，否则你可以使用任何文件编辑器创建该文件。\n\n1. 在 GitHub 上，导航到存储库的主页面。\n\n2. 在仓库名称下，单击 <svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-gear\" aria-label=\"gear\" role=\"img\"><path d=\"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z\"></path></svg>“Settings”\\*\\*\\*\\*。 如果看不到“设置”选项卡，请选择“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-kebab-horizontal\" aria-label=\"kebab horizontal icon\" role=\"img\"><path d=\"M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z\"></path></svg>”下拉菜单，然后单击“设置”。\n\n   ![存储库标头的屏幕截图，其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。](/assets/images/help/repository/repo-actions-settings.png)\n\n3. 在边栏的“Security”部分中，单击“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-codescan\" aria-label=\"codescan\" role=\"img\"><path d=\"M8.47 4.97a.75.75 0 0 0 0 1.06L9.94 7.5 8.47 8.97a.75.75 0 1 0 1.06 1.06l2-2a.75.75 0 0 0 0-1.06l-2-2a.75.75 0 0 0-1.06 0ZM6.53 6.03a.75.75 0 0 0-1.06-1.06l-2 2a.75.75 0 0 0 0 1.06l2 2a.75.75 0 1 0 1.06-1.06L5.06 7.5l1.47-1.47Z\"></path><path d=\"M12.246 13.307a7.501 7.501 0 1 1 1.06-1.06l2.474 2.473a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM1.5 7.5a6.002 6.002 0 0 0 3.608 5.504 6.002 6.002 0 0 0 6.486-1.117.748.748 0 0 1 .292-.293A6 6 0 1 0 1.5 7.5Z\"></path></svg> Advanced Security”\\*\\*\\*\\*。\n\n4. 在“Dependabot”下，在“Dependabot version updates”右侧，单击“Enable”\\*\\*\\*\\* 以在仓库的 `dependabot.yml` 目录中打开基本的 `.github` 配置文件。 For information about the options you can use to customize how Dependabot maintains your repositories, see [Dependabot 选项参考](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference).\n\n   ```yaml copy\n   # To get started with Dependabot version updates, you'll need to specify which\n   # package ecosystems to update and where the package manifests are located.\n\n   version: 2\n   updates:\n   - package-ecosystem: \"\" # See documentation for possible values\n     directory: \"/\" # Location of package manifests\n     schedule:\n       interval: \"weekly\"\n   ```\n\n5. 添加 `version`。 此密钥是必填项。 该文件必须以 `version: 2` 开头。\n\n6. （可选）如果专用注册表中包含依赖项，请添加包含身份验证详细信息的 `registries` 部分。 有关详细信息，请参阅“[为 Dependabot 配置对专用注册表的访问权限](/zh/code-security/dependabot/working-with-dependabot/configuring-access-to-private-registries-for-dependabot)”。\n\n7. 添加 `updates` 部分，并输入希望 Dependabot 监视的每个包管理器的条目。 此密钥是必填项。 您使用它来配置 Dependabot 如何更新版本或项目的依赖项。 每个条目都为特定的包管理器配置更新设置。 有关详细信息，请参阅 [关于 dependabot.yml 文件](/zh/code-security/concepts/supply-chain-security/about-the-dependabot-yml-file) 和 [Dependabot 选项参考](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference)。\n\n8. 对于每个包管理器，可使用：\n\n   * ```\n         `package-ecosystem` 指定包管理器。 有关支持的包管理器的详细信息，请参阅 [`package-ecosystem`](/code-security/dependabot/working-with-dependabot/dependabot-options-reference#package-ecosystem-)。\n     ```\n   * ```\n         `directories` 或 `directory`，以指定多个清单或其他定义文件的位置。 有关详细信息，请参阅[定义清单文件的多个位置](/code-security/dependabot/dependabot-version-updates/controlling-dependencies-updated#defining-multiple-locations-for-manifest-files)。\n     ```\n   * ```\n         `schedule.interval` 指定检查新版本的频率。\n     ```\n\n9. 将 dependabot.yml 配置文件签入存储库的 `.github` 目录中。\n\n### 示例 `dependabot.yml` 文件\n\n下面的示例 `dependabot.yml` 文件配置以下三个包管理器的版本更新：npm、Docker 和 GitHub Actions。 当此文件被检入时，Dependabot 会检查默认分支上的清单文件中是否有过时的依赖项。 如果发现过时的依赖项，将针对默认分支提出拉取请求，以更新依赖项。\n\n```yaml copy\n# Basic `dependabot.yml` file with\n# minimum configuration for three package managers\n\nversion: 2\nupdates:\n  # Enable version updates for npm\n  - package-ecosystem: \"npm\"\n    # Look for `package.json` and `lock` files in the `root` directory\n    directory: \"/\"\n    # Check the npm registry for updates every day (weekdays)\n    schedule:\n      interval: \"daily\"\n\n  # Enable version updates for Docker\n  - package-ecosystem: \"docker\"\n    # Look for a `Dockerfile` in the `root` directory\n    directory: \"/\"\n    # Check for updates once a week\n    schedule:\n      interval: \"weekly\"\n\n  # Enable version updates for GitHub Actions\n  - package-ecosystem: \"github-actions\"\n    # Workflow files stored in the default location of `.github/workflows`\n    # You don't need to specify `/.github/workflows` for `directory`. You can use `directory: \"/\"`.\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n```\n\n在上述示例中，如果 Docker 依赖项已过时很久，你可能需要先执行 `daily` 计划，直到这些依赖项达到最新状态，然后降回每周计划。\n\n## 在复刻上启用版本更新\n\n如果您想在复刻上启用版本更新，还需要执行一个额外的步骤。 存在 `dependabot.yml` 配置文件时，不会自动启用版本更新。 这样可确保分支所有者在从原始存储库拉取更改（包括 `dependabot.yml` 配置文件）时，不会无意中启用版本更新。\n\n在复刻上，也需要显式启用 Dependabot。\n\n1. 在 GitHub 上，导航到存储库的主页面。\n2. 在仓库名称下，单击 <svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-gear\" aria-label=\"gear\" role=\"img\"><path d=\"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11-.059-.19l-.815-.806c-.411-.406-.562-.957-.53-1.456a4.709 4.709 0 0 0 0-.582c-.032-.499.119-1.05.53-1.456l.815-.806c.081-.08.073-.159.059-.19a6.464 6.464 0 0 0-.573-.989c-.02-.03-.085-.076-.195-.046l-1.102.303c-.56.153-1.113.008-1.53-.27a4.44 4.44 0 0 0-.501-.29c-.447-.222-.85-.629-.997-1.189l-.289-1.105c-.029-.11-.101-.143-.137-.146a6.6 6.6 0 0 0-1.142 0ZM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0ZM9.5 8a1.5 1.5 0 1 0-3.001.001A1.5 1.5 0 0 0 9.5 8Z\"></path></svg>“Settings”\\*\\*\\*\\*。 如果看不到“设置”选项卡，请选择“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-kebab-horizontal\" aria-label=\"kebab horizontal icon\" role=\"img\"><path d=\"M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z\"></path></svg>”下拉菜单，然后单击“设置”。\n\n   ![存储库标头的屏幕截图，其中显示了选项卡。 “设置”选项卡以深橙色边框突出显示。](/assets/images/help/repository/repo-actions-settings.png)\n3. 在边栏的“Security”部分中，单击“<svg version=\"1.1\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" class=\"octicon octicon-codescan\" aria-label=\"codescan\" role=\"img\"><path d=\"M8.47 4.97a.75.75 0 0 0 0 1.06L9.94 7.5 8.47 8.97a.75.75 0 1 0 1.06 1.06l2-2a.75.75 0 0 0 0-1.06l-2-2a.75.75 0 0 0-1.06 0ZM6.53 6.03a.75.75 0 0 0-1.06-1.06l-2 2a.75.75 0 0 0 0 1.06l2 2a.75.75 0 1 0 1.06-1.06L5.06 7.5l1.47-1.47Z\"></path><path d=\"M12.246 13.307a7.501 7.501 0 1 1 1.06-1.06l2.474 2.473a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215ZM1.5 7.5a6.002 6.002 0 0 0 3.608 5.504 6.002 6.002 0 0 0 6.486-1.117.748.748 0 0 1 .292-.293A6 6 0 1 0 1.5 7.5Z\"></path></svg> Advanced Security”\\*\\*\\*\\*。\n4. 在“Dependabot”下，在“Dependabot version updates”右侧，单击“Enable”以允许 Dependabot 启动版本更新。\\*\\*\\*\\*\n\n## 获取间接依赖项的更新\n\n默认情况下，只有清单中显式定义的直接依赖项才会由 Dependabot version updates 保持最新。 可以选择接收锁文件中定义的间接依赖项更新。 有关详细信息，请参阅“[控制 Dependabot 更新的依赖项](/zh/code-security/dependabot/dependabot-version-updates/controlling-dependencies-updated#allowing-specific-dependencies-to-be-updated)”。\n\n## 启用对专用依赖项的访问\n\n在运行安全性或版本更新时，有些生态系统必须能够解决来自其来源的所有依赖项，以验证版本更新是否成功。 如果清单或锁定文件包含任何私有依赖项，Dependabot 必须能够访问这些依赖项所在的位置。 组织所有者可以授予 Dependabot 访问包含同一个组织内项目依赖项的私有仓库. 有关详细信息，请参阅“[管理组织的安全和分析设置](/zh/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/managing-security-and-analysis-settings-for-your-organization#allowing-dependabot-to-access-private-dependencies)”。 你可以在存储库的 `dependabot.yml` 配置文件中配置对专用注册表的访问。 有关详细信息，请参阅“[为 Dependabot 配置对专用注册表的访问权限](/zh/code-security/dependabot/working-with-dependabot/configuring-access-to-private-registries-for-dependabot)”。\n\n此外，Dependabot 不支持所有包管理器的专用 GitHub 依赖项。 有关详细信息，请参阅 [Dependabot 支持的生态系统和存储库](/zh/code-security/dependabot/ecosystems-supported-by-dependabot/supported-ecosystems-and-repositories) 和 [GitHub语言支持](/zh/get-started/learning-about-github/github-language-support)。\n\n## 检查版本更新的状态\n\n启用版本更新后，将填充存储库依赖项关系图中的 **Dependabot** 选项卡。 此选项卡显示配置了哪些要监视的包管理器 Dependabot 以及 Dependabot 上次检查新版本的时间。\n\n![“依赖项关系图”页面的屏幕截图。 标题为“Dependabot”的选项卡以橙色轮廓突出显示。](/assets/images/help/dependabot/dependabot-tab-view.png)\n\n如需相关信息，请参阅 [列出为版本更新配置的依赖项](/zh/code-security/dependabot/troubleshooting-dependabot/listing-dependencies-configured-for-version-updates)。\n\n## 禁用 Dependabot version updates\n\n可通过从存储库中删除 `dependabot.yml` 文件来完全禁用版本更新。 更多情况下，您会希望临时为一个或多个依赖项或包管理器禁用更新。\n\n* 包管理器：若要禁用，可设置 `open-pull-requests-limit: 0` 或注释掉配置文件中的相关 `package-ecosystem` 内容。\n* 特定依赖项：若要禁用，可为你想从更新中排除的包或应用程序添加 `ignore` 属性。\n\n禁用依赖项时，可以使用通配符匹配一组相关库。 您也可以指定要排除的版本。 如果您需要阻止库更新，利用待处理的工作支持对 API 进行重大变更，但又希望您使用的版本得到所有安全修复，此方法将特别有用。\n\n### 为某些依赖项禁用版本更新的示例\n\n下面的示例 `dependabot.yml` 文件中包含几个示例，它们显示了禁用某些依赖项的更新，同时允许其他更新继续进行的不同方式。\n\n```yaml\n# `dependabot.yml` file with updates\n# disabled for Docker and limited for npm\n\nversion: 2\nupdates:\n  # Configuration for Dockerfile\n  - package-ecosystem: \"docker\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n      # Disable all pull requests for Docker dependencies\n    open-pull-requests-limit: 0\n\n  # Configuration for npm\n  - package-ecosystem: \"npm\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n    ignore:\n      # Ignore updates to packages that start with 'aws'\n      # Wildcards match zero or more arbitrary characters\n      - dependency-name: \"aws*\"\n      # Ignore some updates to the 'express' package\n      - dependency-name: \"express\"\n        # Ignore only new versions for 4.x and 5.x\n        versions: [\"4.x\", \"5.x\"]\n      # For all packages, ignore all patch updates\n      - dependency-name: \"*\"\n        update-types: [\"version-update:semver-patch\"]\n```\n\n有关检查现有忽略首选项的详细信息，请参阅 [Dependabot 选项参考](/zh/code-security/dependabot/working-with-dependabot/dependabot-options-reference#ignore--)。"}