Skip to content

Commit 637d8fd

Browse files
authored
Merge pull request #3820 from olamilekan000/fix-lima-failing-to-run-when-version-is-not-properly-set
fix limactl run bug by treating unparseable versions as latest instead of crashing during template validation.
2 parents 2f01516 + c492c69 commit 637d8fd

File tree

5 files changed

+31
-37
lines changed

5 files changed

+31
-37
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ jobs:
2727
timeout-minutes: 30
2828
steps:
2929
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
30-
with:
31-
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
32-
fetch-depth: 0
3330
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
3431
with:
3532
go-version: 1.24.x
@@ -218,9 +215,6 @@ jobs:
218215
git config --global core.autocrlf false
219216
git config --global core.eol lf
220217
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
221-
with:
222-
# To avoid "can't parse builtin Lima version" errors
223-
fetch-depth: 0
224218
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
225219
with:
226220
go-version: 1.24.x
@@ -246,9 +240,6 @@ jobs:
246240
timeout-minutes: 120
247241
steps:
248242
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
249-
with:
250-
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
251-
fetch-depth: 0
252243
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
253244
with:
254245
go-version: 1.24.x
@@ -318,9 +309,6 @@ jobs:
318309
- ../hack/test-templates/test-misc.yaml # TODO: merge net-user-v2 into test-misc
319310
steps:
320311
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
321-
with:
322-
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
323-
fetch-depth: 0
324312
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
325313
with:
326314
go-version: 1.24.x
@@ -370,6 +358,8 @@ jobs:
370358
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
371359
with:
372360
# fetch-depth is set to 0 to let `limactl --version` print semver-ish version
361+
# fetch-depth: 0 is required for Colima integration test because Colima
362+
# checks Lima's version and requires proper semantic version format
373363
fetch-depth: 0
374364
ref: ${{ github.event.pull_request.head.sha }}
375365
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
@@ -415,8 +405,6 @@ jobs:
415405
timeout-minutes: 120
416406
steps:
417407
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
418-
with:
419-
fetch-depth: 0
420408
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
421409
with:
422410
go-version: 1.24.x
@@ -470,9 +458,6 @@ jobs:
470458
oldver: ["v0.15.1"] # The default VM type was always QEMU until Lima v1.0
471459
steps:
472460
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
473-
with:
474-
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
475-
fetch-depth: 0
476461
- name: Fetch homebrew-core commit messages
477462
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
478463
with:
@@ -515,8 +500,6 @@ jobs:
515500
- default.yaml
516501
steps:
517502
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
518-
with:
519-
fetch-depth: 0
520503
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
521504
with:
522505
go-version: 1.24.x
@@ -550,8 +533,6 @@ jobs:
550533
timeout-minutes: 30
551534
steps:
552535
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
553-
with:
554-
fetch-depth: 0
555536
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
556537
with:
557538
go-version: 1.24.x
@@ -577,9 +558,6 @@ jobs:
577558
timeout-minutes: 30
578559
steps:
579560
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
580-
with:
581-
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
582-
fetch-depth: 0
583561
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
584562
with:
585563
go-version: 1.24.x
@@ -592,9 +570,6 @@ jobs:
592570
timeout-minutes: 30
593571
steps:
594572
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
595-
with:
596-
# To avoid "failed to load YAML file \"templates/experimental/riscv64.yaml\": can't parse builtin Lima version \"3f3a6f6\": 3f3a6f6 is not in dotted-tri format"
597-
fetch-depth: 0
598573
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
599574
with:
600575
go-version: 1.24.x

