Skip to content

Commit

Permalink
Rename -bump-to-next to -target and streamline implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdomke committed May 13, 2024
1 parent cf8b124 commit b56d2cf
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 140 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
## [6.9.0] - tbd
### Added
* New flag `-bump-to-next` that can be used to select which version component will be bumped
if version contains pre-release. Possible values are `patch` (default), `minor` and `major`.
* New flag `-target` that can be used to select to which component the version will be bumped to.
Possible values are `dev` (default), `patch`, `minor` and `major`. E.g.

$ git describe
v6.8.1-16-gcf8b124
$ git-semver -target minor
v6.9.0
* Added [devbox](https://www.jetpack.io/devbox/) configuration

### Changed
Expand Down
77 changes: 48 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/mdomke/git-semver/lint-and-test.yaml?branch=master)](https://github.com/mdomke/git-semver/actions?query=workflow%3Alint-and-test)
[![Codecov](https://codecov.io/gh/mdomke/git-semver/branch/master/graph/badge.svg)](https://codecov.io/gh/mdomke/git-semver)
![License](https://img.shields.io/github/license/mdomke/git-semver.svg)
![Tag](https://img.shields.io/github/tag/mdomke/git-semver.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/mdomke/git-semver)](https://goreportcard.com/report/github.com/mdomke/git-semver)
<p align="center">
<a href="https://github.com/mdomke/git-semver/actions?query=workflow%3Alint-and-test"><img src="https://img.shields.io/github/actions/workflow/status/mdomke/git-semver/lint-and-test.yaml?branch=master" /></a>
<a href="https://codecov.io/gh/mdomke/git-semver"><img src="https://codecov.io/gh/mdomke/git-semver/branch/master/graph/badge.svg" /></a>
<a href="LICENSE"><img src="https://img.shields.io/github/license/mdomke/git-semver.svg" /></a>
<img src="https://img.shields.io/github/tag/mdomke/git-semver.svg" />
<a href="https://goreportcard.com/report/github.com/mdomke/git-semver"><img src="https://goreportcard.com/badge/github.com/mdomke/git-semver" /></a>
</p>

# Semantic Versioning with git tags
# `git-semver`: Semantic Versioning with git tags

## What is this used for?

* CI/CD pipeline: Continuously version your artifacts and uniquely identify your dev-builds.
```console
$ APP_VERSION=$(git-semver)
```
* Tag releases: Automate your workflow for tagging releases of your software.
```console
$ git tag $(git-semver -target minor)
```

## Background

Software should be versioned in order to be able to identify a certain
feature set or to know when a specific bug has been fixed. It is a good
Expand Down Expand Up @@ -35,15 +50,15 @@ to attach a pre-release identifier to a version e.g. for a release candidate. Th
identifier is separated with hyphen from the core version component. A valid version
tag would be, e.g. `1.2.3`, `v2.3.0`, `1.1.0-rc3`.

```sh
```console
$ git tag v2.0.0-rc1
```

So for a tagged commit we would know which version to assign to our software, but
which version should we use for not tagged commits? We can use `git describe` to
get a unique identifier based on the last tagged commit.

```sh
```console
$ git describe --tags
3.5.1-22-gbaf822dd5
```
Expand All @@ -52,7 +67,7 @@ This is the 22nd commit after the tag `3.5.1` with the abbreviated commit hash `
Sadly this identifier has two drawbacks.

1. It's not compliant to SemVer, because there are multiple hyphens after the core version.
See the [BNF specifiction](https://github.com/semver/semver/blob/master/semver.md#backusnaur-form-grammar-for-valid-semver-versions)
See the [BNF specification](https://github.com/semver/semver/blob/master/semver.md#backusnaur-form-grammar-for-valid-semver-versions)

2. It doesn't allow proper sorting of versions, because the pre-release identifier would
make the version smaller than the tagged version, even though it has several commits build
Expand Down Expand Up @@ -111,12 +126,12 @@ The output and parsing of `git-semver` can be controlled with the following opti
| `-prefix` | Prefix string for version e.g.: v |
| `-set-meta` | Set buildmeta to this value |
| `-guard` | Ignore shorthand formats for pre-release versions |
| `-bump-to-next` | Bump `patch` (default), `minor` or `major` of pre-release versions |
| `-target` | Set target release `dev`(default), `patch`, `minor` or `major` |


#### Examples

```sh
```console
$ git-semver
3.5.2-dev.22+8eaec5d3

Expand All @@ -134,21 +149,25 @@ v3.5.2
$ git-semver -set-meta custom
3.5.2+custom

$ git-semver -bump-to-next minor
3.6.0-dev.22+8eaec5d3
$ git-semver -target minor
3.6.0

$ git-semver -bump-to-next major
4.0.0-dev.22+8eaec5d3
$ git-semver -target major
4.0.0
```

### Bumping versions

A common application of `git-semver` is to create new

### Release safeguard

If you use `git-semver` to automatically derive versions for your application and you
want to provide convenient shorthand versions (e.g. `1.2`), so that it is easier to follow
non-breaking updates, you might run into the problem that a pre-release version accidentally
overwrites a production version. This is because
If you use `git-semver` to automatically derive versions for your application (e.g. in a CI/CD
environment), and you want to provide convenient shorthand versions (e.g. `1.2`), so that it is
easier to follow non-breaking updates, you might run into the problem that a pre-release version
accidentally overwrites a production version. This is because

```sh
```console
# tag of HEAD commit: 1.2.2
$ git-semver -no-patch
1.2
Expand All @@ -162,7 +181,7 @@ result in the same shorthand version. To mitigate this problem you can use the `
that will ignore any output format that doesn't contain the pre-release identifier if the current
version is a pre-release version. E.g.

```sh
```console
# tag of HEAD commit: 1.2.3-dev.1"
$ git-semver -guard -no-patch
1.2.3-dev.1+8eaec5d3
Expand All @@ -174,7 +193,7 @@ If you create multiple annotated tags on the same commit (e.g. you want to promo
to be the final release without adding any further commits), `git-semver` will pick the tag that was
created last, which is usually what you want. E.g.

```sh
```console
$ git tag -a -m "Release candidate" 1.1.0-rc.1
$ git-semver
1.1.0-rc.1
Expand All @@ -185,15 +204,15 @@ $ git-semver

## Installation

Currently `git-semver` can be installed with `go install`
Currently, `git-semver` can be installed with `go install`

```sh
```console
$ go install github.com/mdomke/git-semver/v6@latest
```

There is also a [Homebrew](https://brew.sh/) formula that can be installed with

```sh
```console
$ brew install mdomke/git-semver/git-semver
```

Expand All @@ -202,12 +221,12 @@ $ brew install mdomke/git-semver/git-semver
You can also use `git-semver` as a docker-container. Images are available from [DockerHub][1] and
[GitHub Container Registry][2]

```sh
docker run --rm -v `pwd`:/git-semver mdomke/git-semver
```console
$ docker run --rm -v `pwd`:/git-semver mdomke/git-semver
```
or
```sh
docker run --rm -v `pwd`:/git-semver ghcr.io/mdomke/git-semver
```console
$ docker run --rm -v `pwd`:/git-semver ghcr.io/mdomke/git-semver
```

[1]: https://hub.docker.com/r/mdomke/git-semver
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/mdomke/git-semver/v6
go 1.20

require (
github.com/go-git/go-git/v5 v5.11.0
github.com/stretchr/testify v1.8.4
github.com/go-git/go-git/v5 v5.12.0
github.com/stretchr/testify v1.9.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -22,13 +22,13 @@ require (
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
Expand All @@ -21,13 +23,16 @@ github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcej
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4=
github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY=
github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys=
github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -50,14 +55,20 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand All @@ -70,6 +81,8 @@ golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
Expand All @@ -83,6 +96,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -102,6 +117,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
Expand Down Expand Up @@ -130,5 +147,6 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20 changes: 15 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
excludeMinor bool
guardRelease bool
matchPattern string
versionComp version.VersionComp
releaseTarget version.Target
args []string
stderr io.Writer
stdout io.Writer
Expand All @@ -35,7 +35,7 @@ func parseFlags(progname string, args []string) (*Config, string, error) {
cfg Config
)

cfg.versionComp = version.DefaultVersionComp
cfg.releaseTarget = version.DefaultTarget

flags := flag.NewFlagSet(progname, flag.ContinueOnError)
flags.SetOutput(&buf)
Expand All @@ -49,8 +49,17 @@ func parseFlags(progname string, args []string) (*Config, string, error) {
flags.BoolVar(&cfg.excludePatch, "no-patch", false, "exclude patch version (default: false)")
flags.BoolVar(&cfg.excludeMinor, "no-minor", false, "exclude pre-release version (default: false)")
flags.BoolVar(&cfg.excludePrefix, "no-prefix", false, "exclude version prefix (default: false)")
flags.BoolVar(&cfg.guardRelease, "guard", false, "ignore shorthand options if version contains pre-release (default: false)")
flags.Var(&cfg.versionComp, "bump-to-next", "set which version component (major, minor or patch) will be bumped if version contains pre-release (default: patch)")
flags.BoolVar(
&cfg.guardRelease,
"guard",
false,
"ignore shorthand options if version contains pre-release (default: false)",
)
flags.Var(
&cfg.releaseTarget,
"target",
"set release target (major, minor, patch or dev) to bump version to (default: dev)",
)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [opts] [<repo>]\n\nOptions:\n", progname)
flags.PrintDefaults()
Expand Down Expand Up @@ -108,6 +117,7 @@ func handle(cfg *Config, repoPath string) int {
fmt.Fprintln(cfg.stderr, err)
return 1
}
v = v.BumpTo(cfg.releaseTarget)
if cfg.setMeta != "" {
v.Meta = cfg.setMeta
}
Expand All @@ -117,7 +127,7 @@ func handle(cfg *Config, repoPath string) int {
if cfg.excludePrefix {
v.Prefix = ""
}
s, err := v.Format(selectFormat(cfg, v), cfg.versionComp)
s, err := v.Format(selectFormat(cfg, v))
if err != nil {
fmt.Fprintln(cfg.stderr, err)
return 1
Expand Down
4 changes: 4 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func TestParseFlags(t *testing.T) {
args: []string{"-set-meta", "finleap"},
cfg: &Config{setMeta: "finleap", args: []string{}},
},
{
args: []string{"-target", "minor"},
cfg: &Config{releaseTarget: version.Minor, args: []string{}},
},
{
args: []string{"-help"},
hasError: true,
Expand Down
Loading

0 comments on commit b56d2cf

Please sign in to comment.