From 9c67ed5210479082c9228c9ba8c523caef35986b Mon Sep 17 00:00:00 2001 From: Maksim Petrov <47208721+vmapetr@users.noreply.github.com> Date: Thu, 9 Jan 2020 15:27:54 +0300 Subject: [PATCH] Toolcache: Rework linux toolcache tests, add Ruby 2.7.0 support (#5) * Toolcache: rework linux toolcache tests * Toolcache: add Ruby 2.7 for windows/linux --- .../scripts/installers/test-toolcache.sh | 153 +++++++----------- images/linux/toolcache-1604.json | 2 +- images/linux/toolcache-1804.json | 2 +- images/win/toolcache.json | 2 +- 4 files changed, 59 insertions(+), 100 deletions(-) diff --git a/images/linux/scripts/installers/test-toolcache.sh b/images/linux/scripts/installers/test-toolcache.sh index 0a64882a2c..c54118e196 100644 --- a/images/linux/scripts/installers/test-toolcache.sh +++ b/images/linux/scripts/installers/test-toolcache.sh @@ -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 \ No newline at end of file +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" diff --git a/images/linux/toolcache-1604.json b/images/linux/toolcache-1604.json index 2674d57af2..ea7f73c245 100644 --- a/images/linux/toolcache-1604.json +++ b/images/linux/toolcache-1604.json @@ -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" diff --git a/images/linux/toolcache-1804.json b/images/linux/toolcache-1804.json index ca75563cdb..b076eaf2c2 100644 --- a/images/linux/toolcache-1804.json +++ b/images/linux/toolcache-1804.json @@ -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" diff --git a/images/win/toolcache.json b/images/win/toolcache.json index 69434da3aa..32aae3d50b 100644 --- a/images/win/toolcache.json +++ b/images/win/toolcache.json @@ -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"