diff --git a/pkg/services/pluginsintegration/plugininstaller/service.go b/pkg/services/pluginsintegration/plugininstaller/service.go index d49fe12b0da..ccebdf184fe 100644 --- a/pkg/services/pluginsintegration/plugininstaller/service.go +++ b/pkg/services/pluginsintegration/plugininstaller/service.go @@ -129,6 +129,10 @@ func (s *Service) shouldUpdate(ctx context.Context, pluginID, currentVersion str s.log.Debug("New major version available, skipping update due to possible breaking changes", "pluginId", pluginID, "version", info.Version) return false } + if parsedCurrentVersion.Compare(parsedLatestVersion) >= 0 { + s.log.Debug("No update available", "pluginId", pluginID, "version", info.Version) + return false + } // We should update the plugin return true diff --git a/pkg/services/pluginsintegration/plugininstaller/service_test.go b/pkg/services/pluginsintegration/plugininstaller/service_test.go index d2b8668560f..1df3c8d2888 100644 --- a/pkg/services/pluginsintegration/plugininstaller/service_test.go +++ b/pkg/services/pluginsintegration/plugininstaller/service_test.go @@ -120,6 +120,20 @@ func TestService_Run(t *testing.T) { shouldInstall: true, pluginsToInstall: []setting.InstallPlugin{{ID: "myplugin", URL: "https://example.com/myplugin.tar.gz"}}, }, + { + name: "Should not update a plugin if the current version is greater than the latest version", + shouldInstall: false, + pluginsToInstall: []setting.InstallPlugin{{ID: "myplugin", Version: ""}}, + existingPlugins: []*plugins.Plugin{{JSONData: plugins.JSONData{ID: "myplugin", Info: plugins.Info{Version: "1.0.1"}}}}, + latestPlugin: &repo.PluginArchiveInfo{Version: "1.0.0"}, + }, + { + name: "Should not update a plugin if the current version is equal to the latest version, ignoring the prerelease", + shouldInstall: false, + pluginsToInstall: []setting.InstallPlugin{{ID: "myplugin", Version: ""}}, + existingPlugins: []*plugins.Plugin{{JSONData: plugins.JSONData{ID: "myplugin", Info: plugins.Info{Version: "1.0.0"}}}}, + latestPlugin: &repo.PluginArchiveInfo{Version: "1.0.0-rc.1"}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {