-
Notifications
You must be signed in to change notification settings - Fork 6
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
NETOBSERV-2019: Make sure the required yq version is installed #140
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env bash | ||
|
||
set +u | ||
|
||
function check_dependencies() { | ||
echo "Checking dependencies... " | ||
|
||
LOCAL_YQ="/tmp/yq" | ||
if [ -x "$LOCAL_YQ" ]; then | ||
YQ_BIN=$LOCAL_YQ | ||
else | ||
# Check if yq is installed | ||
YQ_BIN=$(which yq 2>/dev/null) | ||
fi | ||
if [ -z "$YQ_BIN" ]; then | ||
echo "Error: 'yq' is not installed or not in PATH." | ||
install_yq "$2" | ||
return | ||
fi | ||
|
||
# Get the current version of yq | ||
current_yq_version=$("$YQ_BIN" --version | awk '{print $NF}') | ||
required_yq_version="$1" | ||
# Compare versions | ||
compare_versions "${current_yq_version#v}" "${required_yq_version#v}" | ||
|
||
if [ "$result" -eq 0 ]; then | ||
echo "Installing yq version $required_yq_version. Found version $current_yq_version." | ||
install_yq "$2" | ||
else | ||
echo "'yq' is up to date (version $current_yq_version)." | ||
fi | ||
} | ||
|
||
function compare_versions() { | ||
IFS="." read -r -a ver1 <<< "$1" | ||
IFS="." read -r -a ver2 <<< "$2" | ||
|
||
for ((i = 0; i < ${#ver1[@]} || i < ${#ver2[@]}; i++)); do | ||
v1=${ver1[i]:-0} # Default to 0 if unset | ||
v2=${ver2[i]:-0} | ||
if ((v1 < v2)); then | ||
result=0 # less than | ||
return | ||
elif ((v1 > v2)); then | ||
result=1 # greater than | ||
return | ||
fi | ||
done | ||
result=2 # equal | ||
} | ||
|
||
function install_yq() { | ||
OS=$(uname | tr '[:upper:]' '[:lower:]') # Get the OS type (linux or darwin) | ||
supported_archs="$1" | ||
YQ_BIN="$LOCAL_YQ" | ||
for arch in $supported_archs; do | ||
echo "Attempting to download yq version $required_yq_version for $OS/$arch..." | ||
DOWNLOAD_URL="https://github.com/mikefarah/yq/releases/download/$required_yq_version/yq_${OS}_${arch}" | ||
if curl -Lo "$YQ_BIN" "$DOWNLOAD_URL" && chmod +x "$YQ_BIN" | ||
then | ||
echo "Successfully downloaded and installed yq version $required_yq_version for $arch." | ||
return | ||
else | ||
echo "Error: Failed to download yq version $required_yq_version for $arch." | ||
fi | ||
done | ||
|
||
echo "Error: Unable to install 'yq' for any of the supported architectures." | ||
exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msherif1234 - qq , where do you set the required version here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its passed as an arg in the Makefile https://github.com/netobserv/network-observability-cli/pull/140/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R158
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see it, the YQ_VERSION env var value already exists in main.