From f2fa57e7bbc1b6021991dc8da0efeb209223c125 Mon Sep 17 00:00:00 2001 From: sasha-astiadi Date: Tue, 2 Sep 2025 13:24:15 +0200 Subject: [PATCH] Implement branch-aware deployment: auto-detect environment to prevent merge conflicts - Auto-detects git branch (master/development/other) - Sets correct base_url for each environment: * master -> https://www.mycelium.threefold.io/ (production) * development -> https://www2.mycelium.threefold.io/ (staging) * other -> /mycelium/ (local development) - Eliminates merge conflicts between staging and production - Enables seamless branch merging workflow --- build.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index 209979e..ea445c6 100755 --- a/build.sh +++ b/build.sh @@ -43,14 +43,28 @@ echo "Compiling tailwindcss and building zola project..." rm -rf public static/css ./tailwindcss -i css/index.css -o ./static/css/index.css --minify +# Auto-detect deployment environment based on git branch +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +echo "Detected git branch: $CURRENT_BRANCH" -# echo "Building without prefix..." -# sed 's|base_url = "BASEURL"|base_url = "https://www.mycelium.threefold.io/"|' config.templ.toml > config.toml -# zola --root $ABS_DIR_OF_SCRIPT build -# rsync -avz --delete public/ "root@threefold.info:/root/hero/www/info/$PREFIX/" +if [ "$CURRENT_BRANCH" = "master" ]; then + # Production deployment (www.mycelium.threefold.io) + echo "Building for PRODUCTION environment..." + BASE_URL="https://www.mycelium.threefold.io/" + DEPLOY_PATH="root@threefold.info:/root/hero/www/info/$PREFIX/" +elif [ "$CURRENT_BRANCH" = "development" ]; then + # Staging deployment (www2.mycelium.threefold.io) + echo "Building for STAGING environment..." + BASE_URL="https://www2.mycelium.threefold.io/" + DEPLOY_PATH="root@threefold.info:/root/hero/www/info/$PREFIX/" +else + # Fallback for other branches (local development mode) + echo "Building for LOCAL/OTHER branch environment..." + BASE_URL="/mycelium/" + DEPLOY_PATH="${HOME}/hero/var/www/$PREFIX/" +fi -echo "Building with prefix: /$PREFIX/" -sed 's|base_url = "BASEURL"|base_url = "/mycelium/"|' config.templ.toml > config.toml +echo "Using base_url: $BASE_URL" +sed "s|base_url = \"BASEURL\"|base_url = \"$BASE_URL\"|" config.templ.toml > config.toml zola --root $ABS_DIR_OF_SCRIPT build -rsync -rav --delete public/ "${HOME}/hero/var/www/$PREFIX/" - +rsync -avz --delete public/ "$DEPLOY_PATH"