name: Deploy to Server on: [push] jobs: deploy: runs-on: ubuntu steps: - name: Download and deploy code uses: https://gitea.com/actions/appleboy-ssh-action@v1.0.3 with: host: 6.6.6.66 username: quant password: 123quant-speed script: | TARGET_DIR="/home/quant/data/dev/deploy" SUDO_PASSWORD="123quant-speed" API_BASE="https://gitea.tangledup-ai.com/api/v1" REPO="quant-speed-AI/Scoring-System" AUTH="sdd:zsj981107" BRANCH="main" echo "===== 停止并清理 Docker =====" cd $TARGET_DIR echo $SUDO_PASSWORD | sudo -S docker compose down echo "===== 通过 API 下载代码 =====" # 获取文件树 FILE_LIST=$(curl -sk -u "$AUTH" "$API_BASE/repos/$REPO/git/trees/$BRANCH?recursive=true" | python3 -c " import json,sys data = json.load(sys.stdin) for item in data.get('tree', []): if item['type'] == 'blob': print(item['path']) ") echo "共发现 $(echo "$FILE_LIST" | wc -l) 个文件" # 逐个下载文件 echo "$FILE_LIST" | while read -r filepath; do # 跳过不需要的文件 case "$filepath" in backend/.env|backend/media/*|.git/*) continue ;; esac mkdir -p "$TARGET_DIR/$(dirname "$filepath")" curl -sk -u "$AUTH" -o "$TARGET_DIR/$filepath" \ "$API_BASE/repos/$REPO/raw/$filepath?ref=$BRANCH" done echo "代码更新完成" echo "===== 配置环境变量 =====" cat > $TARGET_DIR/backend/.env <