Created
March 31, 2022 18:33
-
-
Save bizzk3t/7e70d1e99253d50fc1c230c59c51f5ec to your computer and use it in GitHub Desktop.
test-package-manager-network.sh
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
#!/usr/bin/env bash | |
# test installation of packages using different package managers | |
# used for testing network | |
# I have tested this on Ubuntu 21.10 | |
# Bash version: 5.1.8(1)-release | |
# must have node/npm/yarn installed. | |
# Whenever I have an ipv4 address yarn should fail almost every time. | |
# However, when I have an ipv6 address, everything works. | |
# make sure to chmod +x ./run.sh | |
name="test-package-manager-network.sh" | |
print_usage() { | |
echo "usage: ./$name [package manager: yarn, npm, yarn2]" | |
echo "" | |
echo "examples" | |
echo "--------" | |
echo "./$name yarn" | |
echo "./$name npm" | |
echo "./$name yarn2" | |
echo "./$name --help|-h|help" | |
} | |
if [[ $# -eq 0 ]]; then | |
print_usage | |
exit 1 | |
fi | |
while [[ $# -gt 0 ]]; do | |
case $1 in | |
-h|--help|help) | |
print_usage | |
exit 0 | |
;; | |
-*|--*) | |
echo "unknown options: $1" | |
exit 1 | |
;; | |
yarn|yarn2|npm) | |
CMD="$1" | |
shift | |
;; | |
*) | |
echo "ERROR: unknown argument: $1" | |
print_usage | |
exit 1 | |
shift | |
;; | |
esac | |
done | |
# TODO: implment clean cache option | |
# yarn cache clean -g | |
# npm cache clean -g --force | |
echo "Running package manager: $CMD" | |
TEST_DIRECTORY="test-directory-for-$CMD" | |
mkdir $TEST_DIRECTORY | |
cd $TEST_DIRECTORY | |
# init directory | |
case $CMD in | |
yarn) yarn init -y;; | |
yarn2) yarn init -y -2;; | |
npm) npm init -y;; | |
esac | |
# any packages here are fine. I chose the most popular ones on a list I found online. | |
PKGS=(lodash chalk react express moment react-dom bluebird underscore vue) | |
PASS=() | |
FAIL=() | |
# loop through list of packages and install each package one at a time. | |
for i in "${PKGS[@]}"; do | |
echo "Testing package: '$i'..." | |
case $CMD in | |
yarn|yarn2) yarn add "$i" && PASS+=("$i") || FAIL+=("$i");; | |
npm) npm install "$i" && PASS+=("$i") || FAIL+=("$i");; | |
esac | |
if [[ "${#FAIL[@]}" -gt 0 ]]; then | |
echo "FOUND A FAILURE! Quitting..." | |
break | |
fi | |
done | |
echo "'$CMD' package manager install results: " | |
echo "Fail: ${#FAIL[@]} ($FAIL)" | |
echo "Pass: ${#PASS[@]} ($PASS)" | |
# copy package.json to current directory to verify package version numbers | |
# cp -v package.json "../$(date +%s)-package.json" | |
cd .. | |
rm -rf $TEST_DIRECTORY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment