From c3eb4af3f672c23092c32ad833812bb1d280f5d1 Mon Sep 17 00:00:00 2001 From: Kristian Freeman Date: Fri, 11 Oct 2019 14:25:47 -0500 Subject: [PATCH] Switch to inputs --- action.yml | 7 +++++++ entrypoint.sh | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/action.yml b/action.yml index 666cce4..4b7cb0d 100644 --- a/action.yml +++ b/action.yml @@ -3,3 +3,10 @@ description: 'Cloudflare Workers Deploy' runs: using: 'docker' image: 'Dockerfile' +inputs: + apiKey: + description: "Your Cloudflare API Key" + required: true + email: + description: "Your Cloudflare Email" + required: true diff --git a/entrypoint.sh b/entrypoint.sh index 678248d..5e72747 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,25 +6,36 @@ export HOME="/github/workspace" export NVM_DIR="/github/workspace/nvm" export WRANGLER_HOME="/github/workspace" -mkdir -p "$HOME/.wrangler" -chmod -R 777 "$HOME/.wrangler" +function install_nvm() { + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" +} -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +function main() { + mkdir -p "$HOME/.wrangler" + chmod -R 777 "$HOME/.wrangler" -if [ -n "$CLOUDFLARE_API_KEY" ]; then - echo "CLOUDFLARE_API_KEY env var needs to be set. Add this field in the 'Secrets' section of your repo's settings." - exit 1 -fi + install_nvm -if [ -n "$CLOUDFLARE_EMAIL" ]; then - echo "CLOUDFLARE_EMAIL env var needs to be set. Add this field in the 'Secrets' section of your repo's settings." - exit 1 -fi + sanitize "${INPUT_EMAIL}" "email" + export CLOUDFLARE_EMAIL="$INPUT_EMAIL" + sanitize "${INPUT_APIKEY}" "apiKey" + export CLOUDFLARE_API_KEY="$INPUT_APIKEY" -npm i @cloudflare/wrangler -g -npm i + npm i @cloudflare/wrangler -g + npm i -wrangler whoami -wrangler publish + wrangler whoami + wrangler publish +} + +# h/t https://github.com/elgohr/Publish-Docker-Github-Action +function sanitize() { + if [ -z "${1}" ]; then + >&2 echo "Unable to find the ${2}. Did you set with.${2}?" + exit 1 + fi +} + +main