pkg/limayaml/validate.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ func Validate(y *LimaYAML, warn bool) error {
4040
if _, err := versionutil.Parse(*y.MinimumLimaVersion); err != nil {
4141
errs = errors.Join(errs, fmt.Errorf("field `minimumLimaVersion` must be a semvar value, got %q: %w", *y.MinimumLimaVersion, err))
4242
}
43-
limaVersion, err := versionutil.Parse(version.Version)
44-
if err != nil {
45-
errs = errors.Join(errs, fmt.Errorf("can't parse builtin Lima version %q: %w", version.Version, err))
46-
}
47-
if limaVersion != nil && versionutil.GreaterThan(*y.MinimumLimaVersion, limaVersion.String()) {
48-
errs = errors.Join(errs, fmt.Errorf("template requires Lima version %q; this is only %q", *y.MinimumLimaVersion, limaVersion.String()))
43+
// Unparsable version.Version (like commit hashes or "<unknown>") is treated as "latest/greatest"
44+
// and will pass all version comparisons, allowing development builds to work.
45+
if !versionutil.GreaterEqual(version.Version, *y.MinimumLimaVersion) {
46+
errs = errors.Join(errs, fmt.Errorf("template requires Lima version %q; this is only %q", *y.MinimumLimaVersion, version.Version))
4947
}
5048
}
5149
if y.VMOpts.QEMU.MinimumVersion != nil {

pkg/limayaml/validate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ func TestValidateMinimumLimaVersion(t *testing.T) {
3838
name: "minimumLimaVersion greater than current version",
3939
currentVersion: "1.1.1-114-g5bf5e513",
4040
minimumLimaVersion: "1.1.2",
41-
wantErr: `template requires Lima version "1.1.2"; this is only "1.1.1"`,
41+
wantErr: `template requires Lima version "1.1.2"; this is only "1.1.1-114-g5bf5e513"`,
4242
},
4343
{
4444
name: "invalid current version",
4545
currentVersion: "<unknown>",
4646
minimumLimaVersion: "0.8.0",
47-
wantErr: `can't parse builtin Lima version "<unknown>": <unknown> is not in dotted-tri format`,
47+
wantErr: "", // Unparsable versions are treated as "latest"
4848
},
4949
{
5050
name: "invalid minimumLimaVersion",
5151
currentVersion: "1.1.1-114-g5bf5e513",
5252
minimumLimaVersion: "invalid",
53-
wantErr: "field `minimumLimaVersion` must be a semvar value, got \"invalid\": invalid is not in dotted-tri format\ntemplate requires Lima version \"invalid\"; this is only \"1.1.1\"",
53+
wantErr: "field `minimumLimaVersion` must be a semvar value, got \"invalid\": invalid is not in dotted-tri format", // Only parse error, no comparison error
5454
},
5555
}
5656

pkg/version/versionutil/versionutil.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ func compare(limaVersion, oldVersion string) int {
3131
if err != nil {
3232
return 1
3333
}
34-
cmp := version.Compare(*semver.New(oldVersion))
34+
// Handle Unparsable oldVersion gracefully - treat as 0.0.0 so Unparsable limaVersion is always greater
35+
oldVer, err := semver.NewVersion(oldVersion)
36+
if err != nil {
37+
return 1
38+
}
39+
cmp := version.Compare(*oldVer)
3540
if cmp == 0 && strings.Contains(limaVersion, "-") {
3641
cmp = 1
3742
}

pkg/version/versionutil/versionutil_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,19 @@ func TestParse(t *testing.T) {
4141
assert.Equal(t, v2.Minor, int64(19))
4242
assert.Equal(t, v2.Patch, int64(1))
4343
}
44+
45+
func TestCompareWithUnparsableOldVersion(t *testing.T) {
46+
assert.Equal(t, GreaterThan("1.0.0", "invalid-version"), true)
47+
assert.Equal(t, GreaterThan("0.1.0", "<unknown>"), true)
48+
assert.Equal(t, GreaterThan("0.0.1", "commit-hash-abc123"), true)
49+
50+
assert.Equal(t, GreaterEqual("1.0.0", "invalid-version"), true)
51+
assert.Equal(t, GreaterEqual("0.1.0", "<unknown>"), true)
52+
assert.Equal(t, GreaterEqual("0.0.1", "commit-hash-abc123"), true)
53+
54+
assert.Equal(t, GreaterThan("invalid-lima-version", "1.0.0"), true)
55+
assert.Equal(t, GreaterEqual("invalid-lima-version", "1.0.0"), true)
56+
57+
assert.Equal(t, GreaterThan("invalid-lima-version", "invalid-old-version"), true)
58+
assert.Equal(t, GreaterEqual("invalid-lima-version", "invalid-old-version"), true)
59+
}

0 commit comments

Comments
 (0)