DEV Community

Cover image for Locally test and validate your Renovate configuration files
Anthony Simmon
Anthony Simmon

Posted on • Originally published at anthonysimmon.com

Locally test and validate your Renovate configuration files

Renovate is an automated dependency management tool that can be used to keep your dependencies up-to-date. It can be configured to automatically create pull requests to update your dependencies, and it supports a wide range of package managers and platforms.

To use Renovate, you need to create a renovate.json configuration file. The creation process can take some time, as there are many configuration options available. Depending on the complexity of your project, the package managers you use, your platform (GitHub, GitLab, Azure DevOps, etc.), and your specific needs, you may need to go through several iterations to get a configuration that works well for you.

In this article, we will see how to test and validate your Renovate configuration files locally, to avoid having to push changes to your source control and wait for your pipeline to see if Renovate works as intended.

Prerequisites

We will be using the self-hosted version of Renovate distributed via npm, but you can adapt the scripts in this article to use the Docker version, or others. Make sure you have Node.js installed on your machine.

You also need a project with a Renovate configuration file, of course. For demonstration purposes, we will use a .NET project that contains a single dependency on an older version of Microsoft.Extensions.Hosting:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <!-- The most recent version of Microsoft.Extensions.Hosting is 8.0.0 as of this writing. -->
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
  </ItemGroup>
</Project>
Enter fullscreen mode Exit fullscreen mode

Next, let's create a renovate.json file at the root:

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": [
    "config:best-practices"
  ],
  "enabledManagers": [
    "nuget"
  ]
}
Enter fullscreen mode Exit fullscreen mode

This simplistic Renovate configuration will serve as our example. Use your own Renovate configuration file if you already have one.

Launching Renovate locally

It is possible to run Renovate locally to test your configuration. To do this, we will use the following command for Linux and macOS:

LOG_LEVEL=debug npx renovate --platform=local --repository-cache=reset
Enter fullscreen mode Exit fullscreen mode

For Windows using PowerShell Core, use this command:

pwsh -Command { $env:LOG_LEVEL="debug"; npx renovate --platform=local --repository-cache=reset }
Enter fullscreen mode Exit fullscreen mode

The three important points to remember here are:

  • LOG_LEVEL=debug is used to obtain additional debugging information. Thanks to this environment variable, Renovate will display the updates available for the packages.
  • --platform=local is used to perform a dry run on the local computer.
  • --repository-cache=reset is used to force Renovate to ignore the cache. This can avoid incorrect results between your different modifications of your configuration.

Reading the Renovate output logs

In the .NET project of our example, we intentionally used an older version of Microsoft.Extensions.Hosting (7.0.0) so that Renovate could find an update. Here is an excerpt from the Renovate logs:

DEBUG: packageFiles with updates (repository=local)
       "config": {
         "nuget": [
           {
             "deps": [
               {
                 "datasource": "nuget",
                 "depType": "nuget",
                 "depName": "Microsoft.Extensions.Hosting",
                 "currentValue": "7.0.0",
                 "updates": [
                   {
                     "bucket": "non-major",
                     "newVersion": "7.0.1",
                     "newValue": "7.0.1",
                     "releaseTimestamp": "2023-02-14T13:21:52.713Z",
                     "newMajor": 7,
                     "newMinor": 0,
                     "updateType": "patch",
                     "branchName": "renovate/dotnet-monorepo"
                   },
                   {
                     "bucket": "major",
                     "newVersion": "8.0.0",
                     "newValue": "8.0.0",
                     "releaseTimestamp": "2023-11-14T13:23:17.653Z",
                     "newMajor": 8,
                     "newMinor": 0,
                     "updateType": "major",
                     "branchName": "renovate/major-dotnet-monorepo"
                   }
                 ],
                 "packageName": "Microsoft.Extensions.Hosting",
                 "versioning": "nuget",
                 "warnings": [],
                 "sourceUrl": "https://github.com/dotnet/runtime",
                 "registryUrl": "https://api.nuget.org/v3/index.json",
                 "homepage": "https://dot.net/",
                 "currentVersion": "7.0.0",
                 "isSingleVersion": true,
                 "fixedVersion": "7.0.0"
               }
             ],
             "packageFile": "RenovateDemo.csproj"
           }
         ]
       }
Enter fullscreen mode Exit fullscreen mode

Notice how config.nuget[0].deps[0].updates contains two updates for Microsoft.Extensions.Hosting: one for a patch update (7.0.1) and one for a major update (8.0.0). This is the type of information you can expect to see when you run Renovate locally. The output might be more detailed or contain more information depending on your configuration and the packages you use.

Top comments (0)