Integrating Dependabot with Mergify
How to automate your dependencies update using Mergify.
Dependabot helps you keep your dependencies up-to-date by automatically opening pull requests for outdated dependencies. When combined with Mergify, you can automate more of the process.
Approving Dependabot pull requests
Section titled Approving Dependabot pull requestsIf your branch protection requires approvals, approve Dependabot pull requests
from a GitHub Actions workflow: a job on pull_request granted
pull-requests: write in its permissions:, gated on
github.event.pull_request.user.login == 'dependabot[bot]', that runs
gh pr review --approve. The repository’s Actions settings must allow GitHub
Actions to create and approve pull requests.
Filtering Dependabot PRs
Section titled Filtering Dependabot PRsMergify exposes condition attributes describing each Dependabot update:
dependabot-dependency-name, dependabot-dependency-type, and
dependabot-update-type. You can use these in your merge
protection conditions to filter which
Dependabot PRs are allowed to merge. For instance, you might want to block
major version bumps:
merge_protections: - name: block-major-dependabot-updates if: - author = dependabot[bot] success_conditions: - dependabot-update-type != version-update:semver-majorBatching dependency updates
Section titled Batching dependency updatesFor projects where there are frequent updates to a large number of small libraries, you can batch these updates together. Using Mergify’s merge queue feature, you can automatically batch and test these updates together, reducing CI load and ensuring compatibility.
For example, you could set up a merge queue to batch those PRs 10 by 10:
queue_rules: - name: dep-update batch_size: 10 # Wait for up to 30 minutes for the batch to fill up batch_max_wait_time: 30 min queue_conditions: - author = dependabot[bot]Disable Dependabot’s automatic rebase
Section titled Disable Dependabot’s automatic rebaseBy default, Dependabot will try to rebase its pull requests every time there’s a new commit to the main branch. In high-velocity projects with a lot of updates, this can lead to unnecessary CI runs. It’s recommended to disable Dependabot’s automatic rebase feature and instead rely on Mergify to queue and merge these updates efficiently.
To disable automatic rebasing in Dependabot, use the
rebase-strategy
settings and turn off automatic rebase.
version: 2updates: - package-ecosystem: "npm" directory: "/" schedule: interval: "weekly" # Disable rebasing for npm pull requests rebase-strategy: "disabled"Reaching Mergify from Dependabot pull requests
Section titled Reaching Mergify from Dependabot pull requestsWorkflows run for Dependabot pull requests get an ID token like the repository’s other runs. A job that reaches Mergify with OIDC uploads test results to CI Insights and sends scopes from them with nothing to add.
Those runs read your Dependabot secrets only, never the repository’s GitHub Actions secrets. A job that uses an application key needs it there too, or it fails to authenticate on those pull requests:
-
Go to your repository Settings → Secrets and variables → Dependabot.
-
Click New repository secret.
-
Set the name to
MERGIFY_TOKENand paste the same application key you use in your GitHub Actions secrets.
Was this page helpful?
Thanks for your feedback!