Package: tbump
tbump: bump software releasestbump helps you bump the version of your project easily.NoteThis project was originally hosted on theTankerHQorganization, which was my employer from 2016
to 2021. They kindly agreed to give me back ownership of this project. Thanks!InstallationThe recommended way to installtbumpis to usepipxMake sure to have Python3.7or later installed.InstallpipxRunpipx install tbump.tbumpis also available onpypiand can be installed withpipif you know what you are doing.ScreenshotHere’s what a typical usage oftbumplooks like:$tbump5.0.5:: Bumping from 5.0.4 to 5.0.5
=> Would patch these files
- setup.py:14 version="5.0.4",
+ setup.py:14 version="5.0.5",
- tbump.toml:2 current = "5.0.4"
+ tbump.toml:2 current = "5.0.5"
=> Would run these hooks before commit
* (1/2) $ ./test.sh
* (2/2) $ grep -q -F 5.0.5 Changelog.rst
=> Would run these git commands
 * git add --update
 * git commit --message Bump to 5.0.5
 * git tag --annotate --message v5.0.5 v5.0.5
 * git push origin master
 * git push origin v5.0.5
=> Would run these hooks after push
* (1/1) $ ./publish.sh
:: Looking good? (y/N)
y
=> Patching files
...
=> Running hooks before commit
...
=> Making bump commit and push matching tags
...
=> Running hooks after push
...
Done ✓UsageFirst, runtbump init <current_version>, wherecurrent_versionis the current version of your program. This will create atbump.tomlfile looking like this:[version]current="1.2.41"regex='''(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'''[git]message_template="Bump to {new_version}"tag_template="v{new_version}"[[file]]src="setup.py"NoteThe file usestoml syntax.Strings should be templated using curly brackets, to be used with
Python’s built-in.format()method.Paths may contain unix-styleglobs, e.g.src ="a/**/script.?s"matches botha/b/script.jsanda/b/c/script.ts.The version regular expression will be used inverbose modeand can
contain named groups (see below).tbump will also look for a[tool.tbump]section in thepyproject.tomlfile if its exists. You can usetbump initwith
the--pyprojectoption to append the configuration in this file
instead of creating a new file.Then run:$tbump1.2.42tbumpwill:Replace the string1.2.41by1.2.42in every file listed in the
configurationMake a commit based on themessage_template.Make anannotatedtag based on thetag_templatePush the current branch and the tag.Note that by default,tbumpwill display all the changes and stop to ask if they are correct before performing any action, allowing you to abort and re-try the bump if something is not right.
You can use--non-interactiveto disable this behavior.If you only want to bump the files without performing any git actions or running the hook commands, use the--only-patchoption.The current version of the project can be found using the command:$tbumpcurrent-versionAdvanced configurationCommand-line optionsSee:tbump --helpRestricting the lines that are replacedSometimes you want to make sure only the line matching a given pattern is replaced. For instance, with the followingpackage.json:/* in package.json */{"name":"foo","version":"0.42","dependencies":{"some-dep":"0.42","other-dep":"1.3",}}you’ll want to make sure that when you bump from0.42to0.43, that the line containingsome-depdoes not change.In this case, you can set asearchoption in thefilesection:# In tbump.toml[[file]]src="package.json"search='"version": "{current_version}"'Note that the search string is actually a full regular expression, except for the{current_version}marker which is substituted as plain text.Using a custom version templateIf you are using a version schema like1.2.3-alpha-4, you may want to expose a variable that only contains the “public” part of the version string. (1.2.3in this case).To do so, add aversion_templateoption in thefilesection. The names used in the format string should match the group names in the regular expression./* in version.js */exportFULL_VERSION='1.2.3-alpha-4';exportPUBLIC_VERSION='1.2.3';[[file]]src="version.js"version_template="{major}.{minor}.{patch}"search="export PUBLIC_VERSION = '{current_version}'"[[file]]src="version.js"search="export FULL_VERSION = '{current_version}'"Running commands before commitYou can specify a list of hooks to be run after the file have changed, but before the commit is made and pushed.This is useful if some of the files under version control are generated through an external program.Here’s an example:[[before_commit]]name="Check Changelog"cmd="grep -q -F {new_version} Changelog.rst"The name is mandatory. The command will be executed via the shell, after the{new_version}placeholder is replaced with the new version.Any hook that fails will interrupt the bump. You may want to rungit reset--hardbefore trying again to undo the changes made in the files.Running commands after pushYou can specify a list of hooks to be run right after the tag has been pushed, using an[[after_push]]section.This is useful if you need the command to run on a clean repository, without un-committed changes, for instance to publishrustpackages:[[after_push]]name="Publish to crates.io"cmd="cargo publish"Setting default values for version fields(Added in 6.6.0)If you have aversion_templatethat includes fields that don’t always have a match
(e.g. prerelease info),
you can set a default value to use instead ofNone,
which would raise an error.For example:[version]current="1.2.3"regex="""(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<extra>.+))?"""[[file]]src="version.py"version_template='({major}, {minor}, {patch}, "{extra}")'search="version_info = {current_version}"[[field]]# the name of the fieldname="extra"# the default value to use, if there is no matchdefault=""Working with git providers that don’t support –atomicIf the push destination does not support--atomic,
addatomic_push=falseto the config file,
under the[git]section:..code-block:: ini[git]
atomic_push = false