Skip to content

Commit

Permalink
Add plugin dependencies to releases file (#329)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pkwarren authored Jan 26, 2023
1 parent ef3c312 commit 5ec9931
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 != "" {
Expand Down
1 change: 1 addition & 0 deletions internal/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5ec9931

Please sign in to comment.