Skip to content

Commit bc5cd1d

Browse files
authored
Merge pull request #21971 from Caesarsage/fix-get-version-multiple-matches
Fix: get_version.go returns wrong version when multiple entries exist
2 parents f0e3a0d + f16e986 commit bc5cd1d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

hack/update/get_version/get_version.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,15 @@ func main() {
135135
if err != nil {
136136
log.Fatalf("failed to read file: %v", err)
137137
}
138-
submatches := re.FindSubmatch(data)
138+
139+
// this handles cases where multiple versions exist (e.g., old and new versions in go.mod)
140+
allMatches := re.FindAllSubmatch(data, -1)
141+
if len(allMatches) == 0 {
142+
log.Fatalf("no matches found")
143+
}
144+
145+
// Take the last match (most recent version)
146+
submatches := allMatches[len(allMatches)-1]
139147
if len(submatches) < 2 {
140148
log.Fatalf("less than 2 submatches found")
141149
}

0 commit comments

Comments
 (0)