func pluginUpdate(c *cli.Context) error { // Input validation if len(c.Args()) == 0 { log.Fatal("Missing plugin name") } name := c.Args()[0] if name == "" { log.Fatal("Missing plugin name") } plugin, found, err := plugins.LoadPlugin(name) if err != nil { log.Fatalf("Failed to check if plugin (%s) installed, error: %s", name, err) } else if !found { log.Fatalf("Plugin (%s) is not installed", name) } // Check for new version if newVersion, err := plugins.CheckForNewVersion(plugin); err != nil { log.Fatalf("Failed to check for plugin (%s) new version, error: %s", plugin.Name, err) } else if newVersion != "" { log.Infof("Installing new version (%s) of plugin (%s)", newVersion, plugin.Name) route, found, err := plugins.ReadPluginRoute(plugin.Name) if err != nil { log.Fatalf("Failed to read plugin route, error: %s", err) } if !found { log.Fatalf("no route found for already loaded plugin (%s)", plugin.Name) } plugin, version, err := plugins.InstallPlugin(route.Source, newVersion) if err != nil { log.Fatalf("Failed to install plugin from (%s), error: %s", route.Source, err) } fmt.Println() log.Infoln(colorstring.Greenf("Plugin (%s) with version (%s) installed ", plugin.Name, version)) if len(plugin.Description) > 0 { fmt.Println() fmt.Println(plugin.Description) fmt.Println() } } else { log.Info("No new version available") } return nil }
// Run ... func Run() { // Parse cl cli.VersionPrinter = printVersion app := cli.NewApp() app.Name = path.Base(os.Args[0]) app.Usage = "Bitrise Automations Workflow Runner" app.Version = version.VERSION app.Author = "" app.Email = "" app.Before = before app.Flags = flags app.Commands = commands app.Action = func(c *cli.Context) error { pluginName, pluginArgs, isPlugin := plugins.ParseArgs(c.Args()) if isPlugin { log.Debugf("Try to run bitrise plugin: (%s) with args: (%v)", pluginName, pluginArgs) plugin, found, err := plugins.LoadPlugin(pluginName) if err != nil { return fmt.Errorf("Failed to get plugin (%s), error: %s", pluginName, err) } if !found { return fmt.Errorf("Plugin (%s) not installed", pluginName) } log.Debugf("Start plugin: (%s)", pluginName) if err := plugins.RunPluginByCommand(plugin, pluginArgs); err != nil { return fmt.Errorf("Failed to run plugin (%s), error: %s", pluginName, err) } } else { if err := cli.ShowAppHelp(c); err != nil { return fmt.Errorf("Failed to show help, error: %s", err) } return errors.New("") } return nil } if err := app.Run(os.Args); err != nil { log.Fatal(err) } }
func pluginDelete(c *cli.Context) error { // Input validation if len(c.Args()) == 0 { log.Fatal("Missing plugin name") } name := c.Args()[0] if name == "" { log.Fatal("Missing plugin name") } if _, found, err := plugins.LoadPlugin(name); err != nil { log.Fatalf("Failed to check if plugin (%s) installed, error: %s", name, err) } else if !found { log.Fatalf("Plugin (%s) is not installed", name) } versionPtr, err := plugins.GetPluginVersion(name) if err != nil { log.Fatalf("Failed to read plugin (%s) version, error: %s", name, err) } // Delete version := "local" if versionPtr != nil { version = versionPtr.String() } log.Infof("=> Deleting plugin (%s) with version (%s) ...", name, version) if err := plugins.DeletePlugin(name); err != nil { log.Fatalf("Failed to delete plugin (%s) with version (%s), error: %s", name, version, err) } fmt.Println() log.Infof(colorstring.Greenf("Plugin (%s) with version (%s) deleted", name, version)) return nil }
// CheckIsPluginInstalled ... func CheckIsPluginInstalled(name string, dependency PluginDependency) error { _, found, err := plugins.LoadPlugin(name) if err != nil { return err } currentVersion := "" installOrUpdate := false if !found { fmt.Println() log.Warnf("Default plugin (%s) NOT found.", name) fmt.Println() fmt.Print("Installing...") installOrUpdate = true currentVersion = dependency.MinVersion } else { installedVersion, err := plugins.GetPluginVersion(name) if err != nil { return err } if installedVersion == nil { fmt.Println() log.Warnf("Default plugin (%s) is not installed from git, no version info available.", name) fmt.Println() currentVersion = "local" } else { currentVersion = installedVersion.String() minVersion, err := ver.NewVersion(dependency.MinVersion) if err != nil { return err } if installedVersion.LessThan(minVersion) { fmt.Println() log.Warnf("Default plugin (%s) version (%s) is lower than required (%s).", name, installedVersion.String(), minVersion.String()) fmt.Println() log.Infoln("Updating...") installOrUpdate = true currentVersion = dependency.MinVersion } } } if installOrUpdate { var plugin plugins.Plugin err := progress.SimpleProgressE(".", 2*time.Second, func() error { return retry.Times(2).Wait(5 * time.Second).Try(func(attempt uint) error { if attempt > 0 { fmt.Println() fmt.Print("==> Download failed, retrying ...") } p, _, err := plugins.InstallPlugin(dependency.Source, dependency.Binary, dependency.MinVersion) plugin = p return err }) }) fmt.Println() if err != nil { return fmt.Errorf("Failed to install plugin, error: %s", err) } if len(plugin.Description) > 0 { fmt.Println() fmt.Println(plugin.Description) fmt.Println() } } pluginDir := plugins.GetPluginDir(name) log.Infof(" * %s Plugin (%s) : %s", colorstring.Green("[OK]"), name, pluginDir) log.Infof(" version : %s", currentVersion) return nil }