Created
July 23, 2024 11:45
-
-
Save guilhermeprokisch/5036659c0148dd30138f6e2ad57b9aa3 to your computer and use it in GitHub Desktop.
update patch version for .tools-version
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
#!/bin/bash | |
get_latest_patch_version() { | |
local plugin=$1 | |
local current_version=$2 | |
local major_minor=$(echo $current_version | cut -d. -f1-2) | |
local latest_patch=$(asdf list-all $plugin | grep "^$major_minor\." | sort -V | tail -n1) | |
echo $latest_patch | |
} | |
# Check if .tool-versions file exists | |
if [ ! -f ".tool-versions" ]; then | |
echo "Error: .tool-versions file not found in the current directory." | |
exit 1 | |
fi | |
# Read the .tool-versions file | |
while IFS=' ' read -r plugin version || [[ -n "$plugin" ]]; do | |
# Skip empty lines | |
if [ -z "$plugin" ]; then | |
continue | |
fi | |
echo "Checking $plugin..." | |
# Get the latest patch version | |
latest_patch_version=$(get_latest_patch_version $plugin $version) | |
# Compare versions | |
if [ "$version" != "$latest_patch_version" ]; then | |
echo "Updating $plugin from $version to $latest_patch_version" | |
# Update the version in .tool-versions file | |
sed -i.tmp "s/^$plugin .*/$plugin $latest_patch_version/" .tool-versions | |
rm .tool-versions.tmp # Remove temporary file created by sed on macOS | |
echo "Updated .tool-versions file for $plugin" | |
else | |
echo "$plugin is already at the latest patch version ($version)" | |
fi | |
echo "-------------------" | |
done <.tool-versions | |
echo "All tools in .tool-versions have been checked and the file has been updated with the latest patch versions if necessary." | |
echo "Please run 'asdf install' to install the new versions specified in .tool-versions" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment