2019-10-11 19:22:20 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
2019-10-07 22:19:11 +02:00
|
|
|
|
2019-10-11 20:01:57 +02:00
|
|
|
export HOME="/github/workspace"
|
|
|
|
export WRANGLER_HOME="/github/workspace"
|
|
|
|
|
2019-10-11 21:30:51 +02:00
|
|
|
mkdir -p "$HOME/.wrangler"
|
2019-10-15 17:52:07 +02:00
|
|
|
chmod -R 770 "$HOME/.wrangler"
|
2019-10-11 21:30:51 +02:00
|
|
|
|
2019-11-22 17:27:40 +01:00
|
|
|
export API_CREDENTIALS=""
|
|
|
|
|
|
|
|
# If an API token is detected as input
|
|
|
|
if [ -n "$INPUT_APITOKEN" ]
|
|
|
|
then
|
|
|
|
export CF_API_TOKEN="$INPUT_APITOKEN"
|
|
|
|
export API_CREDENTIALS="API Token"
|
|
|
|
fi
|
2019-10-14 22:04:41 +02:00
|
|
|
|
2019-11-22 17:27:40 +01:00
|
|
|
# If an API key and email are detected as input
|
|
|
|
if [ -n "$INPUT_APIKEY" ] && [ -n "$INPUT_EMAIL" ]
|
|
|
|
then
|
|
|
|
export CF_EMAIL="$INPUT_EMAIL"
|
|
|
|
export CF_API_KEY="$INPUT_APIKEY"
|
|
|
|
export API_CREDENTIALS="Email and API Key"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$INPUT_APIKEY" ] && [ -z "$INPUT_EMAIL" ]
|
|
|
|
then
|
|
|
|
echo "Provided an API key without an email for authentication. Please pass in 'apiKey' and 'email' to the action."
|
|
|
|
fi
|
2019-10-11 21:30:51 +02:00
|
|
|
|
2019-11-22 17:27:40 +01:00
|
|
|
if [ -z "$INPUT_APIKEY" ] && [ -n "$INPUT_EMAIL" ]
|
|
|
|
then
|
|
|
|
echo "Provided an email without an API key for authentication. Please pass in 'apiKey' and 'email' to the action."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$API_CREDENTIALS" ]
|
|
|
|
then
|
|
|
|
>&2 echo "Unable to find authentication details. Please pass in an 'apiToken' as an input to the action, or a legacy 'apiKey' and 'email'."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Using $API_CREDENTIALS authentication"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If a Wrangler version is detected as input
|
|
|
|
if [ -z "$INPUT_WRANGLERVERSION" ]
|
|
|
|
then
|
|
|
|
npm i @cloudflare/wrangler -g
|
|
|
|
else
|
|
|
|
npm i "@cloudflare/wrangler@$INPUT_WRANGLERVERSION" -g
|
|
|
|
fi
|
2019-10-14 22:24:54 +02:00
|
|
|
|
2019-11-22 17:27:40 +01:00
|
|
|
# If a working directory is detected as input
|
|
|
|
if [ -n "$INPUT_WORKINGDIRECTORY" ]
|
2019-11-07 22:15:49 +01:00
|
|
|
then
|
2019-11-22 17:27:40 +01:00
|
|
|
cd "$INPUT_WORKINGDIRECTORY"
|
2019-11-07 22:15:49 +01:00
|
|
|
fi
|
|
|
|
|
2019-12-09 18:34:35 +01:00
|
|
|
# If an environment is detected as input
|
2019-10-14 22:24:54 +02:00
|
|
|
if [ -z "$INPUT_ENVIRONMENT" ]
|
|
|
|
then
|
|
|
|
wrangler publish
|
2019-10-14 22:33:15 +02:00
|
|
|
else
|
|
|
|
wrangler publish -e "$INPUT_ENVIRONMENT"
|
2019-10-14 22:24:54 +02:00
|
|
|
fi
|
2019-10-11 21:30:51 +02:00
|
|
|
|
2019-11-22 17:27:40 +01:00
|
|
|
# If a working directory is detected as input, revert to the
|
|
|
|
# original directory before continuing with the workflow
|
|
|
|
if [ -n "$INPUT_WORKINGDIRECTORY" ]
|
2019-11-07 22:15:49 +01:00
|
|
|
then
|
|
|
|
cd $HOME
|
|
|
|
fi
|