release: Fix release candidate to major version upgrade check

Fix `kata-runtime kata-check`'s network version check which was failing
when the user was running a release candidate build and the latest
release was a major one, two examples of the error being:

- `BUG: unhandled scenario: current version: 1.12.0-rc0, latest version: 1.12.0`
- `BUG: unhandled scenario: current version: 2.0.0-rc0, latest version: 2.0.0`

Fixes: #1104.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
James O. D. Hunt 2020-11-12 10:07:18 +00:00
parent 2e0bf40adb
commit 8f38265be4
2 changed files with 12 additions and 0 deletions

View File

@ -321,6 +321,12 @@ func getNewReleaseType(current semver.Version, latest semver.Version) (string, e
}
} else if latest.Patch == current.Patch && len(latest.Pre) > 0 {
desc = "pre-release"
} else if latest.Major == current.Major &&
latest.Minor == current.Minor &&
latest.Patch == current.Patch {
if len(current.Pre) > 0 && len(latest.Pre) == 0 {
desc = "major"
}
} else {
return "", fmt.Errorf("BUG: unhandled scenario: current version: %s, latest version: %s", current, latest)
}

View File

@ -488,6 +488,12 @@ func TestGetNewReleaseType(t *testing.T) {
{"1.0.0", "1.0.3", false, "patch"},
{"1.0.0-beta29", "1.0.0-beta30", false, "pre-release"},
{"1.0.0", "1.0.3-alpha99.1b", false, "patch pre-release"},
{"2.0.0-rc0", "2.0.0", false, "major"},
{"2.0.0-rc1", "2.0.0", false, "major"},
{"1.12.0-rc0", "1.12.0", false, "major"},
{"1.12.0-rc5", "1.12.0", false, "major"},
}
for i, d := range data {