mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-20 06:29:50 +00:00
Merge pull request #216 from vmapetr/v-mapetr/add-npm-toolcache
Toolcache: Add NPM Toolcache support for Windows/Linux
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
#!/bin/bash
|
||||
################################################################################
|
||||
## File: hosted-tool-cache.sh
|
||||
## Desc: Downloads and installs hosted tools cache
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/document.sh
|
||||
|
||||
# Fail out if any setups fail
|
||||
set -e
|
||||
|
||||
# Download hosted tool cache
|
||||
AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
|
||||
echo "AGENT_TOOLSDIRECTORY=$AGENT_TOOLSDIRECTORY" | tee -a /etc/environment
|
||||
azcopy --recursive \
|
||||
--source https://vstsagenttools.blob.core.windows.net/tools/hostedtoolcache/ubuntu-1804 \
|
||||
--destination $AGENT_TOOLSDIRECTORY
|
||||
|
||||
# Install tools from hosted tool cache
|
||||
original_directory=$PWD
|
||||
setups=$(find $AGENT_TOOLSDIRECTORY -name setup.sh)
|
||||
for setup in $setups; do
|
||||
chmod +x $setup;
|
||||
cd $(dirname $setup);
|
||||
./$(basename $setup);
|
||||
cd $original_directory;
|
||||
done;
|
||||
|
||||
DocumentInstalledItem "Python:"
|
||||
pythons=$(ls $AGENT_TOOLSDIRECTORY/Python)
|
||||
for python in $pythons; do
|
||||
DocumentInstalledItemIndent "Python $python"
|
||||
done;
|
||||
|
||||
# PyPy is also configured using the setup-python action
|
||||
pypys=$(ls $AGENT_TOOLSDIRECTORY/PyPy)
|
||||
for pypy in $pypys; do
|
||||
DocumentInstalledItemIndent "PyPy $pypy"
|
||||
# Add symlinks for pypy2 and pypy3 to usr/local/bin, there should only be 2 versions of PyPy in the tools cache that is downloaded
|
||||
if [ ${pypy:0:1} -eq "3" ] ; then
|
||||
# add pypy 3.X to PATH
|
||||
ln -s $AGENT_TOOLSDIRECTORY/PyPy/$pypy/x64/bin/pypy3 /usr/local/bin/pypy3
|
||||
else
|
||||
# add pypy 2.X to PATH
|
||||
ln -s $AGENT_TOOLSDIRECTORY/PyPy/$pypy/x64/bin/pypy /usr/local/bin/pypy
|
||||
fi
|
||||
done;
|
||||
|
||||
DocumentInstalledItem "Ruby:"
|
||||
rubys=$(ls $AGENT_TOOLSDIRECTORY/Ruby)
|
||||
for ruby in $rubys; do
|
||||
DocumentInstalledItemIndent "Ruby $ruby"
|
||||
done;
|
||||
@@ -7,7 +7,6 @@
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/document.sh
|
||||
|
||||
BOOST_ZIP_PATH=/opt/hostedtoolcache/Boost
|
||||
BOOST_LIB=/usr/local/share/boost
|
||||
|
||||
# Install Boost
|
||||
@@ -15,9 +14,6 @@ for BOOST_VERSION in ${BOOST_VERSIONS//,/ }
|
||||
do
|
||||
BOOST_SYMLINK_VER=`echo "${BOOST_VERSION//[.]/_}"`
|
||||
BOOST_ROOT="BOOST_ROOT_$BOOST_SYMLINK_VER"
|
||||
BOOST_ZIP="boost_`echo $BOOST_VERSION`_gcc.zip"
|
||||
|
||||
unzip $BOOST_ZIP_PATH/$BOOST_ZIP -d $BOOST_LIB
|
||||
|
||||
echo "$BOOST_ROOT=$BOOST_LIB/$BOOST_VERSION" | tee -a /etc/environment
|
||||
if [[ $BOOST_VERSION == $BOOST_DEFAULT ]]; then
|
||||
@@ -26,6 +22,3 @@ do
|
||||
|
||||
DocumentInstalledItem "Boost C++ Libraries $BOOST_VERSION"
|
||||
done
|
||||
|
||||
# Deleting archives with Boost Libraries
|
||||
rm -rf $BOOST_ZIP_PATH
|
||||
|
||||
@@ -10,21 +10,23 @@ source $HELPER_SCRIPTS/document.sh
|
||||
# Fail out if any setups fail
|
||||
set -e
|
||||
|
||||
# Download hosted tool cache
|
||||
AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
|
||||
mkdir $AGENT_TOOLSDIRECTORY
|
||||
echo "AGENT_TOOLSDIRECTORY=$AGENT_TOOLSDIRECTORY" | tee -a /etc/environment
|
||||
azcopy --recursive \
|
||||
--source https://vstsagenttools.blob.core.windows.net/tools/hostedtoolcache/linux \
|
||||
--destination $AGENT_TOOLSDIRECTORY
|
||||
|
||||
# Install tools from hosted tool cache
|
||||
original_directory=$PWD
|
||||
setups=$(find $AGENT_TOOLSDIRECTORY -name setup.sh)
|
||||
for setup in $setups; do
|
||||
chmod +x $setup;
|
||||
cd $(dirname $setup);
|
||||
./$(basename $setup);
|
||||
cd $original_directory;
|
||||
chmod -R 777 $AGENT_TOOLSDIRECTORY
|
||||
|
||||
echo "Installing npm-toolcache..."
|
||||
TOOLSET_PATH="$INSTALLER_SCRIPT_FOLDER/toolcache.json"
|
||||
|
||||
PACKAGE_LIST=($(jq -r 'keys | .[]' $TOOLSET_PATH))
|
||||
|
||||
for PACKAGE_NAME in ${PACKAGE_LIST[@]}; do
|
||||
PACKAGE_VERSIONS=($(jq -r ".[\"$PACKAGE_NAME\"] | .[]" $TOOLSET_PATH))
|
||||
for PACKAGE_VERSION in ${PACKAGE_VERSIONS[@]}; do
|
||||
echo "Install ${PACKAGE_NAME}@${PACKAGE_VERSION}"
|
||||
npm install ${PACKAGE_NAME}@${PACKAGE_VERSION} --registry=${TOOLCACHE_REGISTRY}
|
||||
done;
|
||||
done;
|
||||
|
||||
DocumentInstalledItem "Python:"
|
||||
@@ -33,22 +35,14 @@ for python in $pythons; do
|
||||
DocumentInstalledItemIndent "Python $python"
|
||||
done;
|
||||
|
||||
# PyPy is also configured using the setup-python action
|
||||
pypys=$(ls $AGENT_TOOLSDIRECTORY/PyPy)
|
||||
for pypy in $pypys; do
|
||||
DocumentInstalledItemIndent "PyPy $pypy"
|
||||
# Add symlinks for pypy2 and pypy3 to usr/local/bin, there should only be 2 versions of PyPy in the tools cache that is downloaded
|
||||
if [ ${pypy:0:1} -eq "3" ] ; then
|
||||
# add pypy 3.X to PATH
|
||||
ln -s $AGENT_TOOLSDIRECTORY/PyPy/$pypy/x64/bin/pypy3 /usr/local/bin/pypy3
|
||||
else
|
||||
# add pypy 2.X to PATH
|
||||
ln -s $AGENT_TOOLSDIRECTORY/PyPy/$pypy/x64/bin/pypy /usr/local/bin/pypy
|
||||
fi
|
||||
done;
|
||||
|
||||
DocumentInstalledItem "Ruby:"
|
||||
rubys=$(ls $AGENT_TOOLSDIRECTORY/Ruby)
|
||||
for ruby in $rubys; do
|
||||
DocumentInstalledItemIndent "Ruby $ruby"
|
||||
done;
|
||||
done;
|
||||
|
||||
DocumentInstalledItem "PyPy:"
|
||||
pypys=$(ls $AGENT_TOOLSDIRECTORY/PyPy)
|
||||
for pypy in $pypys; do
|
||||
DocumentInstalledItemIndent "PyPy $pypy"
|
||||
done;
|
||||
@@ -6,65 +6,69 @@
|
||||
|
||||
# Must be procecessed after tool cache setup(hosted-tool-cache.sh).
|
||||
|
||||
Test_Hostedtoolcache_Tool() {
|
||||
TOOL_NAME=$1
|
||||
TOOL_EXEC_TEST=$2
|
||||
|
||||
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:"
|
||||
|
||||
actual_version=$(eval $AGENT_TOOLSDIRECTORY/$TOOL_NAME/$version_dir/$TOOL_EXEC_TEST)
|
||||
|
||||
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 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
|
||||
# get key alias
|
||||
key_alias=$(echo $package_name | cut -f2 -d-)
|
||||
|
||||
# set dictionary
|
||||
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
|
||||
for version_dir in "${python_dirs[@]}"
|
||||
do
|
||||
echo "Test $AGENT_TOOLSDIRECTORY/Python/$version_dir:"
|
||||
expected_ver=$(echo $version_dir | egrep -o '[0-9]+\.[0-9]+')
|
||||
actual_ver=$($AGENT_TOOLSDIRECTORY/Python/$version_dir/x64/python -c 'import sys;print(sys.version)'| head -1 | egrep -o '[0-9]+\.[0-9]+')
|
||||
|
||||
if [ "$expected_ver" = "$actual_ver" ]; then
|
||||
echo "Passed!"
|
||||
else
|
||||
echo "Expected: $expected_ver; 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
|
||||
for version_dir in "${ruby_dirs[@]}"
|
||||
do
|
||||
echo "Test $AGENT_TOOLSDIRECTORY/Ruby/$version_dir:"
|
||||
expected_ver=$(echo $version_dir | egrep -o '[0-9]+\.[0-9]+')
|
||||
actual_ver=$($AGENT_TOOLSDIRECTORY/Ruby/$version_dir/x64/bin/ruby -e "puts RUBY_VERSION" | egrep -o '[0-9]+\.[0-9]+')
|
||||
|
||||
if [ "$expected_ver" = "$actual_ver" ]; then
|
||||
echo "Passed!"
|
||||
else
|
||||
echo "Expected: $expected_ver; 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
|
||||
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/python -c 'import sys;print(sys.version)'| head -1 | egrep -o '[0-9]+\.[0-9]+' | cut -d '.' -f 1"
|
||||
|
||||
Reference in New Issue
Block a user