From 037983df1efbec2d75fc86cb2c8eb5ad9a8ef335 Mon Sep 17 00:00:00 2001 From: maulik13 Date: Thu, 21 Jan 2021 17:52:08 +0100 Subject: [PATCH 1/2] feat(release): add an option to specify a custom prefix for the version tag --- internal/releaser/git/git.go | 7 ++++++- internal/releaser/github/github.go | 6 +++++- internal/releaser/gitlab/gitlab.go | 6 +++++- pkg/config/config.go | 7 +++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/releaser/git/git.go b/internal/releaser/git/git.go index 61245e9..cde0a1d 100644 --- a/internal/releaser/git/git.go +++ b/internal/releaser/git/git.go @@ -67,7 +67,12 @@ func (g *Client) GetCompareURL(oldVersion, newVersion string) string { // CreateRelease creates release on remote func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, _ *assets.Set) error { - tag := "v" + releaseVersion.Next.Version.String() + tagPrefix := config.DefaultTagPrefix + if g.config.TagPrefix != nil{ + tagPrefix = *g.config.TagPrefix + } + tag := tagPrefix + releaseVersion.Next.Version.String() + g.log.Infof("create release with version %s", tag) head, err := g.git.Repository.Head() diff --git a/internal/releaser/github/github.go b/internal/releaser/github/github.go index 07adb07..5668ccc 100644 --- a/internal/releaser/github/github.go +++ b/internal/releaser/github/github.go @@ -90,7 +90,11 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC // CreateRelease creates release on remote func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error { - tag := "v" + releaseVersion.Next.Version.String() + tagPrefix := config.DefaultTagPrefix + if g.config.TagPrefix != nil{ + tagPrefix = *g.config.TagPrefix + } + tag := tagPrefix + releaseVersion.Next.Version.String() g.log.Debugf("create release with version %s", tag) prerelease := releaseVersion.Next.Version.Prerelease() != "" diff --git a/internal/releaser/gitlab/gitlab.go b/internal/releaser/gitlab/gitlab.go index 9186b7b..5526e62 100644 --- a/internal/releaser/gitlab/gitlab.go +++ b/internal/releaser/gitlab/gitlab.go @@ -98,7 +98,11 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC // CreateRelease creates release on remote func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error { - tag := "v" + releaseVersion.Next.Version.String() + tagPrefix := config.DefaultTagPrefix + if g.config.TagPrefix != nil{ + tagPrefix = *g.config.TagPrefix + } + tag := tagPrefix + releaseVersion.Next.Version.String() g.Release = tag g.log.Infof("create release with version %s", tag) url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo)) diff --git a/pkg/config/config.go b/pkg/config/config.go index 008c176..091a7ff 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,6 +9,10 @@ import ( "gopkg.in/yaml.v2" ) +const ( + DefaultTagPrefix = "v" +) + // ChangelogConfig struct type ChangelogConfig struct { PrintAll bool `yaml:"printAll,omitempty"` @@ -44,6 +48,7 @@ type GitHubProvider struct { User string `yaml:"user"` CustomURL string `yaml:"customUrl,omitempty"` AccessToken string + TagPrefix *string `yaml:"tagPrefix,omitempty"` } // GitLabProvider struct @@ -51,6 +56,7 @@ type GitLabProvider struct { Repo string `yaml:"repo"` CustomURL string `yaml:"customUrl,omitempty"` AccessToken string + TagPrefix *string `yaml:"tagPrefix,omitempty"` } // GitProvider struct @@ -59,6 +65,7 @@ type GitProvider struct { Username string `yaml:"user"` Auth string `yaml:"auth"` SSH bool `yaml:"ssh"` + TagPrefix *string `yaml:"tagPrefix,omitempty"` } // Hooks struct From 15a17e546b9832ea12e83b9df7c9772fcd84b47f Mon Sep 17 00:00:00 2001 From: maulik13 Date: Thu, 21 Jan 2021 21:39:52 +0100 Subject: [PATCH 2/2] docs: update the readme file to include the tagPrefix parameter --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 082dc68..c53b209 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## Release Types -| Type | Implemendet | Git tag | Changelog | Release | Write access git | Api token | +| Type | Implemented | Git tag | Changelog | Release | Write access git | Api token | | ----------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | | `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | @@ -60,7 +60,7 @@ hooks: #### CommitFormat -Set the commit format, at the moment we support ony [angular](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format), more coming soon. +Set the commit format, at the moment we support only [angular](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format), more coming soon. ```yml commitFormat: angular @@ -97,8 +97,10 @@ release: 'github' github: user: "" - ## Optional, if your not using github.com + ## Optional, if you are not using github.com customUrl: + ## Optional, if you want to change the default tag prefix ("v") + tagPrefix: "" ``` ##### Gitlab @@ -112,6 +114,8 @@ gitlab: repo: "" ## Example group/project ## Optional, if your not using gitlab.com customUrl: + ## Optional, if you want to change the default tag prefix ("v") + tagPrefix: "" ``` ##### Git only @@ -125,6 +129,8 @@ git: email: "" # Used for creating tag user: "" : # Used for creating tag and pushing auth: "" # Used for pushing, can be env "$GIT_TOKEN", will be replaced with env + ## Optional, if you want to change the default tag prefix ("v") + tagPrefix: "" ``` @@ -176,7 +182,7 @@ changelog: ### Version -`go-semantic-release` has two modes for calcualting the version: automatic or manual. +`go-semantic-release` has two modes for calculating the version: automatic or manual. #### Automatic