Skip to content

Commit

Permalink
fix: checking version was too strict (#92)
Browse files Browse the repository at this point in the history
* fix: checking version was too strict

check_version now doesn't fail when `tool` has version `0.X` and `threshold` is set to `0.X.0`

* fix: checking subversion failed

As @LangLangBart suggested a tool with version "1"
would pass the check against version "1.0"
but not against "1.0.0".

It now works for whatever subversion

NOTE: code is also cleaner

* fix: remove redundant command in version check

---------

Co-authored-by: lnk3 <lukelr2000@gmail.com>
Co-authored-by: LangLangBart <92653266+LangLangBart@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 1, 2024
1 parent 0fcafa6 commit 556df2e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions gh-notify
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,20 @@ select_notif() {
# This function validates the version of a tool.
check_version() {
local tool=$1 threshold=$2 on_error=${3:-die}
local user_version
local user_version user_version_part index
declare -a ver_parts threshold_parts
user_version=$(command $tool --version 2>&1 |
command command grep --color=never --extended-regexp --only-matching --regexp='[0-9]+(\.[0-9]+)*' |
command grep --color=never --extended-regexp --only-matching --regexp='[0-9]+(\.[0-9]+)*' |
command sed q)

IFS='.' read -ra ver_parts <<<"$user_version"
IFS='.' read -ra threshold_parts <<<"$threshold"

for i in "${!threshold_parts[@]}"; do
if ((i >= ${#ver_parts[@]})) || ((ver_parts[i] < threshold_parts[i])); then
for index in "${!threshold_parts[@]}"; do
user_version_part=${ver_parts[index]:-0}
if ((user_version_part < threshold_parts[index])); then
$on_error "Your '$tool' version '$user_version' is insufficient. The minimum required version is '$threshold'."
elif ((ver_parts[i] > threshold_parts[i])); then
elif ((user_version_part > threshold_parts[index])); then
break
fi
done
Expand Down

0 comments on commit 556df2e

Please sign in to comment.