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 the golangci-lint binary, which should install into bin
  • 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 πŸš€

Written by Jamie Tanna's profile image Jamie Tanna on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

This blog post is 100% human-written, and has nothing derived from LLMs (be it code, editorial support or prose).

Also on:

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.