front/.gitea/workflows/buildsite.yaml
2025-01-30 10:30:11 +08:00

63 lines
1.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Deploy Incremental Updates to NEUxiaozhan
on:
push:
branches: [master]
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Setup local repository
shell: bash
run: |
# 定义本地仓库路径(根据实际情况调整)
REPO_PATH="/opt/gitea/data/gitea-repositories/ember/front.git"
WORK_TREE="/tmp/gitea_worktree"
# 创建临时工作目录
mkdir -p $WORK_TREE
# 使用git worktree挂载最新代码
git --git-dir=$REPO_PATH worktree add --force $WORK_TREE HEAD
- name: Detect changed files
shell: bash
run: |
cd /tmp/gitea_worktree
# 智能识别首次提交情况
if git rev-parse HEAD^ >/dev/null 2>&1; then
DIFF_REF="HEAD^..HEAD"
else
DIFF_REF="HEAD"
fi
# 生成带完整路径的变更文件列表
git diff --name-only --diff-filter=d $DIFF_REF > /tmp/changed_files.txt
- name: Sync incremental files
shell: bash
run: |
# 配置路径参数
SOURCE_DIR="/tmp/gitea_worktree"
TARGET_DIR="/www/wwwroot/front/public"
# 使用rsync进行增量同步
rsync -avR --remove-source-files \
--files-from=/tmp/changed_files.txt \
$SOURCE_DIR/ \
$TARGET_DIR/
# 权限设置根据Web服务器用户调整
# sudo chown -R www:www $TARGET_DIR
# sudo find $TARGET_DIR -type d -exec chmod 755 {} \;
# sudo find $TARGET_DIR -type f -exec chmod 644 {} \;
- name: Cleanup
shell: bash
run: |
# 清理临时工作目录
WORK_TREE="/tmp/gitea_worktree"
git --git-dir=/opt/gitea/data/gitea-repositories/ember/front.git worktree remove $WORK_TREE --force
rm -rf $WORK_TREE /tmp/changed_files.txt