Add Gitea webhook auto-deploy scripts and config template.
Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
50
scripts/gitea-deploy.sh
普通文件
50
scripts/gitea-deploy.sh
普通文件
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Gitea Webhook 触发的自动部署(在服务器上由 gitea_webhook.php 调用)
|
||||
set -euo pipefail
|
||||
|
||||
DEPLOY_PATH="${DEPLOY_PATH:-/www/wwwroot/chufang.gynhc.com}"
|
||||
DEPLOY_BRANCH="${DEPLOY_BRANCH:-main}"
|
||||
RUN_COMPOSER="${RUN_COMPOSER:-0}"
|
||||
LOG_DIR="${DEPLOY_PATH}/deploy/logs"
|
||||
mkdir -p "$LOG_DIR"
|
||||
LOG_FILE="${LOG_DIR}/deploy-$(date +%Y%m%d).log"
|
||||
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
|
||||
}
|
||||
|
||||
log "=== Deploy start ==="
|
||||
log "DEPLOY_PATH=$DEPLOY_PATH branch=$DEPLOY_BRANCH"
|
||||
|
||||
cd "$DEPLOY_PATH"
|
||||
|
||||
if [[ ! -d .git ]]; then
|
||||
log "ERROR: not a git repository"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git config --global --add safe.directory "$DEPLOY_PATH" 2>/dev/null || true
|
||||
|
||||
git fetch origin "$DEPLOY_BRANCH"
|
||||
git reset --hard "origin/${DEPLOY_BRANCH}"
|
||||
log "Git updated to origin/${DEPLOY_BRANCH} @ $(git rev-parse --short HEAD)"
|
||||
|
||||
if [[ "$RUN_COMPOSER" == "1" ]] && [[ -f composer.json ]]; then
|
||||
if command -v composer >/dev/null 2>&1; then
|
||||
log "Running composer install..."
|
||||
composer install --no-dev --optimize-autoloader --no-interaction 2>&1 | tee -a "$LOG_FILE"
|
||||
else
|
||||
log "WARN: composer not found, skip"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -d runtime/cache ]]; then
|
||||
find runtime/cache -type f -delete 2>/dev/null || true
|
||||
log "Cleared runtime/cache"
|
||||
fi
|
||||
if [[ -d runtime/temp ]]; then
|
||||
find runtime/temp -type f -delete 2>/dev/null || true
|
||||
log "Cleared runtime/temp"
|
||||
fi
|
||||
|
||||
log "=== Deploy done ==="
|
||||
在新工单中引用
屏蔽一个用户