From 54ecf9931d9db137e0e0afd2a50964be547b8900 Mon Sep 17 00:00:00 2001 From: Jonathan Prado Date: Sat, 16 Nov 2024 20:50:17 +0100 Subject: [PATCH] fix: issue/1 entrypoint.sh --- entrypoint.sh | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index fe4c4d7..ca4ebbf 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,31 +4,19 @@ COMMIT_MSG=$1 VERSION=$2 -# Validate inputs -if [[ -z "$COMMIT_MSG" || -z "$VERSION" ]]; then - echo "Error: COMMIT_MSG or VERSION is not provided." - exit 1 -fi - -# Validate version format -if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Error: VERSION must follow X.Y.Z format" - exit 1 -fi - -# Split version into X, Y, Z -IFS='.' read -r X Y Z <<< "$VERSION" -base_version="$X.$Y.$Z" +# Make some vars to manipulate each part of a full version (X.Y.Z) +X=$(echo $VERSION|cut -d. -f1) +Y=$(echo $VERSION|cut -d. -f2) +Z=$(echo $VERSION|cut -d. -f3) +base_version=$(echo $X.$Y.$Z) +cusotm_version=$(echo $COMMIT_MSG|cut -d':' -f1) -# Determine new version based on commit message -if [[ "$COMMIT_MSG" =~ ^(major:|breaking:|release:|big-feature:) ]]; then - # Increment major version +# Create new version using type (major,minor,patch,beta,none) +if [[ "$COMMIT_MSG" =~ ^(major:|breaking:|release:|big-feature:) ]]; then NewVersion=$(($X+1)).0.0 elif [[ "$COMMIT_MSG" =~ ^(minor:|enhancement:|update:|feature:) ]]; then - # Increment minor version NewVersion=$X.$(($Y+1)).0 -elif [[ "$COMMIT_MSG" =~ ^(patch:|fix:) ]]; then - # Increment patch version +elif [[ "$COMMIT_MSG" =~ (fix:|patch:) ]]; then NewVersion=$X.$Y.$(($Z+1)) elif [[ "$COMMIT_MSG" =~ ^test: ]]; then # Generate test version string @@ -43,7 +31,6 @@ else NewVersion="$base_version-$custom_version" fi -# Output results echo "COMMIT MSG: $COMMIT_MSG" echo "OLD VERSION: $VERSION" echo "NEW_VERSION: $NewVersion"