From e2a393e4be43ec21edc6dcea310c7245e25cb601 Mon Sep 17 00:00:00 2001 From: Ember Date: Thu, 30 Jan 2025 01:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8git=20checkout=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/buildsite.yaml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/buildsite.yaml b/.gitea/workflows/buildsite.yaml index 9e7c366..cd88a3d 100644 --- a/.gitea/workflows/buildsite.yaml +++ b/.gitea/workflows/buildsite.yaml @@ -8,10 +8,20 @@ jobs: deploy: runs-on: self-hosted steps: - - name: Checkout Repository - uses: git.xn--xhq44jb2fzpc.com/ember/checkout@main + - name: Deploy Code to Web Root + run: | + # 设置 Git 仓库目录和工作目录 + GIT_DIR=/opt/gitea/data/gitea-repositories/ember/front + WORK_TREE=/www/wwwroot/front/public - - name: Sync Files to Web Root - run: rsync -avz --delete ./ $WEB_ROOT - env: - WEB_ROOT: /www/wwwroot/front/public \ No newline at end of file + # 确保 GIT_DIR 目录存在(首次运行需要手动初始化) + if [ ! -d "$GIT_DIR" ]; then + git clone --bare https://gitea.xn--xhq44jb2fzpc.com/ember/front.git $GIT_DIR + fi + + # 获取最新代码并强制检出到网站根目录 + git --git-dir=$GIT_DIR --work-tree=$WORK_TREE fetch origin master + git --git-dir=$GIT_DIR --work-tree=$WORK_TREE reset --hard origin/master + + # 可选:记录日志 + echo "Code deployed to $WORK_TREE at $(date)" >> /opt/gitea/data/gitea-repositories/ember/front/log/git-deploy.log