# go-bumpver _Inspired by the python bump2version tool._ bumpver - print the next semantec version in a given sequence ## Usage ```bash bumpver part [major|minor|patch] [flags] file [-|file] ``` ## Why? - Most version bumpers are fairly tightly coupled to git - Make commits for you - Few have useful pre release mechanisms - Lack of simple interfaces - Lack of unix philosophy ## How? `go-bumpver` takes the sequence of version(s) from a file or stdin and prints the next version. It drops invalid versions in the sequence and only uses valid ones. It does not make a tag or change any state in git or any other VCS, it only prints the next version. It also has the ability to bump pre-release tags using simple formating string. ### Inputs **stdin** ```bash ❯ echo "1.1.1\n1.2.1" | bumpver patch - 1.2.2 ``` **file** ```bash ❯ echo v0.1.0 > VERSION ❯ bumpver patch VERSION 0.1.1 ``` **local repo** ```bash ❯ bumpver patch <(git tag -l) 3.3.2 ``` **remote repo** ```bash ❯ bumpver patch <(git ls-remote --tags --refs origin v\* | awk -F'[ /]' '{ print $NF }') 3.3.4 ``` **bump tags released along a branch** This example supports software that has support for multiple versions at once. E.g. version 2.X is still supported but 3.X is based off of main. ```bash ❯ bumpver patch <(git tag --merged ) 2.1.4 ``` ### Bumps **a patch** ```bash ❯ bumpver patch <(git tag -l) 3.3.2 ``` **a minor** ```bash ❯ bumpver minor <(git tag -l) 3.4.0 ``` **a major** ```bash ❯ bumpver major <(git tag -l) 4.0.0 ``` ***prior version*** Getting the last version could be useful for generating diffs, release notes etc. ``` ❯ bumpver major --last-version <(git tag -l) 3.8.1 ❯ bumpver major <(git tag -l) 4.0.0 ``` ### Pre-release Pre-releases can be formatted in a way that can be easily bumped. Providing `--prerelease` will generate a new prerelease for the given bump. Meaning if you use `major --prerelease` with the last version 1.2.2 will give `2.0.0-RC.0`. Use Case: - A Pull Request/Merge Request is opened. A tag needs to be generated for the PR/MR. - Bumping release candidates for testing. #### Format Strings - `$BumpInt`: increases the integer value. - `$KeyArg `: Value of the key from `key-args` option #### $BumpInit Consider the following format string: `rc.$BumpInt` ```bash ❯ echo "0.1.0-rc.1" | bumpver patch --prerelease --prerelease-fmt 'rc.$BumpInt' - 0.1.0-rc.2 ``` A none existant pre-release yields ```bash ❯ echo "0.1.0" | bumpver patch --prerelease --prerelease-fmt 'rc.$BumpInt' - 0.1.1-rc.0 ``` #### $KeyArg `$KeyArg` allows for run time side effects on prerelease versions. This means you can bump ain integer or provide key word argument. Examples: - add the PR/MR number to the version - add metadata for the version ```bash ❯ bumpver patch --prerelease --prerelease-fmt 'rc.$KeyArg PR_NUM.$BumpInt' --key-args PR_NUM=44 vers.txt 1.2.2-rc.44.0 ```