Renovate is a tool that helps keep your dependencies up-to-date. You configure it using a configuration file at the root of each repository. This post covers how to share that configuration across multiple projects.
Maintaining the same configuration across multiple repositories is error-prone and time-consuming. Sharing the configuration centralizes the logic and makes it easier to maintain.
Sharing is also valuable in a corporate environment to enforce rules across all repositories. For example, you may want to ensure all Docker images are pulled from a specific internal registry. Renovate can enforce this by automatically updating Docker image names in the Dockerfile. You can also replace deprecated packages by creating rules such as: replace my_old_package with my_new_package. Sharing these rules ensures all repositories stay consistent automatically.
Renovate uses the concept of presets: a named set of rules for updating dependencies. You can create a preset and share it across multiple projects. Presets can be hosted on GitHub, GitLab, Bitbucket, or a custom URL. This post shows how to host a preset on GitHub.
#How to share the configuration?
Create a GitHub repository to host the preset. The common name for this repository is renovate-config. Renovate auto-detects this repository when onboarding a project in the same GitHub organization.
Create a file named default.json in the repository. The file contains the configuration for Renovate. Here's an example of the configuration:
JSON
{
"description": "Meziantou's default preset",
"extends": [
"config:recommended",
"schedule:nonOfficeHours",
":semanticCommits",
":enableVulnerabilityAlerts",
"docker:pinDigests",
"helpers:pinGitHubActionDigests",
":pinDevDependencies"
],
"packageRules": [
{
"matchPackageNames": ["alpine"],
"matchCategories": ["docker"],
"replacementName": "docker.io/alpine"
},
{
"matchPackageNames": ["Sample.DeprecatedPackage"],
"matchCategories": ["nuget"],
"replacementName": "Sample.NewPackage"
}
]
}
Reference the configuration in your project by creating a renovate.json file at the root of the repository. To reference a shared configuration hosted on GitHub, use the extends property with the value github>{GitHub Repository}:{file name}. {GitHub Repository} is the GitHub project path (e.g., meziantou/renovate-config), and {file name} is the name of the file in the repository. The {file name} part is optional; if omitted, Renovate defaults to default.json. The two examples below show renovate.json files referencing default.json and custom_preset.json5 respectively:
JSON
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>meziantou/renovate-config"]
}
JSON
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>meziantou/renovate-config:custom_preset.json5"]
}
For repository-specific settings, add them to the renovate.json file. Local configuration takes precedence over the shared preset.
#Additional resources
Do you have a question or a suggestion about this post? Contact me!