drone-netlify/script.sh

61 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=""
2022-10-20 21:58:05 +00:00
if [ -n "$PLUGIN_PROD" ] && [ "$PLUGIN_PROD" != false ]
2018-02-15 20:08:23 +00:00
then
2022-10-20 21:58:05 +00:00
NETLIFY_DEPLOY_OPTIONS="--prod"
2018-02-15 20:08:23 +00:00
fi
if [ -n "$PLUGIN_PATH" ]
then
2022-10-20 21:58:05 +00:00
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --dir ${PLUGIN_PATH}"
2018-02-15 20:08:23 +00:00
else
2022-10-20 21:58:05 +00:00
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --dir ./"
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
2022-10-20 21:58:05 +00:00
if [ -n "$PLUGIN_ALIAS" ]
2018-02-15 20:08:23 +00:00
then
2022-10-20 21:58:05 +00:00
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --alias ${PLUGIN_ALIAS}"
elif [ -n "$DRONE_COMMIT_SHA" ]
2018-02-15 20:08:23 +00:00
then
2022-10-20 21:58:05 +00:00
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --alias ${DRONE_COMMIT_SHA}"
2018-02-15 20:08:23 +00:00
fi
2022-10-20 21:58:05 +00:00
message="Automated deploy from build.mat.services
(${DRONE_COMMIT_BRANCH} @ ${DRONE_COMMIT_SHA})
$DRONE_COMMIT_MESSAGE"
NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} --message '$message'"
2018-02-15 20:08:23 +00:00
2022-10-20 21:58:05 +00:00
if [ -n "$PLUGIN_SITE" ]
2018-02-15 20:08:23 +00:00
then
2022-10-20 21:58:05 +00:00
NETLIFY_SITE="--auth $PLUGIN_TOKEN --site $PLUGIN_SITE"
echo "> Deploying on Netlify…" &&
netlify deploy "$NETLIFY_SITE" "$NETLIFY_DEPLOY_OPTIONS";
else
echo "> Error! site (site ID or name) and token are required"
exit 1
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