Logo

dev-resources.site

for different kinds of informations.

Tips and tricks for using Renovate

Published at
1/20/2023
Categories
dependencies
renovate
Author
msfjarvis
Categories
2 categories in total
dependencies
open
renovate
open
Author
9 person written this
msfjarvis
open
Tips and tricks for using Renovate

Mend Renovate is a free to use dependency update management service powered by the open-source renovate, and is a compelling alternative to GitHubā€™s blessed solution for this problem space: Dependabot. Renovate offers a significantly larger suite of supported language ecosystems compared to Dependabot as well as fine-grained control over where it finds dependencies, how it chooses updated versions, and a lot more. TL;DR: Renovate is a massive upgrade over Dependabot and you should evaluate it if any aspect of Dependabot has caused you grief, thereā€™s a good chance Renovate does it better.

Iā€™m collecting some tips here about ā€œfancyā€ things Iā€™ve done using Renovate that may be helpful to other folks. Youā€™ll be able to find more details about all of these in their very high quality docs at docs.renovatebot.com.

Disabling updates for individual packages

There are times where youā€™re sticking with an older version of a package (temporarily or otherwise) and you just donā€™t want to see PRs bumping it, wasting CI resources for an upgrade that will probably fail and is definitely not going to be merged. Renovate offers a convenient way to do this:

{
  "packageRules": [
    {
      "managers": ["gradle"],
      "packagePatterns": ["^com.squareup.okhttp3"],
      "enabled": false,
    },
  ],
}

Enter fullscreen mode Exit fullscreen mode

Grouping updates together

Renovate already includes preset configurations for monorepos that publish multiple packages with identical versions, but you can also easily add more of your own. As an example, hereā€™s how you can combine updates of the serde crate and its derive macro.

{
  "packageRules": [
    {
      "managers": [
        "cargo"
      ],
      "matchPackagePatterns": [
        "serde",
        "serde_derive"
      ],
      "groupName": "serde"
    }
  ]
}

Enter fullscreen mode Exit fullscreen mode

Set a semver range for upgrades

Sometimes there are cases where you may need to set an upper bound on a package dependency to avoid breaking changes or regressions. Renovate offers intuitive support for the same.

{
  "packageRules": [
    {
      "matchPackageNames": ["com.android.tools.build:gradle"],
      "allowedVersions": "<=7.4.0"
    }
  ]
}

Enter fullscreen mode Exit fullscreen mode

Supporting non-standard dependency declarations

Dependency versions are sometimes specified without their package names, for example in config files. These cannot be automatically detected by Renovate, but you can use a regular expression to teach it how to identify these dependencies.

For example, you can specify the version of Hugo to build your Netlify site with in the netlify.toml file in your repository.

[build.environment]
  HUGO_VERSION = "0.109.0"

Enter fullscreen mode Exit fullscreen mode

This is how the relevant configuration might look like with Renovate

{
  "regexManagers": [
    {
      "description": "Update Hugo version in Netlify config",
      "fileMatch": [".toml$"],
      "matchStrings": [
        "HUGO_VERSION = \"(?<currentValue>.*?)\""
      ],
      "depNameTemplate": "gohugoio/hugo",
      "datasourceTemplate": "github-releases"
    }
  ]
}

Enter fullscreen mode Exit fullscreen mode

You can read more about Regex Managers here.

Making your GitHub Actions usage more secure

According to GitHubā€™s official recommendations, you should be using exact commit SHAs instead of tags for third-party actions. However, this is a pain to do manually. Instead, allow Renovate to manage it for you!

{
  "extends": [
    "config:base",
    "helpers:pinGitHubActionDigests",
 ļ»æ ]
}ļ»æ

Enter fullscreen mode Exit fullscreen mode

Automatically merging compatible updates

Every person with a JavaScript project has definitely loved getting 20 PRs from Dependabot about arbitrary transitive dependencies that they didnā€™t even realise they had. With Renovate, that pain can also be automated away if you have a robust enough test suite to permit automatic merging of minor updates.

{
  "automergeType": "branch",
  "packageRules": [
    {
      "description": "Automerge non-major updates",
      "matchUpdateTypes": ["minor", "patch", "digest", "lockFileMaintenance"],
      "automerge": true
    },
  ]
}

Enter fullscreen mode Exit fullscreen mode

With this configuration, Renovate will push compatible updates to renovate/$depName branches and merge it automatically to your main branch if CI runs on the branch and passes. To make that happen, you will also need to update your GitHub Actions workflows.

 name: Run tests
 on:
   pull_request:
     branches:
       - main
+ push:
+ branches:
+ - renovate/**

Enter fullscreen mode Exit fullscreen mode

Closing notes

This list currently consists exclusively of things Iā€™ve used in my own projects. There is way more you can achieve with Renovate, and I recommend going through the docs at docs.renovatebot.com to find any useful knobs for the language ecosystem you wish to use it with. If you come across something interesting not covered here, let me know either below or on Mastodon at @[email protected]!

dependencies Article's
30 articles in total
Favicon
Forge Compatibility Reports for module management
Favicon
A Developerā€™s Guide to Dependency Mapping
Favicon
The Essence of Task Dependencies in Project Management: Definition & Example
Favicon
Wednesday Links - Edition 2024-09-11
Favicon
You Are Not Saved By IaC
Favicon
The Simplest Way to Extract Your Requirements.txt in Python
Favicon
How I can get away with never installing npm packages globally
Favicon
šŸ“š How to see what changed in Composer files
Favicon
Advanced Usage of Dependencies and Models in FastAPI
Favicon
CDK Dependency Strategies
Favicon
How to link a local npm dependency with pnpm
Favicon
It depends! Exploring my favourite Renovate features for dependency updates
Favicon
ERESOLVE unable to resolve dependency tree
Favicon
šŸ“¦ Upgrading Dependencies
Favicon
Python env: be careful with requirements
Favicon
The Better Npm Audit šŸŖ±
Favicon
Choosing dependencies using deps.dev
Favicon
Tips and tricks for using Renovate
Favicon
How to Keep Project Dependencies Up-To-Date
Favicon
Automatically keep project dependencies up to date with Renovate
Favicon
Another cheat sheet for Dependabot
Favicon
When Package Dependencies Become Problematic
Favicon
Automatically manage Python dependencies with requirements.txt
Favicon
Dockerize the Spring Boot Application.
Favicon
Dependency Injection Explained
Favicon
I broke production 3 times in 3 weeks - Part II
Favicon
5 + 1 tips to reduce the noise of Renovate Bot
Favicon
Lock your Android dependencies šŸ”
Favicon
Sorting a Dependency Graph in Go
Favicon
The Essential Guide to Dependency Graphs

Featured ones: