Deploy: stop first when files in the install were changed by hand (1.52.2)
A setup wizard run on one server added files to backend/src that the backend build picked up, so the deploy failed part-way and rolled back. deploy.sh now lists files git reports as changed or added (ignored files and the PM2 config don't count) and stops before backing up or checking out. --check runs only that; ALLOW_LOCAL_CHANGES=1 deploys anyway; the script also runs from a copy outside the install (the folder you're in). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,20 +6,34 @@
|
||||
# Usage (on the server, from the repo folder):
|
||||
# bash scripts/deploy.sh # the latest main
|
||||
# bash scripts/deploy.sh v1.37.3 # a tagged release
|
||||
# bash scripts/deploy.sh --check # only check for files changed by hand (changes nothing)
|
||||
#
|
||||
# PM2 uses this install's own ecosystem.config.js (app names, ports). It isn't in git, so
|
||||
# deploys never change it; the first deploy creates it from ecosystem.config.example.js.
|
||||
#
|
||||
# A deploy stops before touching anything when files in the repo folder were changed or added
|
||||
# by hand: they'd be built into the release (or block the checkout). ALLOW_LOCAL_CHANGES=1
|
||||
# deploys anyway. Ignored files (.env, uploads, backups, the PM2 config) never count.
|
||||
set -Eeuo pipefail
|
||||
|
||||
# The checkout below replaces this file, and bash reads a script as it runs — so run from a
|
||||
# copy that can't change underneath us.
|
||||
if [ -z "${HOPE_DEPLOY_COPY:-}" ]; then
|
||||
DIR="${HOPE_DEPLOY_DIR:-$(cd "$(dirname "$0")/.." && pwd)}"
|
||||
# Run from a copy outside the repo (e.g. downloaded to /tmp): the folder you're in.
|
||||
if [ ! -d "$DIR/.git" ] || [ ! -d "$DIR/backend" ]; then DIR="$PWD"; fi
|
||||
COPY="$(mktemp)"
|
||||
cp "$0" "$COPY"
|
||||
HOPE_DEPLOY_COPY=1 HOPE_DEPLOY_DIR="$(cd "$(dirname "$0")/.." && pwd)" exec bash "$COPY" "$@"
|
||||
HOPE_DEPLOY_COPY=1 HOPE_DEPLOY_DIR="$DIR" exec bash "$COPY" "$@"
|
||||
fi
|
||||
|
||||
cd "$HOPE_DEPLOY_DIR"
|
||||
if [ ! -d .git ] || [ ! -d backend ]; then
|
||||
echo "!!> $PWD isn't a Cross Events install. Run this from the install's folder (e.g. /var/www/hope-events)."
|
||||
exit 1
|
||||
fi
|
||||
CHECK_ONLY=0
|
||||
if [ "${1:-}" = "--check" ]; then CHECK_ONLY=1; shift; fi
|
||||
TARGET="${1:-main}"
|
||||
PREVIOUS="$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)"
|
||||
|
||||
@@ -51,6 +65,30 @@ checkout() {
|
||||
restore_pm2_config
|
||||
}
|
||||
|
||||
# Files changed or added by hand (anything git reports, apart from this install's PM2 config,
|
||||
# which releases before 1.37.4 tracked). Ignored files — .env, uploads, backups — aren't listed.
|
||||
local_changes() {
|
||||
git status --porcelain --untracked-files=all | awk -v keep="$PM2_CONFIG" 'substr($0, 4) != keep'
|
||||
}
|
||||
|
||||
CHANGES="$(local_changes)"
|
||||
if [ -n "$CHANGES" ]; then
|
||||
echo "!!> Files in $PWD were changed or added by hand:"
|
||||
echo "$CHANGES" | sed 's/^/ /'
|
||||
echo " A release would build them in (or refuse to replace them), so the deploy can fail."
|
||||
echo " Move added files (??) somewhere outside this folder, and put changed ones ( M) back with"
|
||||
echo " \"git checkout -- <file>\" — after checking nothing in them is needed."
|
||||
if [ "$CHECK_ONLY" = 1 ]; then exit 1; fi
|
||||
if [ "${ALLOW_LOCAL_CHANGES:-}" != 1 ]; then
|
||||
echo " Nothing was changed. To deploy anyway: ALLOW_LOCAL_CHANGES=1 bash scripts/deploy.sh $TARGET"
|
||||
exit 1
|
||||
fi
|
||||
echo " ALLOW_LOCAL_CHANGES=1 — deploying anyway."
|
||||
elif [ "$CHECK_ONLY" = 1 ]; then
|
||||
echo "==> No files changed by hand in $PWD — ready to deploy."
|
||||
fi
|
||||
if [ "$CHECK_ONLY" = 1 ]; then exit 0; fi
|
||||
|
||||
echo "==> Deploying $TARGET (currently $PREVIOUS)"
|
||||
|
||||
# Node 20 reached end of life in April 2026 (no more security fixes). Releases still run on it,
|
||||
|
||||
Reference in New Issue
Block a user