Skip to content

Commit

Permalink
Toolcache: Rework linux toolcache tests, add Ruby 2.7.0 support (#5)
Browse files Browse the repository at this point in the history
* Toolcache: rework linux toolcache tests

* Toolcache: add Ruby 2.7 for windows/linux
  • Loading branch information
vmapetr authored Jan 9, 2020
1 parent d98bb53 commit 9c67ed5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 100 deletions.
153 changes: 56 additions & 97 deletions images/linux/scripts/installers/test-toolcache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,112 +6,71 @@

# Must be procecessed after tool cache setup(hosted-tool-cache.sh).

Test_Hostedtoolcache_Tool() {
TOOL_NAME=$1
TOOL_BIN_PATH=$2
TOOL_COMMAND=$3

if [ -d "$AGENT_TOOLSDIRECTORY/$TOOL_NAME" ]; then
cd $AGENT_TOOLSDIRECTORY/$TOOL_NAME

tool_dirs=($(find . -mindepth 1 -maxdepth 1 -type d | sed "s|^\./||"))

echo "--------------------------------------------"
echo "$TOOL_NAME versions folders: ${tool_dirs[@]}"
echo "--------------------------------------------"

if [ -n "$tool_dirs" ]; then
tool_key=$(echo $TOOL_NAME | tr "[:upper:]" "[:lower:]")
package_versions=($(jq -r ".[\"${TOOLCACHE_KEY_VALUE[$tool_key]}\"] | .[]" "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))

for tool_version in ${package_versions[@]}
do
version_dir=$(find . -name "$tool_version.*" -print -quit)

echo "Test $AGENT_TOOLSDIRECTORY/$TOOL_NAME/$version_dir:"

version_bin_path=$(find . -regex "$version_dir/$TOOL_BIN_PATH" -print -quit)
actual_version=$(eval $AGENT_TOOLSDIRECTORY/$TOOL_NAME/$version_bin_path $TOOL_COMMAND)

if [ "$actual_version" = "$tool_version" ]; then
echo "Passed!"
else
echo "Expected: $tool_version; Actual: $actual_version"

exit 1
fi
done;
else
echo "$AGENT_TOOLSDIRECTORY/$tool_version does not include any folders"

exit 1
fi
else
echo "$AGENT_TOOLSDIRECTORY/$tool_version does not exist"

exit 1
fi
}

# Fail out if any tests fail
set -e

# define array of key aliases
key_alias_array=()
bash --version
# define dictionary for key_alias and its values
declare -A toolcache_key_value
PACKAGE_LIST=($(jq -r 'keys | .[]' "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))
for PACKAGE_NAME in ${PACKAGE_LIST[@]}; do
declare -A TOOLCACHE_KEY_VALUE

package_list=($(jq -r 'keys | .[]' "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))

for package_name in ${package_list[@]}; do
# get key alias
key_alias=$(echo $PACKAGE_NAME | cut -f2 -d-)
echo $key_alias
key_alias=$(echo $package_name | cut -f2 -d-)

# set dictionary
toolcache_key_value+=(["$key_alias"]="$PACKAGE_NAME")
TOOLCACHE_KEY_VALUE+=(["$key_alias"]="$package_name")
done;

AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache

# Python test
if [ -d "$AGENT_TOOLSDIRECTORY/Python" ]; then
cd $AGENT_TOOLSDIRECTORY/Python
python_dirs=($(find . -mindepth 1 -maxdepth 1 -type d | sed "s|^\./||"))
echo "Python versions folders: ${python_dirs[@]}"
echo "------------------------------------------"
if [ -n "$python_dirs" ]; then
PACKAGE_VERSIONS=($(jq -r ".[\"${toolcache_key_value[python]}\"] | .[]" "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))
for python_version in ${PACKAGE_VERSIONS[@]}
do
version_dir=$(find . -name "$python_version.*" -print -quit)
echo "Test $AGENT_TOOLSDIRECTORY/Python/$version_dir:"
actual_ver=$($AGENT_TOOLSDIRECTORY/Python/$version_dir/x64/python -c 'import sys;print(sys.version)'| head -1 | egrep -o '[0-9]+\.[0-9]+')
if [ "$actual_ver" = "$python_version" ]; then
echo "Passed!"
else
echo "Expected: $python_version; Actual: $actual_ver"
exit 1
fi
done;
else
echo "$AGENT_TOOLSDIRECTORY/Python does not include any folders"
exit 1
fi
else
echo "$AGENT_TOOLSDIRECTORY/Python does not exist"
exit 1
fi

# Ruby test
if [ -d "$AGENT_TOOLSDIRECTORY/Ruby" ]; then
cd $AGENT_TOOLSDIRECTORY/Ruby
ruby_dirs=($(find . -mindepth 1 -maxdepth 1 -type d | sed "s|^\./||"))
echo "Ruby versions folders: ${ruby_dirs[@]}"
echo "--------------------------------------"
if [ -n "$ruby_dirs" ]; then
PACKAGE_VERSIONS=($(jq -r ".[\"${toolcache_key_value[ruby]}\"] | .[]" "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))
for ruby_version in ${PACKAGE_VERSIONS[@]}
do
version_dir=$(find . -name "$ruby_version.*" -print -quit)
echo "Test $AGENT_TOOLSDIRECTORY/Ruby/$version_dir:"
actual_ver=$($AGENT_TOOLSDIRECTORY/Ruby/$version_dir/x64/bin/ruby -e "puts RUBY_VERSION" | egrep -o '[0-9]+\.[0-9]+')
if [ "$actual_ver" = "$ruby_version" ]; then
echo "Passed!"
else
echo "Expected: $ruby_version; Actual: $actual_ver"
exit 1
fi
done;
else
echo "$AGENT_TOOLSDIRECTORY/Ruby does not include any folders"
exit 1
fi
else
echo "$AGENT_TOOLSDIRECTORY/Ruby does not exist"
exit 1
fi

# PyPy tests
if [ -d "$AGENT_TOOLSDIRECTORY/PyPy" ]; then
cd $AGENT_TOOLSDIRECTORY/PyPy
pypy_dirs=($(find . -mindepth 1 -maxdepth 1 -type d | sed "s|^\./||"))
echo "PyPy versions folders: ${pypy_dirs[@]}"
echo "------------------------------------------"
if [ -n "$pypy_dirs" ]; then
PACKAGE_VERSIONS=($(jq -r ".[\"${toolcache_key_value[pypy]}\"] | .[]" "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))
for pypy_version in ${PACKAGE_VERSIONS[@]}
do
version_dir=$(find . -name "$pypy_version.*" -print -quit)
pypy_path=$(find . -regex "$version_dir/x64/bin/pypy[0-9]*" -print -quit)
echo $pypy_path
actual_ver=$($pypy_path -c 'import sys;print(sys.version)'| head -1 | egrep -o '[0-9]+\.[0-9]+' | cut -d '.' -f 1)
echo "actual_ver = $actual_ver : pypy_version = $pypy_version"
if [ "$actual_ver" = "$pypy_version" ]; then
echo "Passed!"
else
echo "Expected: $pypy_version; Actual: $actual_ver"
exit 1
fi
done;
else
echo "$AGENT_TOOLSDIRECTORY/PyPy does not include any folders"
exit 1
fi
else
echo "$AGENT_TOOLSDIRECTORY/PyPy does not exist"
exit 1
fi
Test_Hostedtoolcache_Tool "Python" "x64/python" "-c 'import sys;print(sys.version)'| head -1 | egrep -o '[0-9]+\.[0-9]+'"
Test_Hostedtoolcache_Tool "Ruby" "x64/bin/ruby" "-e 'puts RUBY_VERSION' | egrep -o '[0-9]+\.[0-9]+'"
Test_Hostedtoolcache_Tool "PyPy" "x64/bin/pypy[0-9]*" "-c 'import sys;print(sys.version)'| head -1 | egrep -o '[0-9]+\.[0-9]+' | cut -d '.' -f 1"
2 changes: 1 addition & 1 deletion images/linux/toolcache-1604.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"toolcache-ruby-ubuntu-1604-x64": [
"2.4", "2.5", "2.6"
"2.4", "2.5", "2.6", "2.7"
],
"toolcache-pypy-ubuntu-1604-x64": [
"2", "3"
Expand Down
2 changes: 1 addition & 1 deletion images/linux/toolcache-1804.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"toolcache-ruby-ubuntu-1804-x64": [
"2.4", "2.5", "2.6"
"2.4", "2.5", "2.6", "2.7"
],
"toolcache-pypy-ubuntu-1804-x64": [
"2", "3"
Expand Down
2 changes: 1 addition & 1 deletion images/win/toolcache.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"2.7", "3.5", "3.6", "3.7", "3.8"
],
"toolcache-ruby-windows-x64": [
"2.4", "2.5", "2.6"
"2.4", "2.5", "2.6", "2.7"
],
"toolcache-pypy-windows-x86": [
"2", "3"
Expand Down

0 comments on commit 9c67ed5

Please sign in to comment.