Skip to content

Commit

Permalink
Formatting fixes for semver.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Nov 1, 2023
1 parent 0868075 commit 94267a5
Showing 1 changed file with 80 additions and 81 deletions.
161 changes: 80 additions & 81 deletions scripts/semver.sh
Original file line number Diff line number Diff line change
@@ -1,108 +1,107 @@
#!/usr/bin/env bash

# https://github.com/cloudflare/semver_bash/blob/master/semver.sh
# Source: https://github.com/cloudflare/semver_bash/blob/master/semver.sh

function semverParseInto() {
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
#MAJOR
eval $2=`echo $1 | sed -e "s#$RE#\1#"`
#MINOR
eval $3=`echo $1 | sed -e "s#$RE#\2#"`
#MINOR
eval $4=`echo $1 | sed -e "s#$RE#\3#"`
#SPECIAL
eval $5=`echo $1 | sed -e "s#$RE#\4#"`
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
#MAJOR
eval $2=$(echo $1 | sed -e "s#$RE#\1#")
#MINOR
eval $3=$(echo $1 | sed -e "s#$RE#\2#")
#MINOR
eval $4=$(echo $1 | sed -e "s#$RE#\3#")
#SPECIAL
eval $5=$(echo $1 | sed -e "s#$RE#\4#")
}

function semverEQ() {
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0

local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0
local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0

semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B
semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B

if [ $MAJOR_A -ne $MAJOR_B ]; then
return 1
fi

if [ $MINOR_A -ne $MINOR_B ]; then
return 1
fi
if [ $MAJOR_A -ne $MAJOR_B ]; then
return 1
fi

if [ $PATCH_A -ne $PATCH_B ]; then
return 1
fi
if [ $MINOR_A -ne $MINOR_B ]; then
return 1
fi

if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then
return 1
fi
if [ $PATCH_A -ne $PATCH_B ]; then
return 1
fi

if [[ "_$SPECIAL_A" != "_$SPECIAL_B" ]]; then
return 1
fi

return 0
return 0

}

function semverLT() {
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0

local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0

semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B

if [ $MAJOR_A -lt $MAJOR_B ]; then
return 0
fi

if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then
return 0
fi

if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then
return 0
fi

if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
return 1
fi
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]] ; then
return 1
fi
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]] ; then
return 0
fi

if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then
return 0
fi
local MAJOR_A=0
local MINOR_A=0
local PATCH_A=0
local SPECIAL_A=0

local MAJOR_B=0
local MINOR_B=0
local PATCH_B=0
local SPECIAL_B=0

semverParseInto $1 MAJOR_A MINOR_A PATCH_A SPECIAL_A
semverParseInto $2 MAJOR_B MINOR_B PATCH_B SPECIAL_B

if [ $MAJOR_A -lt $MAJOR_B ]; then
return 0
fi

if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -lt $MINOR_B ]]; then
return 0
fi

if [[ $MAJOR_A -le $MAJOR_B && $MINOR_A -le $MINOR_B && $PATCH_A -lt $PATCH_B ]]; then
return 0
fi

if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then
return 1
fi
if [[ "_$SPECIAL_A" == "_" ]] && [[ "_$SPECIAL_B" != "_" ]]; then
return 1
fi
if [[ "_$SPECIAL_A" != "_" ]] && [[ "_$SPECIAL_B" == "_" ]]; then
return 0
fi

if [[ "_$SPECIAL_A" < "_$SPECIAL_B" ]]; then
return 0
fi

return 1

}

function semverGT() {
semverEQ $1 $2
local EQ=$?
semverEQ $1 $2
local EQ=$?

semverLT $1 $2
local LT=$?
semverLT $1 $2
local LT=$?

if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then
return 0
else
return 1
fi
if [ $EQ -ne 0 ] && [ $LT -ne 0 ]; then
return 0
else
return 1
fi
}

0 comments on commit 94267a5

Please sign in to comment.