diff --git a/.github/workflows/rust-check-version.yml b/.github/workflows/rust-check-version.yml index 046d795..c1f6041 100644 --- a/.github/workflows/rust-check-version.yml +++ b/.github/workflows/rust-check-version.yml @@ -63,11 +63,7 @@ jobs: )" >> $GITHUB_ENV - name: Check which version is greater - run: echo "GREATER_VER=$(./vergt.sh $VERSION $BEFORE_VERSION)" >> $GITHUB_ENV - - - name: Fail if current version is not greater - run: exit 1 - if: ${{ env.GREATER_VER != 1 }} + run: ./is_version_greater.sh $VERSION $BEFORE_VERSION cargo-build: name: Cargo build diff --git a/is_version_greater.sh b/is_version_greater.sh new file mode 100755 index 0000000..c0f2f02 --- /dev/null +++ b/is_version_greater.sh @@ -0,0 +1,31 @@ +#!/bin/bash +IFS=. +version=($1) +before_version=($2) +# starting from minor of version if version shorter before_version +# fill absent fields in version with zeros +for ((i=${#version[@]}; i<${#before_version[@]}; i++)) +do + version[i]=0 +done +# starting from major of version +for ((i=0; i<${#version[@]}; i++)) +do + if [[ -z ${before_version[i]} ]] + then + # if before_version shorter version then + # fill absent fields in before_version with zeros + ver2[i]=0 + fi + if ((10#${version[i]} > 10#${before_version[i]})) + then + # if version greater than before_version in most major differing field + exit 0 + fi + if ((10#${version[i]} < 10#${before_version[i]})) + then + # if version is not greater in most major differing field + exit 1 + fi +done +exit 1 \ No newline at end of file diff --git a/vergt.sh b/vergt.sh deleted file mode 100755 index 31ad55b..0000000 --- a/vergt.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -IFS=. -ver1=($1) -ver2=($2) -# starting from minor of ver1 if ver1 shorter ver2 -# fill absent fields in ver1 with zeros -for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) -do - ver1[i]=0 -done -# starting from major of ver1 -for ((i=0; i<${#ver1[@]}; i++)) -do - if [[ -z ${ver2[i]} ]] - then - # if ver2 shorter ver1 then - # fill absent fields in ver2 with zeros - ver2[i]=0 - fi - if ((10#${ver1[i]} > 10#${ver2[i]})) - then - # if ver1 greater than ver2 in most major differing field - echo 1 - exit - fi - if ((10#${ver1[i]} < 10#${ver2[i]})) - then - # if ver2 greater than ver1 in most major differing field - echo 2 - exit - fi -done -echo 0 -exit \ No newline at end of file