Enhance deploy script: Add functions to ensure required commands (node, npm, git) are available in the PATH, improving reliability in non-interactive SSH sessions. This includes bootstrapping Node.js environment using nvm if necessary.
Some checks failed
Deploy miriamgemeinde / deploy (push) Failing after 2s
Some checks failed
Deploy miriamgemeinde / deploy (push) Failing after 2s
This commit is contained in:
22
deploy.sh
22
deploy.sh
@@ -9,6 +9,28 @@ NC="\033[0m"
|
|||||||
log() { echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $*${NC}"; }
|
log() { echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $*${NC}"; }
|
||||||
err() { echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] $*${NC}" 1>&2; }
|
err() { echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] $*${NC}" 1>&2; }
|
||||||
|
|
||||||
|
ensure_command() {
|
||||||
|
local cmd="$1"
|
||||||
|
command -v "$cmd" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap_node() {
|
||||||
|
# In non-interactive SSH sessions, node/npm might not be on PATH (e.g. nvm in .bashrc).
|
||||||
|
if ensure_command npm && ensure_command node; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [ -s "$HOME/.nvm/nvm.sh" ]; then
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$HOME/.nvm/nvm.sh"
|
||||||
|
# Prefer default alias if configured, otherwise keep current.
|
||||||
|
nvm use --silent default >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap_node
|
||||||
|
if ! ensure_command git; then err "git not found in PATH"; exit 127; fi
|
||||||
|
if ! ensure_command npm; then err "npm not found in PATH"; exit 127; fi
|
||||||
|
|
||||||
log "Fetching latest changes..."
|
log "Fetching latest changes..."
|
||||||
git fetch --all --prune || { err "git fetch failed"; exit 1; }
|
git fetch --all --prune || { err "git fetch failed"; exit 1; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user