Fix parseHelmVersion to handle helm versions without 'v' prefix (#2132)
* Initial plan * Fix panic in helmfile init when parsing invalid helm versions Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> * Fix parseHelmVersion to handle versions without v prefix Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> * Simplify parseHelmVersion function to be more readable Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
This commit is contained in:
parent
8c123dcdda
commit
7f18858182
|
|
@ -69,7 +69,13 @@ func parseHelmVersion(versionStr string) (*semver.Version, error) {
|
|||
return nil, fmt.Errorf("empty helm version")
|
||||
}
|
||||
|
||||
v, err := chartify.FindSemVerInfo(versionStr)
|
||||
// Check if version string starts with "v", if not add it
|
||||
processedVersion := strings.TrimSpace(versionStr)
|
||||
if !strings.HasPrefix(processedVersion, "v") {
|
||||
processedVersion = "v" + processedVersion
|
||||
}
|
||||
|
||||
v, err := chartify.FindSemVerInfo(processedVersion)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error find helm srmver version '%s': %w", versionStr, err)
|
||||
|
|
|
|||
|
|
@ -1140,6 +1140,24 @@ func TestParseHelmVersion(t *testing.T) {
|
|||
want: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "version without v prefix",
|
||||
version: "3.2.4",
|
||||
want: semver.MustParse("v3.2.4"),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "version without v prefix with build info",
|
||||
version: "3.2.4+ge29ce2a",
|
||||
want: semver.MustParse("v3.2.4+ge29ce2a"),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "version without v prefix with spaces",
|
||||
version: " 3.2.4 ",
|
||||
want: semver.MustParse("v3.2.4"),
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue