mrt-version

mrt-version is a tool for managing the version information in a project. It keeps the version information in a header file, and provides a convenient way to update it and use the version with continuous integration tools.

Creating the header file

mrt-version main/version.h

This will create the header file, with the initial version set to 0.0.0.0

Note

‘yml’, ‘env’, ‘json’, and ‘h’ files are supported

/**
 * @file version.h
 * @author generated by mrt-version (https://mrt.readthedocs.io/en/latest/pages/mrtutils/mrt-version.html)
 * @brief version header
 * @date 05/01/21
 */

#define VERSION_MAJOR      0
#define VERSION_MINOR      0
#define VERSION_PATCH      0
#define VERSION_BUILD      0
#define VERSION_BRANCH     "master"
#define VERSION_COMMIT     "c4526b4ec43b9a74c572bfbb6059b65bce4b0029"

#define VERSION_STRING "0.0.0.0"

Note

To include repo information, call the tool from the root of the projects repo. when the branch is not ‘master’ an ‘*’ will be added to the end of VERSION_STRING. This makes it clear to the user/tester that they are not using an official build

Supported File Types

mrt-version can be used with several file types for different types of projects. The file type is automatically detected from the extension of the filename.

mrt-version version.env  # environment variable file
mrt-version version.h    # C header file
mrt-version version.json # JSON file
mrt-version version.yml  # YAML file

Updating the Version

After the initial file is created, you can set specific parts with the command line arguments (–major,–minor,–patch, –build). These values can be set to a value or incremented by a value. Minor and Patch can also be set to auto. auto will count the number of commits since the parent portion was last updated. i.e. If Patch is set to auto it will count the number of commits on the master branch since Minor was last updated, and use that count as the new value for Patch

mrt-version main/version.h --patch +1 --build 44
#define VERSION_MAJOR      0
#define VERSION_MINOR      0
#define VERSION_PATCH      1
#define VERSION_BUILD      44
#define VERSION_BRANCH     "master"
#define VERSION_COMMIT     "c4526b4ec43b9a74c572bfbb6059b65bce4b0029"

#define VERSION_STRING "0.0.1.44"

Note

Incrementing Minor will reset Patch to 0, and incrementing Major will reset Minor and Patch to 0.

Auto

Minor and Patch can also be set to auto. auto will count the number of commits since the parent portion was last updated. i.e. If Patch is set to auto it will count the number of commits on the master branch since Minor was last updated, and use that count as the new value for Patch

example:

../../_images/git_tree_auto.png
mrt-version inc/version.h --patch auto

This would change the version to v0.1.4 since there have been 4 commits to the master branch since the Minor was incremented at the v0.1.0 tag

Build System/Webhook integration

The tool will always output the version string so it can be easily used for other things such as git tags and documentation.

In this example patch is incremented by 1, and then the commit is tagged in the repo with the output (i.e. ‘v2.1.3’)

VERSION_STR=$(mrt-version main/version.h --patch +1 )
git tag -a $VERSION_STR -m "Adding Version Tag"

By default the output format is Majon.Minor.Patch, but it can be customized with the –format flag. It uses simple string substition and the available variables are $MAJOR, $MINOR, $PATCH, $BUILD , $BRANCH, and $HASH.

Future Improvements

The next step will be to have this tool generate and update changelog as the version is updated.