Skip to content

Commit f4865bf

Browse files
feat: add download plugins flag
1 parent 41b1bd6 commit f4865bf

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

cmd/semantic-release/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ func cliHandler(cmd *cobra.Command, args []string) {
8484
exitIfError(errors.New("terminating..."))
8585
}()
8686

87+
if conf.DownloadPlugins {
88+
exitIfError(pluginManager.FetchAllPlugins())
89+
logger.Println("all plugins are downloaded")
90+
os.Exit(0)
91+
}
92+
8793
ci, err := pluginManager.GetCICondition()
8894
exitIfError(err)
8995
logger.Printf("ci-condition plugin: %s@%s\n", ci.Name(), ci.Version())

pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Config struct {
3535
AllowNoChanges bool
3636
MaintainedVersion string
3737
PrependChangelog bool
38+
DownloadPlugins bool
3839
}
3940

4041
func mustGetString(cmd *cobra.Command, name string) string {
@@ -122,6 +123,7 @@ func NewConfig(cmd *cobra.Command) (*Config, error) {
122123
AllowNoChanges: mustGetBool(cmd, "allow-no-changes"),
123124
MaintainedVersion: viper.GetString("maintainedVersion"),
124125
PrependChangelog: mustGetBool(cmd, "prepend-changelog"),
126+
DownloadPlugins: mustGetBool(cmd, "download-plugins"),
125127
}
126128
return conf, nil
127129
}
@@ -174,6 +176,7 @@ func InitConfig(cmd *cobra.Command) error {
174176
cmd.Flags().Bool("allow-initial-development-versions", false, "semantic-release will start your initial development release at 0.1.0")
175177
cmd.Flags().Bool("allow-no-changes", false, "exit with code 0 if no changes are found, useful if semantic-release is automatically run")
176178
cmd.Flags().Bool("prepend-changelog", false, "if the changelog file already exist the new changelog is prepended")
179+
cmd.Flags().Bool("download-plugins", false, "downloads all required plugins if needed")
177180
cmd.Flags().SortFlags = true
178181

179182
viper.AddConfigPath(".")

pkg/plugin/manager/manager.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,33 @@ func (m *PluginManager) GetChainedHooksExecutor() (*hooks.ChainedHooksExecutor,
116116
func (m *PluginManager) Stop() {
117117
plugin.KillAllPlugins()
118118
}
119+
120+
func (m *PluginManager) FetchAllPlugins() error {
121+
pluginMap := map[string]string{
122+
condition.CIConditionPluginName: m.config.CIConditionPlugin,
123+
provider.PluginName: m.config.ProviderPlugin,
124+
analyzer.CommitAnalyzerPluginName: m.config.CommitAnalyzerPlugin,
125+
generator.ChangelogGeneratorPluginName: m.config.ChangelogGeneratorPlugin,
126+
}
127+
for t, name := range pluginMap {
128+
_, err := discovery.FindPlugin(t, name)
129+
if err != nil {
130+
return err
131+
}
132+
}
133+
134+
for _, pl := range m.config.FilesUpdaterPlugins {
135+
_, err := discovery.FindPlugin(updater.FilesUpdaterPluginName, pl)
136+
if err != nil {
137+
return err
138+
}
139+
}
140+
141+
for _, pl := range m.config.HooksPlugins {
142+
_, err := discovery.FindPlugin(hooks.PluginName, pl)
143+
if err != nil {
144+
return err
145+
}
146+
}
147+
return nil
148+
}

0 commit comments

Comments
 (0)