From 5ec9931e37e88226621a3b94c14a3d9769a776e0 Mon Sep 17 00:00:00 2001 From: "Philip K. Warren" Date: Thu, 26 Jan 2023 10:23:09 -0600 Subject: [PATCH] Add plugin dependencies to releases file (#329) In order to optimize lookups, we should add dependency information to the plugin-releases.json file. This will allow us to avoid scanning every .zip file to parse the buf.plugin.yaml. --- cmd/release/main.go | 17 +++++++++++++++++ internal/release/release.go | 1 + 2 files changed, 18 insertions(+) diff --git a/cmd/release/main.go b/cmd/release/main.go index d8058a810..c28cc8209 100644 --- a/cmd/release/main.go +++ b/cmd/release/main.go @@ -220,10 +220,12 @@ func (c *command) calculateNewReleasePlugins(currentRelease *release.PluginRelea URL: downloadURL, LastUpdated: now, Status: status, + Dependencies: pluginDependencies(plugin), }) } else { log.Printf("plugin %s:%s unchanged", pluginRelease.PluginName, pluginRelease.PluginVersion) pluginRelease.Status = release.StatusExisting + pluginRelease.Dependencies = pluginDependencies(plugin) existingPlugins = append(existingPlugins, pluginRelease) } return nil @@ -242,6 +244,21 @@ func (c *command) calculateNewReleasePlugins(currentRelease *release.PluginRelea return plugins, nil } +func pluginDependencies(plugin *plugin.Plugin) []string { + if len(plugin.Deps) == 0 { + return nil + } + deps := make([]string, len(plugin.Deps)) + for i, dep := range plugin.Deps { + if dep.Revision != 0 { + log.Fatalf("unsupported plugin dependency revision: %v", dep.Revision) + } + deps[i] = dep.Plugin + } + sort.Strings(deps) + return deps +} + func (c *command) loadMinisignPublicKeyFromFileOrPrivateKey(privateKey minisign.PrivateKey) (minisign.PublicKey, error) { var publicKey minisign.PublicKey if c.minisignPublicKey != "" { diff --git a/internal/release/release.go b/internal/release/release.go index 5f8f68a6c..da5416fa0 100644 --- a/internal/release/release.go +++ b/internal/release/release.go @@ -39,6 +39,7 @@ type PluginRelease struct { URL string `json:"url"` // URL to GitHub release zip file for the plugin - i.e. https://github.com/bufbuild/plugins/releases/download/20221121.1/bufbuild-connect-go-v1.1.0.zip LastUpdated time.Time `json:"last_updated"` Status Status `json:"-"` + Dependencies []string `json:"dependencies,omitempty"` // direct dependencies on other plugins } // CalculateDigest will calculate the sha256 digest of the given file.