drone-netlify/script.sh

56 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -e
NETLIFY_SITE=""
NETLIFY_DEPLOY_OPTIONS=""
if [ -n "$PLUGIN_PROD" ] && [ "$PLUGIN_PROD" != false ]
then
NETLIFY_DEPLOY_OPTIONS="--prod"
fi
if [ -n "$PLUGIN_PATH" ]
then
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --dir ${PLUGIN_PATH}"
else
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --dir ./"
fi
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
if [ -n "$PLUGIN_ALIAS" ]
then
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --alias ${PLUGIN_ALIAS}"
elif [ -n "$DRONE_COMMIT_SHA" ]
then
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --alias ${DRONE_COMMIT_SHA}"
fi
if [ -n "$PLUGIN_SITE" ]
then
NETLIFY_SITE="--auth $PLUGIN_TOKEN --site $PLUGIN_SITE"
echo "> Deploying on Netlify…" &&
netlify deploy $NETLIFY_SITE $NETLIFY_DEPLOY_OPTIONS --message "$DRONE_COMMIT_MESSAGE";
else
echo "> Error! site (site ID or name) and token are required"
exit 1
fi
rc=$?;
if [[ $rc != 0 ]]
then
echo "> non-zero exit code $rc" &&
exit $rc
else
echo $'\n'"> Successfully deployed!"$'\n'
fi