drone-netlify/script.sh

66 lines
1.4 KiB
Bash
Raw Normal View History

2020-11-20 03:46:29 +00:00
#!/bin/bash
2018-02-15 20:08:23 +00:00
set -e
NETLIFY_SITE=""
NETLIFY_DEPLOY_OPTIONS=""
NETLIFY_UPDATE_OPTIONS=""
if [ -n "$PLUGIN_ENVIRONMENT" ]
then
NETLIFY_DEPLOY_OPTIONS="-e ${PLUGIN_ENVIRONMENT}"
NETLIFY_UPDATE_OPTIONS="${NETLIFY_DEPLOY_OPTIONS}"
fi
if [ -n "$PLUGIN_PATH" ]
then
2020-01-29 01:03:33 +00:00
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} -d ${PLUGIN_PATH}"
2018-02-15 20:08:23 +00:00
else
2020-01-29 01:03:33 +00:00
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} -d ./"
2018-02-15 20:08:23 +00:00
fi
2018-02-15 21:11:09 +00:00
if [ -z "$PLUGIN_TOKEN" ]
then
if [ -z "$NETLIFY_TOKEN" ]
then
echo "> Error! token or netlify_token secret is required"
exit 1;
else
PLUGIN_TOKEN="$NETLIFY_TOKEN"
fi
fi
2018-02-15 20:08:23 +00:00
if [ -n "$PLUGIN_SITE_ID" ] && [ -n "$PLUGIN_TOKEN" ]
then
2020-01-29 01:10:17 +00:00
NETLIFY_SITE="--prod -a $PLUGIN_TOKEN -s $PLUGIN_SITE_ID"
2018-02-15 20:08:23 +00:00
echo "> Deploying on Netlify…" &&
netlify deploy $NETLIFY_SITE $NETLIFY_DEPLOY_OPTIONS;
2018-02-15 20:08:23 +00:00
else
echo "> Error! site_id and token are required"
2018-02-15 21:11:09 +00:00
exit 1
2018-02-15 20:08:23 +00:00
fi
if [ -n "$PLUGIN_SITE_NAME" ]
then
NETLIFY_UPDATE_OPTIONS="${NETLIFY_UPDATE_OPTIONS} -n ${PLUGIN_SITE_NAME}"
fi
if [ -n "$PLUGIN_DOMAIN" ]
then
NETLIFY_UPDATE_OPTIONS="${NETLIFY_UPDATE_OPTIONS} -d ${PLUGIN_DOMAIN}"
fi
if [ -n "$PLUGIN_SITE_NAME" ] || [ -n "$PLUGIN_DOMAIN" ]
then
echo "> Updating your Netlify site…" &&
netlify $NETLIFY_SITE update $NETLIFY_UPDATE_OPTIONS;
2018-02-15 20:08:23 +00:00
fi
2018-02-15 20:43:33 +00:00
rc=$?;
if [[ $rc != 0 ]]
2018-02-15 20:43:33 +00:00
then
echo "> non-zero exit code $rc" &&
exit $rc
else
echo $'\n'"> Successfully deployed!"$'\n'
2020-01-29 01:03:33 +00:00
fi