npm ci --omit=dev excluded TypeScript (devDep) causing the build step to fail. Build needs devDeps; runtime doesn't because it runs compiled dist/. Co-Authored-By: Paperclip <[email protected]>
68 lines
1.9 KiB
Bash
Executable File
68 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Lightweight Gitea webhook handler — triggered by POST from Gitea on push to main.
|
|
# Deploy: run this as a cron, or via a minimal webhook receiver (e.g. adnanh/webhook).
|
|
# Example crontab (pulls and redeploys every 5 min if new commits):
|
|
# */5 * * * * /opt/news-platform/deploy/scripts/webhook-deploy.sh >> /var/log/news-deploy.log 2>&1
|
|
set -euo pipefail
|
|
|
|
APP_DIR="/opt/news-platform"
|
|
LOCK_FILE="/tmp/news-platform-deploy.lock"
|
|
LOG_TAG="webhook-deploy"
|
|
|
|
log() { echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) [$LOG_TAG] $*"; }
|
|
|
|
# Prevent concurrent deploys
|
|
if [ -f "$LOCK_FILE" ]; then
|
|
log "Deploy already in progress, skipping."
|
|
exit 0
|
|
fi
|
|
touch "$LOCK_FILE"
|
|
trap 'rm -f "$LOCK_FILE"' EXIT
|
|
|
|
# Fetch remote state
|
|
cd "$APP_DIR"
|
|
git fetch origin main --quiet
|
|
|
|
LOCAL=$(git rev-parse HEAD)
|
|
REMOTE=$(git rev-parse origin/main)
|
|
|
|
if [ "$LOCAL" = "$REMOTE" ]; then
|
|
log "Already up-to-date ($LOCAL), nothing to deploy."
|
|
exit 0
|
|
fi
|
|
|
|
log "New commit detected: $LOCAL → $REMOTE. Starting deploy..."
|
|
|
|
git reset --hard origin/main
|
|
|
|
# Rebuild bridge if changed
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^bridge/"; then
|
|
log "Bridge changed — rebuilding..."
|
|
cd "$APP_DIR/bridge"
|
|
npm ci --silent
|
|
npm run build
|
|
systemctl restart news-bridge
|
|
log "Bridge restarted."
|
|
fi
|
|
|
|
# Rebuild frontend if changed
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^frontend/"; then
|
|
log "Frontend changed — rebuilding..."
|
|
cd "$APP_DIR/frontend"
|
|
npm ci --silent
|
|
npm run build
|
|
systemctl restart news-frontend
|
|
log "Frontend restarted."
|
|
fi
|
|
|
|
# Reload nginx if config changed
|
|
if git diff --name-only "$LOCAL" "$REMOTE" | grep -q "^deploy/nginx/"; then
|
|
log "Nginx config changed — reloading..."
|
|
cp "$APP_DIR/deploy/nginx/newsproject.bitreport.pt.conf" \
|
|
/etc/nginx/sites-available/newsproject.bitreport.pt.conf
|
|
nginx -t && systemctl reload nginx
|
|
log "Nginx reloaded."
|
|
fi
|
|
|
|
log "Deploy complete at $REMOTE."
|