Allow deploy branch selection

This commit is contained in:
rucki
2026-09-11 17:50:38 +02:00
parent 504f58aa36
commit 854b0035ec
2 changed files with 28 additions and 2 deletions
+3
View File
@@ -183,3 +183,6 @@ cython_debug/
# Local my2dos project API config # Local my2dos project API config
.my2dos .my2dos
# Local deployment branch override
.deploy-branch
+25 -2
View File
@@ -7,6 +7,8 @@ set -euo pipefail
# #
# Optional: # Optional:
# DEPLOY_REMOTE=origin DEPLOY_BRANCH=main ./deploy.sh # DEPLOY_REMOTE=origin DEPLOY_BRANCH=main ./deploy.sh
# ./deploy.sh workspace-tenancy
# echo workspace-tenancy > .deploy-branch
# SKIP_PIP=1 ./deploy.sh # SKIP_PIP=1 ./deploy.sh
# SKIP_COLLECTSTATIC=1 ./deploy.sh # SKIP_COLLECTSTATIC=1 ./deploy.sh
# DEPLOY_RESTART_CMD="..." ./deploy.sh # DEPLOY_RESTART_CMD="..." ./deploy.sh
@@ -14,7 +16,19 @@ set -euo pipefail
cd "$(dirname "$0")" cd "$(dirname "$0")"
REMOTE="${DEPLOY_REMOTE:-origin}" REMOTE="${DEPLOY_REMOTE:-origin}"
BRANCH="${DEPLOY_BRANCH:-$(git branch --show-current 2>/dev/null || echo main)}" BRANCH_SOURCE="current branch"
if [[ $# -gt 0 && -n "${1:-}" ]]; then
BRANCH="$1"
BRANCH_SOURCE="command line"
elif [[ -n "${DEPLOY_BRANCH:-}" ]]; then
BRANCH="$DEPLOY_BRANCH"
BRANCH_SOURCE="DEPLOY_BRANCH"
elif [[ -f ".deploy-branch" && -n "$(tr -d '[:space:]' < .deploy-branch)" ]]; then
BRANCH="$(tr -d '[:space:]' < .deploy-branch)"
BRANCH_SOURCE=".deploy-branch"
else
BRANCH="$(git branch --show-current 2>/dev/null || echo main)"
fi
if [[ -x ".venv/bin/python" ]]; then if [[ -x ".venv/bin/python" ]]; then
PY=".venv/bin/python" PY=".venv/bin/python"
@@ -28,9 +42,18 @@ else
fi fi
echo "==> Deploy $(pwd)" echo "==> Deploy $(pwd)"
echo "==> Branch: ${BRANCH} (${BRANCH_SOURCE})"
echo "==> Python: $($PY --version)" echo "==> Python: $($PY --version)"
echo "==> Git Pull: ${REMOTE}/${BRANCH}" echo "==> Git Update: ${REMOTE}/${BRANCH}"
git fetch "$REMOTE" "$BRANCH" git fetch "$REMOTE" "$BRANCH"
CURRENT_BRANCH="$(git branch --show-current 2>/dev/null || true)"
if [[ "$CURRENT_BRANCH" != "$BRANCH" ]]; then
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
git checkout "$BRANCH"
else
git checkout -b "$BRANCH" --track "$REMOTE/$BRANCH"
fi
fi
git pull --ff-only "$REMOTE" "$BRANCH" git pull --ff-only "$REMOTE" "$BRANCH"
if [[ "${SKIP_PIP:-0}" != "1" ]]; then if [[ "${SKIP_PIP:-0}" != "1" ]]; then