aboutsummaryrefslogtreecommitdiff

go-bumpver

Inspired by the python bump2version tool.

bumpver - print the next semantec version in a given sequence

Usage

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

echo "1.1.1\n1.2.1" | bumpver patch -
1.2.2

file

echo v0.1.0 > VERSION
❯ bumpver patch VERSION
0.1.1

local repo

❯ bumpver patch <(git tag -l)
3.3.2

remote repo

❯ 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.

❯ bumpver patch <(git tag --merged <release branch name>)
2.1.4

Bumps

a patch

❯ bumpver patch <(git tag -l)
3.3.2

a minor

❯ bumpver minor <(git tag -l)
3.4.0

a major

❯ 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 <KEY NAME>: Value of the key from key-args option

$BumpInit

Consider the following format string: rc.$BumpInt

echo "0.1.0-rc.1" | bumpver patch --prerelease --prerelease-fmt 'rc.$BumpInt' -
0.1.0-rc.2

A none existant pre-release yields

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 an integer or provide key word argument. Example use cases:

  • add the PR/MR number to the version
  • add metadata for the version
❯ bumpver patch --prerelease --prerelease-fmt 'rc.$KeyArg PR_NUM.$BumpInt' --key-args PR_NUM=44 vers.txt
1.2.2-rc.44.0

❯ bumpver patch --prerelease --prerelease-fmt 'rc.$KeyArg USER_NAME.$BumpInt' --key-args USER_NAME=grumps vers.txt
1.2.2-rc.grumps.0