Tips & Tricks Tips & Tricks How to manage your releases using git-semver?

Short answer

This way of managing releases requires git-semver and an initial semantic version git tag. You can install git-semver by running pip install -U git-semver.

Generate a new version number

Choose one of the following, depending which kind of version you're releasing:

# next patch: 1.4.2 -> 1.4.3
VERSION=`git semver --next-patch`

# next minor: 1.4.2 -> 1.5.0
VERSION=`git semver --next-minor`

# next major: 1.4.2 -> 2.0.0
VERSION=`git semver --next-major`

Update your version file with the new version number (optional)

  • Using a version.txt file:

    echo $VERSION > version.txt
    
  • Using a package.json file (node.js):

    cp package.json package.json.bak
    sed 's/"version": ".*",/"version": "'$VERSION'",/g' package.json.bak > package.json
    

Run your tests before publishing the new release (optional, but you should)

This step depends on your project, I usually run the following for my python projects:

# exit our virtualenv
deactivate

# run a full clean build including deps install
make clean install lint test doc

Create the git release

git add version.txt package.json
git commit -m "release: $VERSION"
git tag -am $VERSION $VERSION
git push origin master --tags

Publish to PyPI (python only)

  • First time, you need to register the package:

    python setup.py register
    
  • Then, you can build your eggs/wheels running:

python setup.py sdist bdist bdist_egg bdist_wheel
  • Then, you can publish it to PyPI (includes the egg/wheel build too):

    python setup.py sdist bdist bdist_egg bdist_wheel upload
    

Share the love!

Liked this article? Please consider sharing it on your favorite network, it really helps me a lot!

You can also add your valuable insights by commenting below.