Use parts of matchStrings in autoReplaceStringTemplate #29068
-
What would you like help with?I would like help with my configuration How are you running Renovate?Self-hosted If you're self-hosting Renovate, tell us which platform (GitHub, GitLab, etc) and which version of Renovate.Gitlab; Renovate '37-full' Please tell us more about your question or problemI have created a custom manager: {
"customManagers": [
{
"customType": "regex",
"fileMatch": [
"^.*\\.ya?ml$"
],
"matchStrings": [
"originalImage=(?<depName>.*?)\\s.*: *(?<currentValue>[vV]?\\d+[\\.\\-\\w+]*)(@(?<currentDigest>sha256:[a-f0-9]+))?"
],
"datasourceTemplate": "docker"
}
]
} With this manager I can define the actual dependency in a comment before the line with the value/version. Here an example: # originalImage=the-actual/image
version: 1.2.3
# originalImage=another/image
image: my-virtual/image:1.2.3 In the previous example Renovate successfully detects:
To enable Renovate to pin digests, I have read that I have to tell Renovate how to replace the original match. This is by defining autoReplaceStringTemplate. But how can I re-use required parts of the "matchStrings" in my "autoReplaceStringTemplate"? This is required, because I don't know the whole match aforehand. I tried to use a custom named capture group named "customPrelude", which didn't work: {
"customManagers": [
{
"customType": "regex",
"fileMatch": [
"^.*\\.ya?ml$"
],
"matchStrings": [
"originalImage=(?<depName>.*?)\\s(?<customPrelude>.*: *)(?<currentValue>[vV]?\\d+[\\.\\-\\w+]*)(@(?<currentDigest>sha256:[a-f0-9]+))?"
],
"autoReplaceStringTemplate": "originalImage={{{depName}}}\n{{{customPrelude}}}:{{{newValue}}}{{#if newDigest}}@{{{newDigest}}}{{/if}}",
"datasourceTemplate": "docker"
}
]
} So is this even possible? Logs (if relevant)No response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
Try using both depName and packageName |
Beta Was this translation helpful? Give feedback.
I've found a way better solution than before.
With this solution I ship around the "blank problem" and also don't need any custom named capture groupd.
For this solution I needed to understand, that Renovate only replaces the last match, when using
recursive
match strategy.So in the last match I can focus on detecting the version and possible digest.
I didn't need to bother with whats between the version and the package name.
I have update my example with the latest tag: https://github.com/ThomasSteinbach/renovate-29068-example/blob/best-solution/renovate.json
The essence is, that in the last regex I only match the version. Then there is no need for a complex
autoReplaceStringTemplate
.