Sharing the Renovate configuration across multiple projects

 
 
  • Gérald Barré

Renovate is a tool that helps you to keep your dependencies up-to-date. You can configure Renovate using a configuration file at the root of the repository. In this post, I describe how to share the Renovate configuration across multiple projects.

Developers don't like to maintain the same configuration in multiple repositories. It's error-prone and time-consuming. By sharing the configuration, you can centralize the logic and make it easier to maintain.

Also, it can be useful in a corporate environment to enforce some rules across all repositories. For instance, you may want to ensure that all Docker images are pulled from a specific internal registry. Renovate can help you enforce this rule by automatically updating the Docker image name in the Dockerfile. It can also help you replace deprecated packages with new ones. For instance, you can create a rule that says replace my_old_package with my_new_package. By sharing this logic across all repositories, you ensure that all repositories follow the same rules automatically.

Renovate has the concept of presets. A preset is a set of rules that Renovate uses to update dependencies. You can create a preset and share it across multiple projects. There are multiple options to host the preset, such as GitHub, GitLab, Bitbucket, or a custom URL. In this post, I'll show you how to host the preset on GitHub.

#How to share the configuration?

  1. Create a GitHub repository to host the preset. The common name for the repository is renovate-config. Note that Renovate auto-detect this repository when onboarding a project in the same GitHub organization.

  2. 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"
        }
      ]
    }
  3. Reference the configuration in your project. Create a file named renovate.json at the root of the repository. To reference the shared configuration hosted on GitHub, you can 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. {file name} is optional. If you don't specify a file name, Renovate uses default.json. Here are 2 examples of the renovate.json file. The first one expects the shared preset to be named default.json and the second one expects the shared preset to be named custom_preset.json5:

    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"]
    }

If you have a repository-specific configuration, you can add it to the renovate.json file. The configuration in the renovate.json file takes precedence over the shared configuration.

#Additional resources

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub