From 81902a0b3c58db26fdf95c5704bcf0e79f1bbf9a Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Halili Date: Fri, 5 May 2023 08:55:24 +0000 Subject: [PATCH] fix(scripts): :hammer: patch scripts for environment detection stuff [skip ci] Signed-off-by: Andrei Jiroh Halili --- bin/build.sh | 29 +++++++++++++++++++++++ bin/deploykit-pages.sh | 52 ++++++++++++++++++++++++++++++++++++++++++ bin/localdev.sh | 5 ++-- 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100755 bin/build.sh create mode 100755 bin/deploykit-pages.sh diff --git a/bin/build.sh b/bin/build.sh new file mode 100755 index 0000000..fdeb42c --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -e +if [[ $DEBUG != "" ]]; then + set -x +fi + +_root_directory_git=$(git rev-parse --show-toplevel) +TARGET_DIR=${TARGET_DIR:-"$PWD/public"} + +## source vars from .env first ## +export "$(xargs < "$_root_directory_git/.env")" + +warn() { + echo "warning: $*" +} + +error() { + echo "error: $*" +} + +if [[ ! -d .venv ]]; then + python3 -m venv .venv + "$_root_directory_git/.venv/bin/pip3" install -r requirements.txt --upgrade +fi + +"$_root_directory_git/.venv/bin/mkdocs" build \ + -d "$TARGET_DIR" \ + --use-directory-urls \ + --verbose \ No newline at end of file diff --git a/bin/deploykit-pages.sh b/bin/deploykit-pages.sh new file mode 100755 index 0000000..ecf0d69 --- /dev/null +++ b/bin/deploykit-pages.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +set -e +if [[ $DEBUG != "" ]]; then + set -x +fi + +## source vars from .env first ## +_root_directory_git=$(git rev-parse --show-toplevel) +export "$(xargs < "$_root_directory_git/.env")" + +_branch_name_git=$(git rev-parse --abbrev-ref HEAD) +_commit_sha=$(git rev-parse HEAD) +_commit_sha_short=$(git rev-parse --short HEAD) +_command_prefix="npx wrangler pages publish $_root_directory_git/public --project-name $CF_PAGES_PROJECT_NAME --branch $_branch_name_git --commit-hash $_commit_sha" + +warn() { + echo "warning: $*" +} + +error() { + echo "error: $*" +} + +info() { + echo "info: $*" +} + +if [[ $_branch_name_git == "main" ]]; then + DEPLOY_COMMAND="$_command_prefix --env production" +elif [[ $CI_PIPELINE_SOURCE == "merge_request" ]]; then + DEPLOY_COMMAND="$_command_prefix --env pr-#CI_MERGE_REQUEST_ID" +fi + +if ! git diff-index --quiet HEAD -- && [[ $FF_DIRTY_DEPLOY != "true" ]]; then + error Possible dirty working directory, aborting for safety reasons... + info To deploy while still dirty, set FF_DIRTY_DEPLOY=true on next invocation. + exit 1 +fi + +if [[ ! -d "$_root_directory_git/public" ]]; then + bash "$_root_directory_git/bin/build.sh" +fi + +if [[ $FF_DIRTY_DEPLOY == "true" ]]; then + $DEPLOY_COMMAND --commit-dirty +else + ${DEPLOY_COMMAND:-"$_command_prefix"} +fi + +if [[ $DEBUG != "" ]]; then + set +x +fi \ No newline at end of file diff --git a/bin/localdev.sh b/bin/localdev.sh index 1e3818a..b00984b 100755 --- a/bin/localdev.sh +++ b/bin/localdev.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash -if [ ! -f "$PWD/.venv/bin/mkdocs" ]; then +if [ ! -f "$PWD/.venv/bin/mkdocs" ] || [ $FF_DEPS_REFRESH != "true" ]; then "$PWD/.venv/bin/pip3" install -r requirements.txt fi -"$PWD/.venv/bin/mkdocs" serve \ No newline at end of file +# enable embeding commit info in previews +FF_ENABLE_COMMIT_DATA=true "$PWD/.venv/bin/mkdocs" serve \ No newline at end of file