Skip to content

Instantly share code, notes, and snippets.

@cedricfarinazzo
Created September 12, 2019 14:15
Show Gist options
  • Save cedricfarinazzo/3d9badd728d11966c216a1eeee75ebfc to your computer and use it in GitHub Desktop.
Save cedricfarinazzo/3d9badd728d11966c216a1eeee75ebfc to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -ne 1 ]; then
exit 1
fi
git status > /dev/null
if [ $? -ne 0 ]; then
exit 1
fi
prefix="submission/"
suffix="-v"
last_version=""
for tag in $(git tag | grep "$prefix$1$suffix"); do
last_version="$tag"
done
echo "Subject: $1"
if [ -z "$last_version" ]; then
echo "No tags found"
echo "Version: 1.0"
user_choice=
while [ "$user_choice" != "y" ] && [ "$user_choice" != "n" ]; do
read -p 'Create it? [y/n]: ' user_choice
done
if [ "$user_choice" == "n" ]; then
exit 1
fi
echo "Create tag $prefix$1${suffix}1.0"
git tag -a "$prefix$1${suffix}1.0" -m"$1"
else
ver=$(echo "$last_version" | cut -d'-' -f2 | cut -d'v' -f2)
echo "last version: $ver"
maj_ver=$(echo "$ver" | cut -d'.' -f1)
min_ver=$(echo "$ver" | cut -d'.' -f2)
min_ver=$(($min_ver+1))
if [ $min_ver -eq 10 ]; then
min_ver=0
maj_ver=$(($maj_ver+1))
fi
new_ver="$maj_ver.$min_ver"
echo "Version: $new_ver"
user_choice=
while [ "$user_choice" != "y" ] && [ "$user_choice" != "n" ]; do
read -p 'Create it? [y/n]: ' user_choice
done
if [ "$user_choice" == "n" ]; then
exit 1
fi
echo "Create tag $prefix$1${suffix}$new_ver"
git tag -a "$prefix$1$suffix$new_ver" -m"$1"
fi
git status
exit 0
@cedricfarinazzo
Copy link
Author

cedricfarinazzo commented Sep 12, 2019

Usage: <tag_name>

It will create a new tag with the following format : submission/<tag_name>-v<major_version>.<minor_version>

If your git contains tags with submission/<tag_name>, this program will search the maximum version and increment it.
Otherwise, the version will be 1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment