A dead simple CLI tool that prints the next semantic version based on the last tag of your git repository
go install github.com/junk1tm/nextver@latest
brew install junk1tm/tap/nextver
Download a prebuilt binary from the Releases page.
nextver
supports major
, minor
and patch
commands:
> git tag
1.2.3
> nextver major
2.0.0
> nextver minor
1.3.0
> nextver patch
1.2.4
nextver
expects an initiated git
repository with tags following the semantic versioning specification,
invalid tags are ignored:
> git tag
a.b.c
1.2.3.4
> nextver -verbose patch
nextver: skipping "a.b.c": invalid semantic version format
nextver: skipping "1.2.3.4": invalid semantic version format
nextver: no valid semantic version has been found
nextver
is designed to be used with git tag
command:
git tag $(nextver patch)
so the only thing it writes to stdout
is the next version, everything else, including usage, errors and additional
information, goes to stderr
. If anything goes wrong, e.g., no git
repository is found, nextver
won't
touch stdout
at all, so the command above will be resolved to git tag
, which simply prints the existing git
tags.
Therefore, accidentally creating an invalid tag is unlikely.
The -prefix
flag allows defining a prefix for tags. If set, nextver
ignores tags without this prefix and prints the
next version prefixed.
A common practice is to prefix semver
tags with v
:
> git tag
v1.2.3
> nextver -prefix=v patch
v1.2.4
Another use case is working with go submodules, which requires submodule's tags to be prefixed:
> tree mainmodule
mainmodule
├── go.mod
└── submodule
└── go.mod
1 directory, 2 files
> cd mainmodule && git tag
0.1.0
submodule/0.1.1
> nextver -prefix=submodule/ patch
submodule/0.1.2
> nextver -help
usage: nextver [flags] <command>
available commands:
major
print the next major version
minor
print the next minor version
patch
print the next patch version
available flags:
-p string
shorthand for -prefix
-prefix string
consider only prefixed tags (also, will be used to print the result)
-v
shorthand for -verbose
-verbose
print additional information to stderr
-version
print the app version