regexversioningregex-negationrenovate

Regex for self hosted renovate bot to fetch linuxserver.io stable images


I've setup the renovate selfhosted bot. Since linuxserver.io has different schemas of creating docker tags, i'll switched to regex.

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": [
    "config:base",
    "docker:enableMajor"
  ],
  "packageRules": [
    {
      "packagePatterns": ["^ghcr.io\\/linuxserver\\/"],
      "versionScheme": "regex:MYFANCYREGEX"
    }
  ]
}

But I need help getting the regex up and running. I created a regex 101 with unittest and example - here

100.200.300
100.200.300.7068-ls170
v100.200.300-ls213
version-100.200.300
version-100.200.300-ls180
version-100.200.300.11111
100.200.300.7068-ls170
nigthly-100.200.300  -> not stable, no match
nightly-100.200.300.3604-ls587  -> not stable, no match
100.200.300-development -> not stable, no match
100.200.300-develop -> not stable, no match
100.200.300-nigthly -> not stable, no match

I'm somehow not able to exclude matches containing something -> (?! or ^)

How should I change the regex to only get stable builds and the image updates (ls/buildnumbers)


Solution

  • I would go with this regex (using the x flag for readability):

    /^
    
    # Build information should not contain dev and nightly stuff:
    (?!.*(nig(ht|th)ly|develop|development))
    
    # Optional compatibility prefix "version-" or "v":
    (?<compatibility>[a-z]*-|v)?
    
    # Major, minor and patch numbers:
    (?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)
    
    # Capture the optional build information:
    (?:
      [\.-]?
      (?<build>.*)
    )?
    
    $/gmx
    

    Updated your regex101 case study here: https://regex101.com/r/KQZykk/4

    If you cannot use the x flag then use the uncommented version that I added here: https://regex101.com/r/KQZykk/5

    PS: To pass from commented to uncommented regex, I created a little tool that you can access here: https://codepen.io/patacra/pen/wvQBxjq