Search code examples
renovate

Renovate: multiple 'allowedVersions' settings for the same package pattern


Our company-preset-repo default.json contains the following packageRule which is supposed to exclude maven dependencies that contain .redhat- in the <version> field.

{
  "matchManagers": ["maven"],
  "matchPackageNames": [
    "commons-io:commons-io",
    "org.apache.commons:commons-lang3",
    "org.apache.httpcomponents:httpclient",
    "com.cronutils:cron-utils",
    "com.jayway.jsonpath:json-path",
    "com.thoughtworks.xstream:xstream",
    "javax.xml.bind:jaxb-api",
    "net.sf.jopt-simple:jopt-simple",
    "org.jsoup:jsoup",
    "org.yaml:snakeyaml"
  ],
  "allowedVersions": "!/\\.redhat-/"
}

In my own team, I created my own renovate preset default.json file which extends local>company-preset-repo and that looks something like this, with the aim of preventing renovate from replacing e.g. commons-io version 2.11.0 with version 20030203.000550:

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "description": [
    "Default preset for my team"
  ],
  "gitAuthor": "some@email",
  "extends": [
    "local>company-preset-repo"
  ],
  "packageRules": [
    {
      "matchPackagePatterns": [
        "^org.apache.commons:",
        "^commons-beanutils:",
        "^commons-cli:",
        "^commons-collections:",
        "^commons-io:"
      ],
      "allowedVersions": "/^\\d{1,2}\\.\\d{1,2}(\\..*)?$/"
    }
  ]
}

Here's my problem:

I'm getting renovate pull-requests for commons-io version 2.11.0.redhat-00001. I want both the first pattern to apply AND the second pattern to apply. In other words, I only want renovate to suggest dependency updates for commons-io when both of these patterns apply:

  1. The version isn't something like 20030203.000550
  2. AND: The version doesn't contain .redhat-

Can this be done, and if so, how?


Solution

  • In the end we solved it with a Regex which combines both patterns into one single pattern. So for those few packages in my own rule it is this more complex pattern that is applied instead of the more simple one from company-preset-repo.

    "allowedVersions": "/^(\\d{1,3}\\.)(\\d*\\.)*\\d*(?!.*\\.redhat-.*)$/"