Skip to content
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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
Loading