Created
April 24, 2020 17:45
-
-
Save willmendesneto/c0df9f94592915752571e92f72976e76 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# | |
# Checks and validations to be done before install command | |
# | |
# How to use | |
# $ chmod +x ./pre-install.sh | |
# $ ./pre-install.sh (-r|--registry) (-n|--npm-namespace) | |
# | |
# $ ./pre-install.sh --registry=https://registry.yarnpkg.com | |
# $ ./pre-install.sh --registry=https://registry.yarnpkg.com --npm-namespace=<my-namespace> | |
# | |
PACKAGE_REGISTRY="" | |
NPM_PACKAGE_NAMESPACE="" | |
for i in "$@" | |
do | |
case $i in | |
-r=*|--registry=*) | |
PACKAGE_REGISTRY="${i#*=}" | |
shift # past argument=value | |
;; | |
-n=*|--npm-namespace=*) | |
NPM_PACKAGE_NAMESPACE="${i#*=}" | |
shift # past argument=value | |
;; | |
--default) | |
shift # past argument with no value | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
done | |
if [ "$PACKAGE_REGISTRY" == "" ]; then | |
echo "Please pass a NPM registry for the pre install command"; | |
echo "./pre-install.sh (-r|--registry) (-n|--npm-namespace)"; | |
echo ""; | |
echo "EX:"; | |
echo "./pre-install.sh --registry=https://registry.yarnpkg.com"; | |
echo "./pre-install.sh --registry=https://registry.yarnpkg.com --npm-namespace=<my-namespace>"; | |
echo ""; | |
exit 1; | |
fi | |
# Check if NPM mirror and NPMRC are configured as expected for private requirements | |
# Also, it has a safeguard check for CI to avoid running yarn config check for registry in CI by accident | |
# since there's no need for that check on Bitbucket pipelines | |
if [[ "$NPM_PACKAGE_NAMESPACE" != "" && "$(cat ~/.npmrc | grep ${NPM_PACKAGE_NAMESPACE})" == "" ]] || [[ "$CI" != "true" && "$(yarn config get registry)" != *"$PACKAGE_REGISTRY"* ]]; then | |
echo "Atlassian private NPM Registry is not configured properly. For more details, please check https://hello.atlassian.net/wiki/spaces/RELENG/pages/137968733/HOWTO+-+Use+Atlassian+private+npm+registry"; | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment