Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compare version #32

Merged
merged 1 commit into from
Aug 21, 2024
Merged

fix: compare version #32

merged 1 commit into from
Aug 21, 2024

Conversation

karrybit
Copy link
Contributor

@karrybit karrybit commented Jun 25, 2024

fixed bug to compare version.

Minimum reproduction code is below.

#!/bin/bash

function compare_old() {
  input_version=$1
  if [[ "$input_version" < "v0.64.0" ]]; then
    echo "Error: runn version $input_version is not supported. Please use v0.64.0 or higher."
    return
  fi

  echo "Success"
}

function compare_new() {
  input_version=$(echo "$1" | sed 's/^v//')
  compatible_version=$(echo "v0.64.0" | sed 's/^v//')

  IFS='.' read -r -a splitted_input_version <<< "$input_version"
  IFS='.' read -r -a splitted_compatible_version <<< "$compatible_version"

  for i in {0..2}; do
    if [[ ! ${splitted_input_version[i]} =~ ^[0-9]+$ ]]; then
      echo "Error: $input_version is invalid version."
      return
    fi

    if ((10#${splitted_input_version[i]} < 10#${splitted_compatible_version[i]})); then
      echo "Error: runn version $input_version is not supported. Please use $compatible_version or higher."
      return
    fi
  done
  echo "Success"
}

compare_old v0.113.2
compare_new v0.113.2
❯ ./compare_version.sh
Error: runn version v0.113.2 is not supported. Please use v0.64.0 or higher.
Success

see: #31

@k2tzumi
Copy link
Owner

k2tzumi commented Aug 21, 2024

@karrybit Thank you!! NICE!!

@k2tzumi k2tzumi merged commit ddaad3c into k2tzumi:main Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants