Skip to content

Commit 6128fdb

Browse files
authored
feat(bump): add --skip-tag flag (#39)
1 parent d30d06f commit 6128fdb

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ Bumps the latest version to the next version, creates a tag and pushes it to `or
2828

2929
**Options:**
3030

31-
| Name | Description |
32-
| -------------------- | -------------------------------------------------------------------------- |
33-
| `-P, --password` | Password to use in HTTP basic authentication (useful for CI/CD pipelines) |
34-
| `-u, --username` | Username to use in HTTP basic authentication (useful for CI/CD pipelines) |
35-
| `-f, --version-file` | Version files that should be updated. Format should be `filename:key` |
31+
| Name | Description |
32+
| -------------------- | ------------------------------------------------------------------------- |
33+
| `-P, --password` | Password to use in HTTP basic authentication (useful for CI/CD pipelines) |
34+
| `-u, --username` | Username to use in HTTP basic authentication (useful for CI/CD pipelines) |
35+
| `-f, --version-file` | Version files that should be updated. Format should be `filename:key` |
36+
| `--v-prefix` | Prefix the version with a `v` |
37+
| `--skip-tag` | Don't create a new tag automatically |
3638

3739
**Example:**
3840

@@ -57,6 +59,12 @@ $ git semver latest
5759

5860
Outputs the next unreleased version.
5961

62+
**Options:**
63+
64+
| Name | Description |
65+
| -------------------- | ------------------------------------------------------------------------- |
66+
| `--v-prefix` | Prefix the version with a `v` |
67+
6068
**Example:**
6169

6270
```shell

cmd/gitsemver/gitsemver.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var bumpCmd = &cobra.Command{
2222
project := newProjectOrPanic(cmd)
2323
versionFilenamesAndKeys := getVersionFilenamesAndKeysOrFail(cmd)
2424
vPrefix := getVPrefixOrFail(cmd)
25+
skipTag := getSkipTagOrFail(cmd)
2526
username := getUsernameOrFail(cmd)
2627
password := getPasswordOrFail(cmd)
2728
latest := getLatestVersionOrFail(project)
@@ -36,7 +37,7 @@ var bumpCmd = &cobra.Command{
3637
}
3738
}
3839

39-
if err := project.Bump(versionFilenamesAndKeys, auth, vPrefix); err != nil {
40+
if err := project.Bump(versionFilenamesAndKeys, auth, vPrefix, skipTag); err != nil {
4041
log.Fatalln(err)
4142
}
4243

@@ -81,6 +82,7 @@ func init() {
8182
bumpCmd.Flags().StringP("username", "u", "", "Username to use in HTTP basic authentication")
8283
bumpCmd.Flags().StringP("password", "P", "", "Password to use in HTTP basic authentication")
8384
bumpCmd.Flags().Bool("v-prefix", false, "Prefix the version with a `v`")
85+
bumpCmd.Flags().Bool("skip-tag", false, "Don't create a new tag automatically")
8486

8587
nextCmd.Flags().Bool("v-prefix", false, "Prefix the version with a `v`")
8688
}
@@ -157,3 +159,12 @@ func getVPrefixOrFail(cmd *cobra.Command) bool {
157159

158160
return vPrefix
159161
}
162+
163+
func getSkipTagOrFail(cmd *cobra.Command) bool {
164+
skipTag, err := cmd.Flags().GetBool("skip-tag")
165+
if err != nil {
166+
log.Fatalln(err)
167+
}
168+
169+
return skipTag
170+
}

pkg/gitsemver/project.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (p *Project) NextVersionIncrement() (Increment, error) {
198198
return increment, nil
199199
}
200200

201-
func (p *Project) Bump(versionFilenamesAndKeys []string, auth AuthMethod, vPrefix bool) error {
201+
func (p *Project) Bump(versionFilenamesAndKeys []string, auth AuthMethod, vPrefix, skipTag bool) error {
202202
latest, err := p.LatestVersion()
203203
if err != nil {
204204
return err
@@ -227,15 +227,19 @@ func (p *Project) Bump(versionFilenamesAndKeys []string, auth AuthMethod, vPrefi
227227
}
228228
}
229229

230-
tagName := TagNameFromProjectAndVersion(p, next)
231-
tagMessage := fmt.Sprintf("Release %s", tagName)
230+
if !skipTag {
231+
tagName := TagNameFromProjectAndVersion(p, next)
232+
tagMessage := fmt.Sprintf("Release %s", tagName)
232233

233-
if err := git.CreateTag(p.Repo(), tagName, tagMessage); err != nil {
234-
return err
234+
if err := git.CreateTag(p.Repo(), tagName, tagMessage); err != nil {
235+
return err
236+
}
235237
}
236238

237-
if err := git.PushToOrigin(p.Repo(), auth); err != nil {
238-
return err
239+
if !skipTag || len(versionFilenamesAndKeys) > 0 {
240+
if err := git.PushToOrigin(p.Repo(), auth); err != nil {
241+
return err
242+
}
239243
}
240244

241245
return nil

0 commit comments

Comments
 (0)