Preinstall: Avoid overwriting development versions (#104781)

This commit is contained in:
Andres Martinez Gotor 2025-05-05 14:51:35 +02:00 committed by GitHub
parent 8435eb2876
commit 0d50efe198
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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) {