1
0
mirror of https://github.com/alrayyes/wercker-surge-deploy-step synced 2023-11-13 18:16:40 +00:00
wercker-surge-deploy-step/run.sh

58 lines
1.6 KiB
Bash
Raw Normal View History

2016-10-04 19:30:15 +00:00
#!/bin/sh
# return true if local npm package is installed at ./node_modules, else false
# example
2016-10-04 19:49:47 +00:00
# echo "surge : $(npm_package_is_installed surge)"
2016-10-04 19:30:15 +00:00
function npm_package_is_installed {
# set to true initially
local return_=true
# set to false if not found
ls node_modules | grep $1 >/dev/null 2>&1 || { local return_=false; }
# return value
echo "$return_"
}
# First make sure surge is installed
2016-10-04 19:49:47 +00:00
if ! type surge &> /dev/null ; then
2016-10-04 19:30:15 +00:00
# Check if it is in repo
if ! $(npm_package_is_installed surge) ; then
info "surge not installed, trying to install it through npm"
if ! type npm &> /dev/null ; then
fail "npm not found, make sure you have npm or surge installed"
else
info "npm is available"
debug "npm version: $(npm --version)"
info "installing surge"
npm config set ca "" --silent
sudo npm install npm -g --silent
2016-10-04 19:49:47 +00:00
sudo npm install -g --silent surge
surge_command="surge"
2016-10-04 19:30:15 +00:00
fi
else
info "surge is available locally"
debug "surge version: $( node ./node_modules/.bin/surge --version)"
surge_command=" node ./node_modules/.bin/surge"
fi
else
info "surge is available"
debug "surge version: $(surge --version)"
surge_command="surge"
fi
debug "$surge_command"
set +e
2016-10-04 19:59:28 +00:00
$surge_command public $WERCKER_SURGE_DOMAIN --token $WERCKER_SURGE_TOKEN
2016-10-04 19:30:15 +00:00
result="$?"
set -e
# Fail if it is not a success or warning
if [[ result -ne 0 && result -ne 6 ]]
then
warn "$result"
fail "surge command failed"
else
success "finished $surge_command"
fi