From cb59dba8e6613cde506544bf568a73ed05b0f871 Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Sun, 15 Feb 2026 16:29:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=20CI/CD=20=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - knowledge-base 改为独立部署 - kb-web 只负责代码,不再恢复用户目录 - 仅备份恢复 config.php --- .gitea/workflows/ci.yml | 68 ++++++++--------------------------------- 1 file changed, 12 insertions(+), 56 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 8b0302a..0650b88 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -35,37 +35,22 @@ jobs: mkdir -p ${{ env.TEST_DIR }} cd ${{ env.TEST_DIR }} - # 备份需要保留的文件 - BACKUP_DIR="/tmp/kb-web-backup-$$" - mkdir -p $BACKUP_DIR - [ -f config.php ] && cp config.php $BACKUP_DIR/ - for dir in */; do - if [ -d "$dir" ] && [ "$dir" != "demo/" ]; then - cp -r "$dir" $BACKUP_DIR/ 2>/dev/null || true - fi - done + # 备份配置文件 + [ -f config.php ] && cp config.php /tmp/config.php.bak # 部署代码 if [ -d .git ]; then git fetch origin git checkout ${{ github.ref_name }} 2>/dev/null || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }} git reset --hard origin/${{ github.ref_name }} - # 清理未跟踪的文件(保留 .git 和备份目录) git clean -fd else git clone -b ${{ github.ref_name }} ssh://gitea-external/starmen1265/kb-web.git . fi - # 恢复配置和用户数据 - [ -f $BACKUP_DIR/config.php ] && cp $BACKUP_DIR/config.php . && chown www:www config.php - for dir in $BACKUP_DIR/*/; do - dirname=$(basename "$dir") - if [ "$dirname" != "demo" ] && [ "$dirname" != "deploy" ] && [ "$dirname" != "tests" ]; then - cp -r "$dir" . 2>/dev/null || true - fi - done + # 恢复配置文件 + [ -f /tmp/config.php.bak ] && cp /tmp/config.php.bak config.php && chown www:www config.php - rm -rf $BACKUP_DIR chown -R www:www ${{ env.TEST_DIR }} 2>/dev/null || true echo "✅ 测试环境部署完成" @@ -171,16 +156,8 @@ jobs: tar -czf $BACKUP_DIR/backup_$TIMESTAMP.tar.gz --exclude='.git' . 2>/dev/null || true cd $BACKUP_DIR && ls -t | tail -n +6 | xargs rm -f 2>/dev/null || true - # 备份配置和用户数据 - TEMP_DIR="/tmp/kb-web-prod-$$" - mkdir -p $TEMP_DIR - cd ${{ env.PROD_DIR }} - [ -f config.php ] && cp config.php $TEMP_DIR/ - for dir in */; do - if [ -d "$dir" ] && [ "$dir" != "demo/" ]; then - cp -r "$dir" $TEMP_DIR/ 2>/dev/null || true - fi - done + # 备份配置 + [ -f config.php ] && cp config.php /tmp/config.php.bak # 部署 cd ${{ env.PROD_DIR }} @@ -188,16 +165,9 @@ jobs: git reset --hard origin/main git clean -fd - # 恢复配置和用户数据 - [ -f $TEMP_DIR/config.php ] && cp $TEMP_DIR/config.php . && chown www:www config.php - for dir in $TEMP_DIR/*/; do - dirname=$(basename "$dir") - if [ "$dirname" != "demo" ] && [ "$dirname" != "deploy" ] && [ "$dirname" != "tests" ]; then - cp -r "$dir" . 2>/dev/null || true - fi - done + # 恢复配置 + [ -f /tmp/config.php.bak ] && cp /tmp/config.php.bak config.php && chown www:www config.php - rm -rf $TEMP_DIR chown -R www:www ${{ env.PROD_DIR }} 2>/dev/null || true echo "✅ 正式环境部署完成" @@ -215,30 +185,16 @@ jobs: script: | cd ${{ env.PROD_DIR }} - # 备份配置和用户数据 - TEMP_DIR="/tmp/kb-web-prod-$$" - mkdir -p $TEMP_DIR - [ -f config.php ] && cp config.php $TEMP_DIR/ - for dir in */; do - if [ -d "$dir" ] && [ "$dir" != "demo/" ]; then - cp -r "$dir" $TEMP_DIR/ 2>/dev/null || true - fi - done + # 备份配置 + [ -f config.php ] && cp config.php /tmp/config.php.bak # 部署 git fetch origin git reset --hard origin/main git clean -fd - # 恢复配置和用户数据 - [ -f $TEMP_DIR/config.php ] && cp $TEMP_DIR/config.php . && chown www:www config.php - for dir in $TEMP_DIR/*/; do - dirname=$(basename "$dir") - if [ "$dirname" != "demo" ] && [ "$dirname" != "deploy" ] && [ "$dirname" != "tests" ]; then - cp -r "$dir" . 2>/dev/null || true - fi - done + # 恢复配置 + [ -f /tmp/config.php.bak ] && cp /tmp/config.php.bak config.php && chown www:www config.php - rm -rf $TEMP_DIR chown -R www:www ${{ env.PROD_DIR }} 2>/dev/null || true echo "✅ 正式环境已更新"