Skip to content

Commit 7aeede4

Browse files
author
tazhate
committed
fix(versioncheck): fix parseVersionsGen for aligned map entries
The parser used `: "` (4-byte needle including both quotes) to detect and split client entries. For aligned entries like: "": "image:tag", the space between `:` and the opening `"` is multiple characters, so the 4-byte needle was not found and the entry was silently dropped. Replace the brittle needle split with a regex that handles any number of spaces between key, colon, and value: ^"([^"]*)"\s*:\s*"([^"]*)"\s*,?\s*$ Also narrow the test command to skip controller tests that require a running Kubernetes environment.
1 parent df3d342 commit 7aeede4

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

.github/workflows/version-update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
version: v2.11.4
3636

3737
- name: Run tests
38-
run: go test ./internal/... ./api/...
38+
run: go test ./internal/adapters/... ./internal/registry/... ./api/...
3939

4040
- name: Create PR
4141
id: cpr

cmd/versioncheck/main.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"log"
1212
"os"
1313
"path/filepath"
14+
"regexp"
1415
"sort"
1516
"strings"
1617
"sync"
@@ -253,6 +254,12 @@ func versionsGenPath() (string, error) {
253254
return "", fmt.Errorf("could not locate go.mod (run from repo root)")
254255
}
255256

257+
// mapEntryRe matches Go map string entries in both normal and aligned formats:
258+
//
259+
// "key": "value",
260+
// "key": "value",
261+
var mapEntryRe = regexp.MustCompile(`^"([^"]*)"\s*:\s*"([^"]*)"\s*,?\s*$`)
262+
256263
// parseVersionsGen reads versions_gen.go and extracts the chainDefaultImages map.
257264
// Relies on the machine-generated file having a stable, well-known format.
258265
func parseVersionsGen(path string) (map[nodesv1alpha1.Chain]map[string]string, error) {
@@ -289,14 +296,9 @@ func parseVersionsGen(path string) (map[nodesv1alpha1.Chain]map[string]string, e
289296
}
290297

291298
if inChain {
292-
// Client entry: "": "image:tag", or "geth": "image:tag",
293-
if strings.Contains(trimmed, `": "`) {
294-
parts := strings.SplitN(trimmed, `": "`, 2)
295-
if len(parts) == 2 {
296-
clientKey := strings.TrimPrefix(parts[0], `"`)
297-
imageRef := strings.TrimSuffix(strings.TrimSuffix(parts[1], `",`), `"`)
298-
result[currentChain][clientKey] = imageRef
299-
}
299+
// Client entry: "key": "value", or aligned: "key": "value",
300+
if m := mapEntryRe.FindStringSubmatch(trimmed); m != nil {
301+
result[currentChain][m[1]] = m[2]
300302
continue
301303
}
302304
if trimmed == "}," || trimmed == "}" {

0 commit comments

Comments
 (0)