Skip to content

Commit 9a75641

Browse files
feat: registry v2 initial
1 parent 124eecd commit 9a75641

File tree

5 files changed

+98
-69
lines changed

5 files changed

+98
-69
lines changed

pkg/plugin/discovery/discovery.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver"
1010
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver/github"
1111
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver/registry"
12+
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver/registryV1"
1213
)
1314

1415
type Discovery struct {
@@ -33,7 +34,7 @@ func loadResolvers(resolvers ...resolver.Resolver) (map[string]resolver.Resolver
3334
}
3435

3536
func New(config *config.Config) (*Discovery, error) {
36-
resolvers, err := loadResolvers(registry.NewResolver(), github.NewResolver())
37+
resolvers, err := loadResolvers(registryV1.NewResolver(), github.NewResolver(), registry.NewResolver())
3738
if err != nil {
3839
return nil, err
3940
}
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,30 @@
11
package registry
22

33
import (
4-
"errors"
54
"fmt"
6-
"runtime"
7-
"sort"
85

9-
"github.com/Masterminds/semver/v3"
6+
"github.com/go-semantic-release/plugin-registry/pkg/client"
107
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin"
118
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver"
129
)
1310

14-
type Resolver struct{}
11+
const DefaultEndpoint = "https://registry-staging.go-semantic-release.xyz/api/v2"
1512

16-
func NewResolver() *Resolver {
17-
return &Resolver{}
13+
type Resolver struct {
14+
client *client.Client
1815
}
1916

20-
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) {
21-
pluginAPIRes, err := getPluginInfo(pluginInfo.NormalizedName)
22-
if err != nil {
23-
return nil, err
24-
}
25-
26-
foundVersion := ""
27-
if pluginInfo.Constraint == nil {
28-
foundVersion = pluginAPIRes.LatestRelease
29-
} else {
30-
versions := make(semver.Collection, 0)
31-
for v := range pluginAPIRes.Versions {
32-
pv, err := semver.NewVersion(v)
33-
if err != nil {
34-
return nil, err
35-
}
36-
versions = append(versions, pv)
37-
}
38-
sort.Sort(sort.Reverse(versions))
39-
for _, v := range versions {
40-
if pluginInfo.Constraint.Check(v) {
41-
foundVersion = v.String()
42-
break
43-
}
44-
}
45-
}
46-
47-
if foundVersion == "" {
48-
return nil, errors.New("version not found")
17+
func NewResolver() *Resolver {
18+
return &Resolver{
19+
client: client.New(DefaultEndpoint),
4920
}
21+
}
5022

51-
releaseAsset := pluginAPIRes.Versions[foundVersion].getMatchingAsset()
52-
if releaseAsset == nil {
53-
return nil, fmt.Errorf("a matching plugin was not found for %s/%s", runtime.GOOS, runtime.GOARCH)
54-
}
55-
return &resolver.PluginDownloadInfo{
56-
URL: releaseAsset.URL,
57-
Checksum: releaseAsset.Checksum,
58-
FileName: releaseAsset.FileName,
59-
Version: foundVersion,
60-
}, nil
23+
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) {
24+
return nil, fmt.Errorf("not implemented")
6125
}
6226

6327
func (r *Resolver) Names() []string {
64-
return []string{"registry"}
28+
// TODO: this should be registry when the registry is ready
29+
return []string{"registry-beta"}
6530
}

pkg/plugin/discovery/resolver/registry/api.go renamed to pkg/plugin/discovery/resolver/registryV1/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package registry
1+
package registryV1
22

33
import (
44
"encoding/json"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package registryV1
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"runtime"
7+
"sort"
8+
9+
"github.com/Masterminds/semver/v3"
10+
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin"
11+
"github.com/go-semantic-release/semantic-release/v2/pkg/plugin/discovery/resolver"
12+
)
13+
14+
type Resolver struct{}
15+
16+
func NewResolver() *Resolver {
17+
return &Resolver{}
18+
}
19+
20+
func (r *Resolver) ResolvePlugin(pluginInfo *plugin.Info) (*resolver.PluginDownloadInfo, error) {
21+
pluginAPIRes, err := getPluginInfo(pluginInfo.NormalizedName)
22+
if err != nil {
23+
return nil, err
24+
}
25+
26+
foundVersion := ""
27+
if pluginInfo.Constraint == nil {
28+
foundVersion = pluginAPIRes.LatestRelease
29+
} else {
30+
versions := make(semver.Collection, 0)
31+
for v := range pluginAPIRes.Versions {
32+
pv, err := semver.NewVersion(v)
33+
if err != nil {
34+
return nil, err
35+
}
36+
versions = append(versions, pv)
37+
}
38+
sort.Sort(sort.Reverse(versions))
39+
for _, v := range versions {
40+
if pluginInfo.Constraint.Check(v) {
41+
foundVersion = v.String()
42+
break
43+
}
44+
}
45+
}
46+
47+
if foundVersion == "" {
48+
return nil, errors.New("version not found")
49+
}
50+
51+
releaseAsset := pluginAPIRes.Versions[foundVersion].getMatchingAsset()
52+
if releaseAsset == nil {
53+
return nil, fmt.Errorf("a matching plugin was not found for %s/%s", runtime.GOOS, runtime.GOARCH)
54+
}
55+
return &resolver.PluginDownloadInfo{
56+
URL: releaseAsset.URL,
57+
Checksum: releaseAsset.Checksum,
58+
FileName: releaseAsset.FileName,
59+
Version: foundVersion,
60+
}, nil
61+
}
62+
63+
func (r *Resolver) Names() []string {
64+
return []string{"registry"}
65+
}

pkg/plugin/manager/manager.go

+18-20
Original file line numberDiff line numberDiff line change
@@ -124,29 +124,27 @@ func (m *PluginManager) Stop() {
124124
plugin.KillAllPlugins()
125125
}
126126

127-
func (m *PluginManager) FetchAllPlugins() error {
128-
pluginMap := map[string]string{
129-
condition.CIConditionPluginName: m.config.CIConditionPlugin,
130-
provider.PluginName: m.config.ProviderPlugin,
131-
analyzer.CommitAnalyzerPluginName: m.config.CommitAnalyzerPlugin,
132-
generator.ChangelogGeneratorPluginName: m.config.ChangelogGeneratorPlugin,
133-
}
134-
for t, name := range pluginMap {
135-
_, err := m.discovery.FindPlugin(t, name)
136-
if err != nil {
137-
return err
138-
}
139-
}
140-
127+
func (m *PluginManager) getAllPlugins() [][]string {
128+
plugins := make([][]string, 0, 4)
129+
// required plugins
130+
plugins = append(plugins, []string{condition.CIConditionPluginName, m.config.CIConditionPlugin})
131+
plugins = append(plugins, []string{provider.PluginName, m.config.ProviderPlugin})
132+
plugins = append(plugins, []string{analyzer.CommitAnalyzerPluginName, m.config.CommitAnalyzerPlugin})
133+
plugins = append(plugins, []string{generator.ChangelogGeneratorPluginName, m.config.ChangelogGeneratorPlugin})
134+
135+
// optional plugins
141136
for _, pl := range m.config.FilesUpdaterPlugins {
142-
_, err := m.discovery.FindPlugin(updater.FilesUpdaterPluginName, pl)
143-
if err != nil {
144-
return err
145-
}
137+
plugins = append(plugins, []string{updater.FilesUpdaterPluginName, pl})
146138
}
147-
148139
for _, pl := range m.config.HooksPlugins {
149-
_, err := m.discovery.FindPlugin(hooks.PluginName, pl)
140+
plugins = append(plugins, []string{hooks.PluginName, pl})
141+
}
142+
return plugins
143+
}
144+
145+
func (m *PluginManager) FetchAllPlugins() error {
146+
for _, pl := range m.getAllPlugins() {
147+
_, err := m.discovery.FindPlugin(pl[0], pl[1])
150148
if err != nil {
151149
return err
152150
}

0 commit comments

Comments
 (0)