Skip to content

Commit

Permalink
fix: filter the related chart only (#26)
Browse files Browse the repository at this point in the history
Signed-off-by: Michele Palazzi <sysdadmin@m1k.cloud>
  • Loading branch information
ironashram authored Nov 16, 2024
1 parent d13fe72 commit 2a0beb4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
28 changes: 13 additions & 15 deletions src/argoaction/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var readAndParseYAML = func(osi internal.OSInterface, path string) (*models.Appl
return &app, nil
}

var parseNativeNewest = func(targetVersion string, entries map[string][]struct {
var parseNativeNewest = func(targetVersion string, versions []struct {
Version string `yaml:"version"`
}, skipPreRelease bool) (*semver.Version, error) {
target, err := semver.NewVersion(targetVersion)
Expand All @@ -38,21 +38,19 @@ var parseNativeNewest = func(targetVersion string, entries map[string][]struct {
}

var newest *semver.Version
for _, entry := range entries {
for _, version := range entry {
upstream, err := semver.NewVersion(version.Version)
if err != nil {
return nil, err
}
for _, version := range versions {
upstream, err := semver.NewVersion(version.Version)
if err != nil {
return nil, err
}

if skipPreRelease && upstream.Prerelease() != "" {
continue
}
if skipPreRelease && upstream.Prerelease() != "" {
continue
}

if target.LessThan(upstream) {
if newest == nil || newest.LessThan(upstream) {
newest = upstream
}
if target.LessThan(upstream) {
if newest == nil || newest.LessThan(upstream) {
newest = upstream
}
}
}
Expand Down Expand Up @@ -85,7 +83,7 @@ func getNewestVersionFromNative(url string, chart string, targetRevision string,
return nil, nil
}

newest, err := parseNativeNewest(targetRevision, index.Entries, skipPreRelease)
newest, err := parseNativeNewest(targetRevision, index.Entries[chart], skipPreRelease)
if err != nil {
action.Debugf("Error comparing versions: %v\n", err)
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions src/argoaction/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestGetNewestVersion(t *testing.T) {
testCases := []struct {
name string
targetVersion string
entries map[string][]struct {
versions []struct {
Version string `yaml:"version"`
}
skipPreRelease bool
Expand All @@ -87,23 +87,23 @@ func TestGetNewestVersion(t *testing.T) {
{
name: "Test Case 1",
targetVersion: "1.0.0",
entries: map[string][]struct {
versions: []struct {
Version string `yaml:"version"`
}{
"entry1": {{Version: "1.1.0"}, {Version: "1.2.0"}},
"entry2": {{Version: "1.3.0"}, {Version: "1.4.0"}},
{Version: "1.1.0"},
{Version: "1.4.0"},
},
skipPreRelease: true,
expected: semver.MustParse("1.4.0"),
},
{
name: "Test Case 2",
targetVersion: "1.0.0",
entries: map[string][]struct {
versions: []struct {
Version string `yaml:"version"`
}{
"entry1": {{Version: "0.9.0"}, {Version: "0.8.0"}},
"entry2": {{Version: "0.7.0"}, {Version: "0.6.0"}},
{Version: "0.8.0"},
{Version: "0.9.5"},
},
skipPreRelease: true,
expected: nil,
Expand All @@ -112,7 +112,7 @@ func TestGetNewestVersion(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result, err := parseNativeNewest(tc.targetVersion, tc.entries, tc.skipPreRelease)
result, err := parseNativeNewest(tc.targetVersion, tc.versions, tc.skipPreRelease)

assert.Equal(t, tc.expected, result)
assert.Equal(t, tc.expectedErr, err)
Expand Down

0 comments on commit 2a0beb4

Please sign in to comment.