Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tools): require min version or use @latest #511

Merged
merged 5 commits into from
Jun 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 112 additions & 4 deletions AmplifyTools/amplify-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,121 @@
# SPDX-License-Identifier: Apache-2.0

set -e
export PATH=$PATH:$(npm bin -g)

if ! which node >/dev/null; then
echo "warning: Node is not installed. Visit https://nodejs.org/en/download/ to install it"
exit 1
elif ! test -f ./amplifytools.xcconfig; then
npx amplify-app --platform ios
fi

export PATH=$PATH:$(npm bin -g)

# Note the use of tail -1 is important here because when upgrading between versions
# the first time that you run these commands, we have seen this variable take on the value of:
# """
# Scanning for plugins...
# plugin scan successful
# 4.21.0
# """
AMP_APP_VERSION_CURRENT=`npx -q amplify-app --version |tail -1`
AMP_APP_VERSION_MINIMUM="2.17.1"
AMP_APP_VERSION_INVALID=0

AMP_CLI_VERSION_CURRENT=`npx -q amplify --version |tail -1`
AMP_CLI_VERSION_MINIMUM="4.21.0"
AMP_CLI_VERSION_INVALID=0


STRIP_ESCAPE_RESULT=
stripEscapeUtil() {
palpatim marked this conversation as resolved.
Show resolved Hide resolved
STRIP_ESCAPE_RESULT=

set +e
HAS_RUBY=0
which ruby > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
HAS_RUBY=1
fi
set -e

if [ ${HAS_RUBY} -eq 1 ]; then
STRIP_ESCAPE_RESULT=`echo "${1}" | ruby -pe 'gsub(/\e\[[0-9;]*m/s, "")'`
else
STRIP_ESCAPE_RESULT=`echo "${1}" | npx -q strip-ansi-cli`
fi
}

VERSION_INVALID=
checkMinVersionCompatibility() {
palpatim marked this conversation as resolved.
Show resolved Hide resolved
VERSION_INVALID=0

stripEscapeUtil "${1}"
palpatim marked this conversation as resolved.
Show resolved Hide resolved
CURR_VERSION_SAFE="${STRIP_ESCAPE_RESULT}"
CURR_VERSION_MAJOR=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $1}'`
CURR_VERSION_MINOR=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $2}'`
CURR_VERSION_PATCH=`echo "${CURR_VERSION_SAFE}" | tr '.' ' ' | awk '{print $3}'`

stripEscapeUtil "${2}"
REQU_VERSION_SAFE="${STRIP_ESCAPE_RESULT}"
REQU_VERSION_MAJOR=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $1}'`
REQU_VERSION_MINOR=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $2}'`
REQU_VERSION_PATCH=`echo "${REQU_VERSION_SAFE}" | tr '.' ' ' | awk '{print $3}'`

if [ -z "${CURR_VERSION_MAJOR}" ] ||
[ -z "${CURR_VERSION_MINOR}" ] ||
[ -z "${CURR_VERSION_PATCH}" ] ||
[ -z "${REQU_VERSION_MAJOR}" ] ||
[ -z "${REQU_VERSION_MINOR}" ] ||
[ -z "${REQU_VERSION_PATCH}" ]; then
VERSION_INVALID=1
return
fi

if [ ${CURR_VERSION_MAJOR} -lt ${REQU_VERSION_MAJOR} ]; then
VERSION_INVALID=1
return
else
if [ ${CURR_VERSION_MINOR} -lt ${REQU_VERSION_MINOR} ]; then
VERSION_INVALID=1
return
else
if [ ${CURR_VERSION_PATCH} -lt ${REQU_VERSION_PATCH} ]; then
VERSION_INVALID=1
return
fi
fi
fi
}

checkMinVersionCompatibility "${AMP_APP_VERSION_CURRENT}" "${AMP_APP_VERSION_MINIMUM}"
AMP_APP_VERSION_INVALID=${VERSION_INVALID}

checkMinVersionCompatibility "${AMP_CLI_VERSION_CURRENT}" "${AMP_CLI_VERSION_MINIMUM}"
AMP_CLI_VERSION_INVALID=${VERSION_INVALID}

if [ ${AMP_CLI_VERSION_INVALID} -eq 1 ]; then
echo "error: Minimum version required of Amplify CLI is not installed."
echo " Min required version: (${AMP_CLI_VERSION_MINIMUM})"
echo " Found Version: (${AMP_CLI_VERSION_CURRENT})"
echo ""
echo "To install the latest version, please run the following command:"
echo " npm install -g @aws-amplify/cli@latest"
exit 1
else
echo "Found amplify-cli version: (${AMP_CLI_VERSION_CURRENT}), Required: >= (${AMP_CLI_VERSION_MINIMUM})"
fi

echo "Found amplify-app version: (${AMP_APP_VERSION_CURRENT}), Required: >= (${AMP_APP_VERSION_MINIMUM})"
if [ ${AMP_APP_VERSION_INVALID} -eq 1 ]; then
echo " Using: npx amplify-app@latest"
NPX_AMP_APPCMD="npx amplify-app@latest"
else
echo " Using: npx amplify-app"
NPX_AMP_APPCMD="npx amplify-app"
fi


if ! test -f ./amplifytools.xcconfig; then
${NPX_AMP_APPCMD} --platform ios
fi

. amplifytools.xcconfig
Expand All @@ -28,7 +136,7 @@ if $amplifyModelgen; then
echo "modelgen is set to true, generating Swift models from schema.graphql..."
amplify codegen model
# calls amplify-app again so the Xcode project is updated with the generated models
npx amplify-app --platform ios
${NPX_AMP_APPCMD} --platform ios
fi

if [ -z "$amplifyAccessKey" ] || [ -z "$amplifySecretKey" ] || [ -z "$amplifyRegion" ]; then
Expand Down