Skip to content

Commit

Permalink
Fix: reinstall a new version of yarn on machine executor (#227)
Browse files Browse the repository at this point in the history
* Indent fix

* Add new test for reinstall yarn on machine behavior

* Remove old yarn installations with nvm

* Fix linter issues
  • Loading branch information
marboledacci authored Aug 30, 2024
1 parent a961cb5 commit 70cddc3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
8 changes: 7 additions & 1 deletion .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ jobs:
echo "pnpm version 9.7.1 not found"
exit 1
fi
integration-test-reinstall-yarn:
machine:
image: ubuntu-2004:current
steps:
- node/install-yarn
integration-test-install-latest:
parameters:
os:
Expand Down Expand Up @@ -187,6 +191,7 @@ jobs:
workflows:
test-deploy:
jobs:
- integration-test-reinstall-yarn
- integration-test-install-specified-version:
filters: *filters
matrix:
Expand Down Expand Up @@ -399,6 +404,7 @@ workflows:
- integration-test-install-lts
- integration-test-install-pnpm
- integration-test-pnpm
- integration-test-reinstall-yarn
- node-yarn-mocha-with-test-result-path-job
- node-test-results-file-job
- node-run-npm-job
Expand Down
57 changes: 30 additions & 27 deletions src/scripts/install-yarn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,44 @@ if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
# FUNCTIONS
get_yarn_version () {
if [[ "$NODE_PARAM_YARN_VERSION" == "" ]]; then
YARN_ORB_VERSION=$(curl -s https://cdn.jsdelivr.net/npm/yarn/package.json | sed -n 's/.*version": "\(.*\)".*/\1/p')
echo "Latest version of Yarn is $YARN_ORB_VERSION"
YARN_ORB_VERSION=$(curl -s https://cdn.jsdelivr.net/npm/yarn/package.json | sed -n 's/.*version": "\(.*\)".*/\1/p')
echo "Latest version of Yarn is $YARN_ORB_VERSION"
else
YARN_ORB_VERSION="$NODE_PARAM_YARN_VERSION"

echo "Selected version of Yarn is $YARN_ORB_VERSION"
YARN_ORB_VERSION="$NODE_PARAM_YARN_VERSION"
echo "Selected version of Yarn is $YARN_ORB_VERSION"
fi
}

installation_check () {
echo "Checking if YARN is already installed..."
if command -v yarn > /dev/null 2>&1; then
if yarn --version | grep "$YARN_ORB_VERSION" > /dev/null 2>&1; then
echo "Yarn $YARN_ORB_VERSION is already installed"
exit 0
else
echo "A different version of Yarn is installed ($(yarn --version)); removing it"

if uname -a | grep Darwin > /dev/null 2>&1; then
brew uninstall yarn > /dev/null 2>&1
elif grep Alpine /etc/issue > /dev/null 2>&1; then
apk del yarn > /dev/null 2>&1
elif grep Debian /etc/issue > /dev/null 2>&1; then
$SUDO apt-get remove yarn > /dev/null 2>&1 && \
$SUDO apt-get purge yarn > /dev/null 2>&1
elif grep Ubuntu /etc/issue > /dev/null 2>&1; then
$SUDO apt-get remove yarn > /dev/null 2>&1 && \
$SUDO apt-get purge yarn > /dev/null 2>&1
elif command -v yum > /dev/null 2>&1; then
yum remove yarn > /dev/null 2>&1
if yarn --version | grep "$YARN_ORB_VERSION" > /dev/null 2>&1; then
echo "Yarn $YARN_ORB_VERSION is already installed"
exit 0
else
echo "A different version of Yarn is installed ($(yarn --version)); removing it"

if uname -a | grep Darwin > /dev/null 2>&1; then
brew uninstall yarn > /dev/null 2>&1
elif grep Alpine /etc/issue > /dev/null 2>&1; then
apk del yarn > /dev/null 2>&1
elif grep Debian /etc/issue > /dev/null 2>&1; then
$SUDO apt-get remove yarn > /dev/null 2>&1 && \
$SUDO apt-get purge yarn > /dev/null 2>&1
OLD_YARN=$(which yarn)
rm "$OLD_YARN"
elif grep Ubuntu /etc/issue > /dev/null 2>&1; then
$SUDO apt-get remove yarn > /dev/null 2>&1 && \
$SUDO apt-get purge yarn > /dev/null 2>&1
OLD_YARN=$(which yarn)
rm "$OLD_YARN"
elif command -v yum > /dev/null 2>&1; then
yum remove yarn > /dev/null 2>&1
fi

$SUDO rm -rf "$HOME/.yarn" > /dev/null 2>&1
$SUDO rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg > /dev/null 2>&1
fi

$SUDO rm -rf "$HOME/.yarn" > /dev/null 2>&1
$SUDO rm -f /usr/local/bin/yarn /usr/local/bin/yarnpkg > /dev/null 2>&1
fi
fi
}

Expand Down

0 comments on commit 70cddc3

Please sign in to comment.