You would like to automatically and programmatically find the next suitable version number for a release in Git.
#!/bin/bash
latest=$(git tag -l | sort -V | tail -n1)
semver_parts=(${latest//./ })
major=${semver_parts[0]}
minor=${semver_parts[1]}
patch=${semver_parts[2]}
patch_version=${major}.${minor}.$((patch+1))
minor_version=${major}.$((minor+1)).0
major_version=$((major+1)).0.0
echo "latest: $latest"
echo "patch release: $patch_version"
echo "minor release: $minor_version"
echo "major release: $major_version"
Issue:
You would like to automatically and programmatically find the next suitable version number for a release in Git.
Prerequisites:
You are working by semantic versioning principles.
Solution:
Save and execute the provided snippet into your terminal.