Tips about Renovate
Tags: renovate
Published: 2021-09-25 00:45:10

In this post, I introduce some tips about [Renovate](https://github.com/renovatebot/renovate).

## Assign reviewers

https://docs.renovatebot.com/configuration-options/#reviewers

It's good to assign reviewers to prevent pull requests from being left.
You can assign GitHub Users and Teams.
On the other hand, if pull requests would be merged automatically, it is not good to assign reviewers because it is noisy.

## Restrict targets

By default, all Managers are enabled.
If you want to update only specific packages, you have to configure [enableManagers](https://docs.renovatebot.com/configuration-options/#enabledmanagers).
And if you want to update only specific files, [includePaths](https://docs.renovatebot.com/configuration-options/#includepaths) would be useful.
If you want to exclude some files, [ignorePaths](https://docs.renovatebot.com/configuration-options/#ignorepaths) is also useful.
Especially if you want to update packages for the specific service in Monorepo, this would be helpful.

## Automerge

[automerge](https://docs.renovatebot.com/configuration-options/#automerge) drastically decreases the burden of handling pull requests by Renovate.
You should use automerge actively.
On the other hand, in some cases automerge isn't desirable so you have to restrict targets of automerge.
For example, it is good to exclude the major update.

```json
    {
      "matchUpdateTypes": ["major"],
      "automerge": false
    }
```

## renovate-approve app

If at least one approval is required to merge pull requests, the GitHub App [renovate-approve](https://github.com/apps/renovate-approve) would be useful.

## Automerge safely

In case of Terraform CI/CD, it would be dangerous to merge pull requests automatically even if CI passes,
because unexpected changes may be applied.
By making CI failed if the pull request author is `renovate[bot]` and the exit code of [terraform plan -detailed-exitcode](https://www.terraform.io/docs/commands/plan.html#detailed-exitcode) is two, you can prevent unexpected changes.


## Regex Manager

Renovate supports [various Managers](https://docs.renovatebot.com/modules/manager/), but sometimes you want to update packages which aren't supported by any Managers.
In that case, Regex Manager would be helpful.
For example, if you download tools from GitHub Releases in shell scripts, you can update tools with Regex Managers.

```sh
version=v0.7.2 # renovate: depName=suzuki-shunsuke/aqua
URL=https://github.com/suzuki-shunsuke/aqua/releases/download/${version}/aqua_linux_amd64.tar.gz
curl --fail -L "$URL" -o aqua_linux_amd64.tar.gz
```

```json
{
  "regexManagers": [
    {
      "fileMatch": ["^.*\\.sh"],
      "matchStrings": ["version=(?<currentValue>.*?) # renovate: depName=(?<depName>.*?)\\n"],
      "datasourceTemplate": "github-releases"
    }
  ]
}
```

For detail of Regex Manger, please see the document.

https://docs.renovatebot.com/modules/manager/regex/

## renovate-config-validator

When Renovate Configuration is updated, it should be validated with renovate-config-validator.
GitHub Actions is useful for it.

e.g. https://github.com/suzuki-shunsuke/aqua/blob/v0.7.2/.github/workflows/renovate-config-validator.yaml

## Split pull requests by `additionalBranchPrefix`

If the same package is used in multiple services in Monorepo,
by default Renovate updates them in the same pull request.
If you want to split pull requests per service,
[additionalBranchPrefix](https://docs.renovatebot.com/configuration-options/#additionalbranchprefix) and [commitMessageSuffix](https://docs.renovatebot.com/configuration-options/#commitmessagesuffix) are useful.

For example, in case of Monorepo of Terraform,
by the following configuration you can update Terraform Providers per service.

```json
{
  "packageRules": [
    {
      "managers": ["terraform"],
      "additionalBranchPrefix": "{{baseDir}}-",
      "packagePatterns": [".*"],
      "commitMessageSuffix": "({{baseDir}})"
    }
  ]
}
```

About the template variables, please see https://docs.renovatebot.com/templates/

## JSON5

Renovate Configuration supports JSON and [JSON5](https://json5.org/).
If you want to write code comments, JSON5 is useful.
On the other hand, the support of JSON5 by tools like editor, IDE, formatter, and linter is poorer than JSON.

## Test Configuration in test repository

When you change Renovate Configuration, you can validate it with renovate-config-validator but it is difficult to test it in CI.

I created some repositories for testing Renovate Configuration.

* https://github.com/suzuki-shunsuke/test-renovate
* https://github.com/suzuki-shunsuke/test-renovate-2
* https://github.com/suzuki-shunsuke/test-renovate-3

It is good to test Renovate Configuration before sending pull requests.

For example, please see the pull request https://github.com/renovatebot/github-action/pull/557 .
Before sending this pull request, I tested the Configuration in a test repository and described it in the pull request description.

## Restrict

If you are tired to handle pull requests by Renovate, it maybe good to restrict pull requests.

* [prConcurrentLimit](https://docs.renovatebot.com/configuration-options/#prconcurrentlimit)
* [prHourlyLimit](https://docs.renovatebot.com/configuration-options/#prhourlylimit)
* [schedule](https://docs.renovatebot.com/configuration-options/#schedule)

## Add links to pull requests

Using [prBodyNotes](https://docs.renovatebot.com/configuration-options/#prbodynotes), you can add helpful links to pull requests.

For example, in case of the package `ingress-nginx`, I added the following links.

e.g.

```json
    {
      "matchManagers": ["helmfile"],
      "matchPackageNames": ["ingress-nginx"],
      "prBodyNotes": [
        "[compare](https://github.com/kubernetes/ingress-nginx/compare/helm-chart-{{currentVersion}}...helm-chart-{{newVersion}}), [Changelog](https://github.com/kubernetes/ingress-nginx/blob/main/charts/ingress-nginx/CHANGELOG.md), [Artifact Hub](https://artifacthub.io/packages/helm/ingress-nginx/ingress-nginx?modal=changelog)"
      ]
    }
```

It is bothersome that you have to configure links per package, but it is helpful to review the pull request.

## Debug

If Renovate doesn't work as expected, there are some ways for debug.
If you use [GitHub App of Renovate](https://github.com/marketplace/renovate), you can check the log with [Renovate Dashboard](https://app.renovatebot.com/dashboard).
You can also run Renovate at localhost.

```
$ npm i -g renovate
$ export RENOVATE_TOKEN=xxx # GitHub Access Token
$ LOG_LEVEL=debug renovate --dry-run=true <repository>
```

[Dependency Dashboard](https://docs.renovatebot.com/configuration-options/#dependencydashboard) is also useful to find the problem.

## Decrease the priority of the specific package for other packages

* [prPriority](https://docs.renovatebot.com/configuration-options/#prpriority)

If the package A is updated so frequently that other packages aren't updated,
maybe it may be good to decrease the priority of the package A.