Skip to content

Commit c1b1b11

Browse files
gionnCopilot
andauthored
Document usage of replaceall (#2738)
* Initial plan * docs: document replaceall usage under versionFilter for regex and regex/semver kinds Co-authored-by: gionn <71768+gionn@users.noreply.github.com> * avoid duplicating the sections. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 56e1161 commit c1b1b11

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

content/en/docs/plugins/_versionFilter.adoc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ If `versionFilter.kind` is set to `regex` then we can use `versionFilter.pattern
5757
return the newest version returned from a resource matching the regex
5858
If no versionFilter.pattern is provided then it uses '.*' which return the newest version
5959

60+
`versionFilter.replaceall` can optionally be used to transform version strings before the regex is applied.
61+
It accepts a `pattern` (regex) and a `replacement` string, similar to a find-and-replace operation.
62+
6063
```
6164
sources:
6265
kubectl:
@@ -74,6 +77,28 @@ sources:
7477
```
7578
=> Return the newest kubectl version matching pattern "kubernetes-1.(\\d*).(\\d*)$" and remove "kubernetes-" from it
7679

80+
===== Example with replaceall
81+
82+
Some projects use version tags that are not directly compatible with the regex pattern. For example, curl uses tags like
83+
`curl-8_11_1` where underscores separate version components.
84+
The `replaceall` option can be used to normalize these tags before applying the regex.
85+
86+
```yaml
87+
sources:
88+
curl:
89+
kind: githubRelease
90+
spec:
91+
owner: "curl"
92+
repository: "curl"
93+
versionFilter:
94+
kind: regex
95+
regex: 'curl-(\d+\.\d+\.\d+)'
96+
replaceall:
97+
pattern: "_"
98+
replacement: "."
99+
```
100+
=> The `replaceall` converts `curl-8_11_1` to `curl-8.11.1` before matching, then the regex extracts `8.11.1`
101+
77102
==== semver
78103

79104
If `versionFilter.kind` is set to `semver` then we can use `versionFilter.pattern` to specify version pattern as explained link:https://github.com/Masterminds/semver#checking-version-constraints[here]. In the process we also sort.
@@ -108,6 +133,10 @@ We can then use `versionFilter.pattern` to specify version pattern as explained
108133
If no `versionFilter.pattern` is provided then it fallback to '*' which return the newest version.
109134
If a extracted version doesn't respect semantic versioning, then it's not the value is just ignored.
110135

136+
`versionFilter.replaceall` can optionally be used to transform version strings before the regex is applied.
137+
It accepts a `pattern` (regex) and a `replacement` string, similar to a find-and-replace operation.
138+
See the [regex section](#_regexp) for an example.
139+
111140
===== Example
112141

113142
```

0 commit comments

Comments
 (0)