Plugins: Update CLI check if plugin is already installed (#91213)

* check if plugin installed

* undo remove initial vers check

* still attempt deps
This commit is contained in:
Will Browne 2024-08-06 09:21:40 +01:00 committed by GitHub
parent da291998cf
commit 9300c1bbea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 9 deletions

View File

@ -117,8 +117,13 @@ func doInstallPlugin(ctx context.Context, pluginID, version string, o pluginInst
// If a version is specified, check if it is already installed // If a version is specified, check if it is already installed
if version != "" { if version != "" {
if services.PluginVersionInstalled(pluginID, version, o.pluginDir) { if p, ok := services.PluginVersionInstalled(pluginID, version, o.pluginDir); ok {
services.Logger.Successf("Plugin %s v%s already installed.", pluginID, version) services.Logger.Successf("Plugin %s v%s already installed.", pluginID, version)
for _, depP := range p.JSONData.Dependencies.Plugins {
if err := doInstallPlugin(ctx, depP.ID, depP.Version, o, installing); err != nil {
return err
}
}
return nil return nil
} }
} }
@ -133,13 +138,28 @@ func doInstallPlugin(ctx context.Context, pluginID, version string, o pluginInst
var archive *repo.PluginArchive var archive *repo.PluginArchive
var err error var err error
pluginZipURL := o.pluginURL if o.pluginURL != "" {
if pluginZipURL != "" { archive, err = repository.GetPluginArchiveByURL(ctx, o.pluginURL, compatOpts)
if archive, err = repository.GetPluginArchiveByURL(ctx, pluginZipURL, compatOpts); err != nil { if err != nil {
return err return err
} }
} else { } else {
if archive, err = repository.GetPluginArchive(ctx, pluginID, version, compatOpts); err != nil { archiveInfo, err := repository.GetPluginArchiveInfo(ctx, pluginID, version, compatOpts)
if err != nil {
return err
}
if p, ok := services.PluginVersionInstalled(pluginID, archiveInfo.Version, o.pluginDir); ok {
services.Logger.Successf("Plugin %s v%s already installed.", pluginID, archiveInfo.Version)
for _, depP := range p.JSONData.Dependencies.Plugins {
if err = doInstallPlugin(ctx, depP.ID, depP.Version, o, installing); err != nil {
return err
}
}
return nil
}
if archive, err = repository.GetPluginArchiveByURL(ctx, archiveInfo.URL, compatOpts); err != nil {
return err return err
} }
} }

View File

@ -88,14 +88,14 @@ func GetLocalPlugins(pluginDir string) []*plugins.FoundBundle {
return res return res
} }
func PluginVersionInstalled(pluginID, version, pluginDir string) bool { func PluginVersionInstalled(pluginID, version, pluginDir string) (plugins.FoundPlugin, bool) {
for _, bundle := range GetLocalPlugins(pluginDir) { for _, bundle := range GetLocalPlugins(pluginDir) {
pJSON := bundle.Primary.JSONData pJSON := bundle.Primary.JSONData
if pJSON.ID == pluginID { if pJSON.ID == pluginID {
if pJSON.Info.Version == version { if pJSON.Info.Version == version {
return true return bundle.Primary, true
} }
} }
} }
return false return plugins.FoundPlugin{}, false
} }

View File

@ -237,7 +237,7 @@ func readPluginJSON(pluginDir string) (plugins.JSONData, error) {
// nolint:gosec // nolint:gosec
data, err = os.ReadFile(pluginPath) data, err = os.ReadFile(pluginPath)
if err != nil { if err != nil {
return plugins.JSONData{}, fmt.Errorf("could not find plugin.json or dist/plugin.json for in %s", pluginDir) return plugins.JSONData{}, fmt.Errorf("could not find plugin.json or dist/plugin.json in %s", pluginDir)
} }
} }