Skip to content

Commit 9746cf6

Browse files
feat: add plugin resolver options
1 parent 4283738 commit 9746cf6

File tree

8 files changed

+57
-23
lines changed

8 files changed

+57
-23
lines changed

cmd/semantic-release/main.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ func cliHandler(cmd *cobra.Command, args []string) {
107107
return
108108
}
109109

110-
ok, _, err := pluginManager.PrefetchAllPluginsIfBatchIsPossible()
111-
if err != nil {
112-
logger.Printf("warning: failed to prefetch plugins: %v", err)
113-
}
114-
if ok {
115-
logger.Println("all plugins were prefetched")
110+
if !conf.PluginResolverDisableBatchPrefetch {
111+
ok, _, pErr := pluginManager.PrefetchAllPluginsIfBatchIsPossible()
112+
if pErr != nil {
113+
logger.Printf("warning: failed to prefetch plugins: %v", pErr)
114+
}
115+
if ok {
116+
logger.Println("all plugins were prefetched!")
117+
}
116118
}
117119

118120
ci, err := pluginManager.GetCICondition()

pkg/config/config.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type Config struct {
4141
ShowProgress bool
4242
AllowMaintainedVersionOnDefaultBranch bool
4343
PluginResolver string
44+
PluginResolverEndpoint string
45+
PluginResolverDisableBatchPrefetch bool
4446
}
4547

4648
func mustGetString(cmd *cobra.Command, name string) string {
@@ -133,6 +135,8 @@ func NewConfig(cmd *cobra.Command) (*Config, error) {
133135
ShowProgress: mustGetBool(cmd, "show-progress"),
134136
AllowMaintainedVersionOnDefaultBranch: mustGetBool(cmd, "allow-maintained-version-on-default-branch"),
135137
PluginResolver: viper.GetString("pluginResolver"),
138+
PluginResolverEndpoint: viper.GetString("pluginResolverEndpoint"),
139+
PluginResolverDisableBatchPrefetch: viper.GetBool("pluginResolverDisableBatchPrefetch"),
136140
}
137141
return conf, nil
138142
}
@@ -193,7 +197,9 @@ func SetFlags(cmd *cobra.Command) {
193197
cmd.Flags().Bool("show-progress", false, "shows the plugin download progress")
194198
cmd.Flags().String("config", "", "config file (default is .semrelrc)")
195199
cmd.Flags().Bool("allow-maintained-version-on-default-branch", false, "allow configuring the maintained version on the default branch")
196-
cmd.Flags().String("plugin-resolver", "registry", "which resolver should be used to resolve plugins (registry or github)")
200+
cmd.Flags().String("plugin-resolver", "registry-v1", "which resolver should be used to resolve plugins (registry-v1, registry-v2 or github)")
201+
cmd.Flags().Bool("plugin-resolver-disable-batch-prefetch", false, "plugins should not be batch prefetched using the registry")
202+
cmd.Flags().String("plugin-resolver-endpoint", "", "explicitly specify the resolver endpoint that should be used for resolving the plugin dependencies")
197203
cmd.Flags().SortFlags = true
198204

199205
must(viper.BindPFlag("maintainedVersion", cmd.Flags().Lookup("maintained-version")))
@@ -208,6 +214,8 @@ func SetFlags(cmd *cobra.Command) {
208214

209215
must(viper.BindPFlag("pluginResolver", cmd.Flags().Lookup("plugin-resolver")))
210216
must(viper.BindEnv("pluginResolver", "SEMREL_PLUGIN_RESOLVER"))
217+
must(viper.BindPFlag("pluginResolverDisableBatchPrefetch", cmd.Flags().Lookup("plugin-resolver-disable-batch-prefetch")))
218+
must(viper.BindPFlag("pluginResolverEndpoint", cmd.Flags().Lookup("plugin-resolver-endpoint")))
211219
}
212220

213221
func InitConfig(cmd *cobra.Command) error {

pkg/plugin/discovery/discovery.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ func loadResolvers(resolvers ...resolver.Resolver) (map[string]resolver.Resolver
3434
}
3535

3636
func New(config *config.Config) (*Discovery, error) {
37-
resolvers, err := loadResolvers(registryV1.NewResolver(), github.NewResolver(), registry.NewResolver())
37+
resolvers, err := loadResolvers(
38+
registry.NewResolver(config.PluginResolverEndpoint),
39+
registryV1.NewResolver(config.PluginResolverEndpoint),
40+
github.NewResolver(),
41+
)
3842
if err != nil {
3943
return nil, err
4044
}

pkg/plugin/discovery/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func downloadBatchPlugins(pluginInfos []*plugin.Info, downloadInfo *resolver.Bat
144144

145145
res := grab.DefaultClient.Do(req)
146146
if showProgress {
147-
showDownloadProgressBar("batched-plugins", res)
147+
showDownloadProgressBar("batched-plugins.tar.gz", res)
148148
}
149149
err = res.Err()
150150
if err != nil {

pkg/plugin/discovery/resolver/registry/registry.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"runtime"
77
"sort"
8+
"strings"
89

910
"github.com/Masterminds/semver/v3"
1011
"github.com/go-semantic-release/plugin-registry/pkg/client"
@@ -13,15 +14,22 @@ import (
1314
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver"
1415
)
1516

16-
const DefaultEndpoint = "https://registry-staging.go-semantic-release.xyz/api/v2"
17+
const DefaultEndpoint = "https://registry.go-semantic-release.xyz/api/v2"
1718

1819
type Resolver struct {
1920
client *client.Client
2021
}
2122

22-
func NewResolver() *Resolver {
23+
func NewResolver(endpoint string) *Resolver {
24+
if endpoint == "" {
25+
endpoint = DefaultEndpoint
26+
}
27+
endpoint = strings.TrimSuffix(endpoint, "/")
28+
if !strings.HasSuffix(endpoint, "/api/v2") {
29+
endpoint = fmt.Sprintf("%s/api/v2", endpoint)
30+
}
2331
return &Resolver{
24-
client: client.New(DefaultEndpoint),
32+
client: client.New(endpoint),
2533
}
2634
}
2735

@@ -110,6 +118,5 @@ func (r *Resolver) BatchResolvePlugins(pluginInfos []*plugin.Info) (*resolver.Ba
110118
}
111119

112120
func (r *Resolver) Names() []string {
113-
// TODO: this should be registry when the registry is ready
114-
return []string{"registry-beta"}
121+
return []string{"registry", "registry-v2"}
115122
}

pkg/plugin/discovery/resolver/registryV1/api.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"time"
1010
)
1111

12-
const PluginAPI = "https://plugins.go-semantic-release.xyz/api/v1"
13-
1412
type apiPluginAsset struct {
1513
FileName string
1614
URL string
@@ -38,8 +36,8 @@ type apiPlugin struct {
3836
Versions map[string]*apiPluginRelease
3937
}
4038

41-
func getPluginInfo(name string) (*apiPlugin, error) {
42-
res, err := http.Get(fmt.Sprintf("%s/plugins/%s.json", PluginAPI, name))
39+
func getPluginInfo(endpoint, name string) (*apiPlugin, error) {
40+
res, err := http.Get(fmt.Sprintf("%s/plugins/%s.json", endpoint, name))
4341
if err != nil {
4442
return nil, err
4543
}

pkg/plugin/discovery/resolver/registryV1/registry.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,34 @@ import (
55
"fmt"
66
"runtime"
77
"sort"
8+
"strings"
89

910
"github.com/Masterminds/semver/v3"
1011
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin"
1112
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver"
1213
)
1314

14-
type Resolver struct{}
15+
const DefaultEndpoint = "https://plugins.go-semantic-release.xyz/api/v1"
1516

16-
func NewResolver() *Resolver {
17-
return &Resolver{}
17+
type Resolver struct {
18+
endpoint string
19+
}
20+
21+
func NewResolver(endpoint string) *Resolver {
22+
if endpoint == "" {
23+
endpoint = DefaultEndpoint
24+
}
25+
endpoint = strings.TrimSuffix(endpoint, "/")
26+
if !strings.HasSuffix(endpoint, "/api/v1") {
27+
endpoint = fmt.Sprintf("%s/api/v1", endpoint)
28+
}
29+
return &Resolver{
30+
endpoint: endpoint,
31+
}
1832
}
1933

2034
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) {
21-
pluginAPIRes, err := getPluginInfo(pluginInfo.ShortNormalizedName)
35+
pluginAPIRes, err := getPluginInfo(r.endpoint, pluginInfo.ShortNormalizedName)
2236
if err != nil {
2337
return nil, err
2438
}
@@ -61,5 +75,5 @@ func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownl
6175
}
6276

6377
func (r *Resolver) Names() []string {
64-
return []string{"registry"}
78+
return []string{"registry-v1"}
6579
}

pkg/plugin/discovery/resolver/resolver.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ type Resolver interface {
2020
}
2121

2222
type BatchResolver interface {
23+
// BatchResolvePlugins resolves a list of plugins and returns a single URL to download all plugins as tgz archive.
2324
BatchResolvePlugins([]*plugin.Info) (*BatchPluginDownloadInfo, error)
2425
}

0 commit comments

Comments
 (0)