Skip to content

Instantly share code, notes, and snippets.

@friek
Created January 8, 2024 13:42
Show Gist options
  • Save friek/ff363be1e6c5a9fd3edb333c88391699 to your computer and use it in GitHub Desktop.
Save friek/ff363be1e6c5a9fd3edb333c88391699 to your computer and use it in GitHub Desktop.
Check if a version is the latest git tag version
#!/bin/sh
# Check if the passed version is greater than the versions registered in the git tags
# Uses sort -V from GNU sort to sort versions and assumes git tags in
# semver format v<major>.<minor>.<patch>
check_version="$1"
if [ -z "$check_version" ]; then
# Assume it's not the latest version
echo "No version specified. Usage: $0 <version>"
echo "Example: $0 v1.1.0 -> checks if v1.1.0 is greater than the versions in the git tags"
exit 1
fi
set -e
latest_in_tags=`( echo $check_version ; git tag ) | grep v | sort -r -V | head -1`
if [ "$latest_in_tags" != "$check_version" ]; then
echo "Version $check_version is not the latest version"
exit 1
fi
echo "Version $check_version is the latest version"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment