Skip to content

Commit

Permalink
chore: add ensure-cloudflare-pages-exists script
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmaynes committed Dec 30, 2023
1 parent 54e196e commit 4611ee2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -24,7 +24,11 @@ download_career_files:

artifact: install build test download_career_files

deploy: artifact
ensure_cloudflare_page_exists:
chmod +x ./script/ensure-cloudflare-pages-exists.sh
./script/ensure-cloudflare-pages-exists.sh "tjmaynes-site"

deploy: artifact ensure_cloudflare_page_exists
chmod +x ./script/cloudflare-pages-deploy.sh
./script/cloudflare-pages-deploy.sh "./public" "tjmaynes-site"

Expand Down
34 changes: 34 additions & 0 deletions script/ensure-cloudflare-pages-exists.sh
@@ -0,0 +1,34 @@
#!/bin/bash

set -e

CLOUDFLARE_PAGES_PROJECT_NAME=$1

function check_requirements() {
if [[ -z "$(command -v node)" ]]; then
echo "Please install 'node' program before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_ACCOUNT_ID" ]]; then
echo "Please ensure environment variable 'CLOUDFLARE_ACCOUNT_ID' exists before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_API_TOKEN" ]]; then
echo "Please ensure environment variable 'CLOUDFLARE_API_TOKEN' exists before running this script"
exit 1
elif [[ -z "$CLOUDFLARE_PAGES_PROJECT_NAME" ]]; then
echo "Arg 1 for script 'CLOUDFLARE_PAGES_PROJECT_NAME' was not given..."
exit 1
fi
}

function main() {
check_requirements

if ./node_modules/.bin/wrangler pages project list | grep -q "$CLOUDFLARE_PAGES_PROJECT_NAME"; then
echo "Cloudflare pages project '$CLOUDFLARE_PAGES_PROJECT_NAME' exists..."
else
echo "Cloudflare pages project '$CLOUDFLARE_PAGES_PROJECT_NAME' does not exist..."
./node_modules/.bin/wrangler pages project create "$CLOUDFLARE_PAGES_PROJECT_NAME" --production-branch main
fi
}

main

0 comments on commit 4611ee2

Please sign in to comment.