Automagically migrating golangci-lint
configuration to v2 with Renovate

As mentioned in Using Renovate to manage updates to golangci-lint
versions I very much recommend using Renovate to update your golangci-lint
versions.
With the release of golangci-lint v2 a couple of weeks ago, consumers need to perform a one-time migration of their configuration.
(I'd meant to post this last week, but yay ADHD, I forgot π«£)
However, one thing that came with the upgrade was that for each and every PR you get from Renovate, you need to check out the code locally and i.e. run:
# i.e. for my setup
rm -r bin/golangci-lint
make golangci-lint
bin/golangci-lint migrate
git add .golangci.yml
git commit --amend
# not -with-lease=ref (https://www.jvt.me/posts/2018/09/18/safely-force-git-push/)
git push --force
This is a little tedious, albeit heavily scriptable.
So how do we get Renovate to do this for us, given it knows there's a major version bump to upgrade to?
This only works if you're self-hosting Renovate, where you have access to allowedCommands
which allowlists arbitrary commands to be run by repository configuration.
Therefore, in our global self-hosting configuration we want to set:
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"packageRules": [
{
"matchPackageNames": [
"github.com/golangci/golangci-lint"
],
"matchUpdateTypes": [
"major"
],
"postUpgradeTasks": {
"commands": [
"make golangci-lint && bin/golangci-lint migrate"
],
"executionMode": "branch",
"fileFilters": [
"^Makefile$",
".golangci.y*ml"
]
}
}
],
"allowedCommands": [
"^make golangci-lint && bin/golangci-lint migrate$"
]
}
This ensures that for any repository across this Renovate's usage, it will:
- find major upgrades from v1 of
golangci-lint
(as a Go module on v1, it does not have a semantic import path) - run
make golangci-lint
to install thegolangci-lint
binary, which should install intobin
- run
bin/golangci-lint migrate
to migrate the configuration
If at any point this fails, for instance if the repository doesn't have a make golangci-lint
task, or doesn't install into bin
, this will fail, and the PR will still require manual handling.
But for those that do work, this shaves off a chunk of time of getting these PRs merged and onto using the latest-and-greatest π