Skip to content

Commit

Permalink
improve dependency_age.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
lepapareil committed Jul 3, 2021
1 parent fb90827 commit 72798dc
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions ci/dependency_age.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,43 @@
exit_code=0
color_red=$(echo -ne "\033[1;31m")
color_green=$(echo -ne "\033[1;32m")
color_yellow=$(echo -ne "\033[1;33m")
color_blue=$(echo -ne "\033[1;34m")
color_reset=$(echo -ne "\033[0m")

for package in packages/* ; do
echo -e "\n=> dependency age for ${package}\n"
while read -r dependency actual_version ; do
last_version=$(curl -I "https://docs.rs/${dependency}" 2>&1 | grep -i "location:" | cut --delimiter "/" --field 5 | grep -E "^[0-9].*.[0-9].*.[0-9]$")
last_version=$(curl --head "https://docs.rs/${dependency}" 2>&1 | grep --ignore-case "location:" | cut --delimiter "/" --field 5 | grep --extended-regexp "^[0-9].*.[0-9].*.[0-9]$")
if [ -z "${last_version}" ] ; then
echo "${color_red}runtime error${color_reset}, i could not get last version from https://docs.rs/${dependency}"
exit 1
fi

echo -n " ${dependency} ${actual_version}: "
newest_version=$(echo -e "${last_version}\n${actual_version}" | sort -V | tail -1)
newest_version=$(echo -e "${last_version}\n${actual_version}" | sort --version-sort | tail -1)
if [ "${newest_version}" == "${actual_version}" ] ; then
echo "${color_green}newest${color_reset}"
if [ "$1" = "--update" ] ; then
echo "${color_green}newest, nothing to update${color_reset}"
else
echo "${color_green}newest${color_reset}"
fi
else
if [ "$1" = "--update" ] ; then
sed -i "s/${dependency} = \"${actual_version}\"/${dependency} = \"${last_version}\"/g" "${package}/Cargo.toml"
echo "${color_blue}old, updated to ${last_version}${color_reset}"
else
if [ "$1" = "--update" ] ; then
sed --in-place "s/${dependency}.*=.*\"${actual_version}\"/${dependency} = \"${last_version}\"/g" "${package}/Cargo.toml"
grep --silent "${dependency} = \"${last_version}\"" "${package}/Cargo.toml" && \
echo "${color_blue}old, updated to ${last_version}${color_reset}" || \
echo "${color_red}error, update to ${last_version} fails, please check ${package}/Cargo.toml format and syntax${color_reset}"
else
echo "${color_red}old, please update to latest ${last_version}${color_reset}"
fi
((exit_code++))
((exit_code++))
fi

done < <(sed -n "/dependencies\]/,/^$/p" "${package}/Cargo.toml" | grep -Ev "\[|path|^$" | tr -d '" ' | tr '=' ' ')
done < <(sed --silent "/dependencies\]/,/^$/p" "${package}/Cargo.toml" | grep --extended-regexp --invert-match "\[|path|^$" | tr --delete '" ' | tr '=' ' ')
done

if [ "$1" != "--update" ] && [ "${exit_code}" -gt 0 ] ; then
echo -e "\n${color_yellow}...Consider executing \"dependency_age.sh --update\" to automatically update ${exit_code} old dependencies on your Cargo.toml files${color_reset}"
fi
exit $exit_code

0 comments on commit 72798dc

Please sign in to comment.