diff --git a/bin/create_release_tag.sh b/bin/create_release_tag.sh index d6aa135..e51cdd0 100755 --- a/bin/create_release_tag.sh +++ b/bin/create_release_tag.sh @@ -1,10 +1,17 @@ #!/bin/sh ENVIRONMENT=$1 +INCREMENT=$2 if [[ -z $ENVIRONMENT || ($ENVIRONMENT != "test" && $ENVIRONMENT != "prod") ]]; then echo "Please specify the environment as either 'prod' or 'test'." - echo "Example: ./bin/create_release_tag.sh test" + echo "Example: ./bin/create_release_tag.sh test patch" + exit 1 +fi + +if [[ -z $INCREMENT || ($INCREMENT != "major" && $INCREMENT != "minor" && $INCREMENT != "patch") ]]; then + echo "Please specify what to increment as either 'major', 'minor', or 'patch'." + echo "Example: ./bin/create_release_tag.sh test patch" exit 1 fi @@ -17,19 +24,39 @@ if [[ $? -ne 0 ]]; then fi # Get the latest tag -latest_tag=$(git describe --tags --abbrev=0) +if [[ $ENVIRONMENT == "prod" ]]; then + latest_tag=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | grep -v -- '-alpha' | sort -V | tail -n 1) +else + latest_tag=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*-alpha' | sort -V | tail -n 1) +fi echo "Latest tag: $latest_tag" -# Extract the version number from the latest tag -version=$(echo "$latest_tag" | sed -E 's/v([0-9]+\.[0-9]+\.[0-9]+).*/\1/') +# Check if latest_tag is empty +if [[ -z $latest_tag ]]; then + major=0 + minor=0 + patch=0 +else + # Extract the version number from the latest tag + version=$(echo "$latest_tag" | sed -E 's/v([0-9]+\.[0-9]+\.[0-9]+).*/\1/') -# Split the version into major, minor, and patch -major=$(echo $version | cut -d. -f1) -minor=$(echo $version | cut -d. -f2) -patch=$(echo $version | cut -d. -f3) + # Split the version into major, minor, and patch + major=$(echo $version | cut -d. -f1) + minor=$(echo $version | cut -d. -f2) + patch=$(echo $version | cut -d. -f3) +fi -# Increment the patch number -patch=$((patch + 1)) +# Increment the specified version part +if [[ $INCREMENT == "major" ]]; then + major=$((major + 1)) + minor=0 + patch=0 +elif [[ $INCREMENT == "minor" ]]; then + minor=$((minor + 1)) + patch=0 +elif [[ $INCREMENT == "patch" ]]; then + patch=$((patch + 1)) +fi # Join the major, minor, and patch into the new version new_version="$major.$minor.$patch"