# README
gitver
-
Simple CLI for semantic versioning
-
Controls version following SemVer spec
-
Automatically push tag versions to Git (require a clean git repository without any pending changes)
-
Possibility to add prefixes to git tags (useful for monorepos to differentiate tags from multiple projects)
Plenty of examples at the end of this document.
Installation
go install github.com/bira37/gitver
Usage
Flags
-config string
config: location of the config file. If not provided, try to find in current dir. Config file has priority over directory flag (default "./gitver.json")
-i string
increment mode: the increment type. valid inputs: major | minor | patch
-l string
label: sets a prefix label only on the git tag (useful for monorepos to differentiate tags from multiple projects)
-p string
prerelease: sets a prerelease suffix
-r release: removes prerelease suffix. Overrides prerelease option
How it works
First of all, you must commit every pending change inside the repo before. If git repository is not clean, the command will fail. You need to have at least one tag created in your git repo (such as 0.0.0
). For example, running gitver -i major -p beta -l myapp
will do the following:
- Create a tag for the latest commit with identifier
myapp-1.0.0-beta
(shown below)
commit 5274c3b2106de103286cad08f5979602effab997 (HEAD -> test, tag: myapp-1.0.0-beta)
Author: Ubiratan Neto <[email protected]>
Date: Wed Oct 18 20:35:29 2023 -0300
"my last commit"
Examples
-
gitver -i major
with latest version as0.0.0
:- TAG created as
1.0.0
- TAG created as
-
gitver -i patch
with latest version as1.0.0
:- TAG created as
1.0.1
- TAG created as
-
gitver -i minor -p beta
with latest version as3.0.2
:- TAG created as
3.1.0-beta
- TAG created as
-
gitver -l service-a -i minor
with latest tag forservice-a
asservice-a-1.2.0
:- TAG created as
service-a-1.3.0
- Note: This way, you are allowed to manage versioning across multiple services/packages/libs within a monorepo individually
- TAG created as
-
gitver -l mylib -i major -p beta
with latest tag formylib
asmylib-2.5.2
:- TAG created as
mylib-3.0.0-beta
- TAG created as
Configs
There are some other changes you can make to the tag generation flow using a gitver.json
file, the complete JSON is shown below:
{
"allowedLabels": ["mylib"],
"allowedBranches": ["main"]
}
allowedLabels
only allows labels specified on config file. Allow everything if not passedallowedBranches
only allows tag generation on specified branches. Allow every branch if not passed