Skip to content

feat: Allow ability to specify a tag-format for providers #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cmd/semantic-release/main.go
Original file line number Diff line number Diff line change
@@ -134,6 +134,13 @@ func cliHandler(cmd *cobra.Command, _ []string) {
if conf.ProviderOpts["token"] == "" {
conf.ProviderOpts["token"] = conf.Token
}

if conf.TagFormat != "" {
conf.ProviderOpts["tag_format"] = conf.TagFormat
}

conf.ProviderOpts["tag_format"] = conf.TagFormat

err = prov.Init(conf.ProviderOpts)
exitIfError(err)

@@ -209,7 +216,9 @@ func cliHandler(cmd *cobra.Command, _ []string) {
logger.Println("getting latest release...")
matchRegex := ""
match := strings.TrimSpace(conf.Match)
if match != "" {
if match != "" && conf.TagFormat != "" {
exitIfError(fmt.Errorf("match should not be specified with tag-format"))
} else if match != "" {
logger.Printf("getting latest release matching %s...", match)
matchRegex = "^" + match
}
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -101,6 +101,7 @@ func NewConfig(cmd *cobra.Command) (*Config, error) {
PluginResolver: viper.GetString("pluginResolver"),
PluginResolverEndpoint: viper.GetString("pluginResolverEndpoint"),
PluginResolverDisableBatchPrefetch: viper.GetBool("pluginResolverDisableBatchPrefetch"),
TagFormat: viper.GetString("tagFormat"),
}
return conf, nil
}
@@ -147,6 +148,7 @@ func SetFlags(cmd *cobra.Command) {
cmd.Flags().StringArray("hooks-opt", []string{}, "options that are passed to the hooks plugins")
cmd.Flags().StringArrayP("update", "u", []string{}, "updates the version of a certain files")
cmd.Flags().String("match", "", "only consider tags matching the given glob(7) pattern, excluding the \"refs/tags/\" prefix.")
cmd.Flags().String("tag-format", "", "Specify a Go template for formatting tags, must be a valid regex after template execution. {{.Version}} is automatically replaced with a semver compatible regex with a named capture group 'version'")
cmd.Flags().String("maintained-version", "", "set the maintained version as base for new releases")
cmd.Flags().BoolP("version-file", "f", false, "create a .version file with the new version")
cmd.Flags().Bool("prerelease", false, "flags the release as a prerelease")
@@ -180,6 +182,9 @@ func SetFlags(cmd *cobra.Command) {
must(viper.BindEnv("pluginResolver", "SEMREL_PLUGIN_RESOLVER"))
must(viper.BindPFlag("pluginResolverDisableBatchPrefetch", cmd.Flags().Lookup("plugin-resolver-disable-batch-prefetch")))
must(viper.BindPFlag("pluginResolverEndpoint", cmd.Flags().Lookup("plugin-resolver-endpoint")))

must(viper.BindPFlag("tagFormat", cmd.Flags().Lookup("tag-format")))
must(viper.BindEnv("tagFormat", "TAG_FORMAT"))
}

func InitConfig(cmd *cobra.Command) error {
183 changes: 88 additions & 95 deletions pkg/config/config.pb.go
1 change: 1 addition & 0 deletions pkg/config/config.proto
Original file line number Diff line number Diff line change
@@ -35,4 +35,5 @@ message Config {
string plugin_resolver = 30;
string plugin_resolver_endpoint = 31;
bool plugin_resolver_disable_batch_prefetch = 32;
string tag_format = 33;
}