Skip to content

Commit

Permalink
feat(bump): add --skip-tag flag (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrqr authored Feb 14, 2022
1 parent d30d06f commit 6128fdb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ Bumps the latest version to the next version, creates a tag and pushes it to `or

**Options:**

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

**Example:**

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

Outputs the next unreleased version.

**Options:**

| Name | Description |
| -------------------- | ------------------------------------------------------------------------- |
| `--v-prefix` | Prefix the version with a `v` |

**Example:**

```shell
Expand Down
13 changes: 12 additions & 1 deletion cmd/gitsemver/gitsemver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var bumpCmd = &cobra.Command{
project := newProjectOrPanic(cmd)
versionFilenamesAndKeys := getVersionFilenamesAndKeysOrFail(cmd)
vPrefix := getVPrefixOrFail(cmd)
skipTag := getSkipTagOrFail(cmd)
username := getUsernameOrFail(cmd)
password := getPasswordOrFail(cmd)
latest := getLatestVersionOrFail(project)
Expand All @@ -36,7 +37,7 @@ var bumpCmd = &cobra.Command{
}
}

if err := project.Bump(versionFilenamesAndKeys, auth, vPrefix); err != nil {
if err := project.Bump(versionFilenamesAndKeys, auth, vPrefix, skipTag); err != nil {
log.Fatalln(err)
}

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

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

return vPrefix
}

func getSkipTagOrFail(cmd *cobra.Command) bool {
skipTag, err := cmd.Flags().GetBool("skip-tag")
if err != nil {
log.Fatalln(err)
}

return skipTag
}
18 changes: 11 additions & 7 deletions pkg/gitsemver/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (p *Project) NextVersionIncrement() (Increment, error) {
return increment, nil
}

func (p *Project) Bump(versionFilenamesAndKeys []string, auth AuthMethod, vPrefix bool) error {
func (p *Project) Bump(versionFilenamesAndKeys []string, auth AuthMethod, vPrefix, skipTag bool) error {
latest, err := p.LatestVersion()
if err != nil {
return err
Expand Down Expand Up @@ -227,15 +227,19 @@ func (p *Project) Bump(versionFilenamesAndKeys []string, auth AuthMethod, vPrefi
}
}

tagName := TagNameFromProjectAndVersion(p, next)
tagMessage := fmt.Sprintf("Release %s", tagName)
if !skipTag {
tagName := TagNameFromProjectAndVersion(p, next)
tagMessage := fmt.Sprintf("Release %s", tagName)

if err := git.CreateTag(p.Repo(), tagName, tagMessage); err != nil {
return err
if err := git.CreateTag(p.Repo(), tagName, tagMessage); err != nil {
return err
}
}

if err := git.PushToOrigin(p.Repo(), auth); err != nil {
return err
if !skipTag || len(versionFilenamesAndKeys) > 0 {
if err := git.PushToOrigin(p.Repo(), auth); err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit 6128fdb

Please sign in to comment.