使用git checkout脚本
Some checks failed
Deploy Incremental Updates to NEUxiaozhan / deploy (push) Failing after 0s
Some checks failed
Deploy Incremental Updates to NEUxiaozhan / deploy (push) Failing after 0s
This commit is contained in:
parent
a0e78f7eef
commit
e51f286ea9
@ -1,28 +1,34 @@
|
||||
name: Deploy Incremental Updates to NEUxiaozhan
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master # 触发分支,可以根据需要修改
|
||||
- master
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Deploy Code to Web Root
|
||||
shell: bash # ← 这里添加 shell 类型
|
||||
- name: Deploy Incremental Updates
|
||||
shell: bash
|
||||
run: |
|
||||
# 设置 Git 仓库目录和工作目录
|
||||
GIT_DIR=/opt/gitea/data/gitea-repositories/ember/front
|
||||
WORK_TREE=/www/wwwroot/front/public
|
||||
REPO_PATH="/opt/gitea/data/gitea-repositories/ember/front"
|
||||
WEB_ROOT="/www/wwwroot/front/public"
|
||||
|
||||
# 确保 GIT_DIR 目录存在(首次运行需要手动初始化)
|
||||
if [ ! -d "$GIT_DIR" ]; then
|
||||
git clone --bare https://git.xn--xhq44jb2fzpc.com/ember/front.git $GIT_DIR
|
||||
fi
|
||||
# 进入仓库目录
|
||||
cd "$REPO_PATH"
|
||||
|
||||
# 获取最新代码并强制检出到网站根目录
|
||||
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
|
||||
# 获取最新代码
|
||||
git fetch origin master
|
||||
|
||||
# 可选:记录日志
|
||||
echo "Code deployed to $WORK_TREE at $(date)" >> /opt/gitea/data/gitea-repositories/ember/front/log/git-deploy.log
|
||||
# 获取最新提交和上一次提交的差异
|
||||
LAST_COMMIT=$(git rev-parse HEAD)
|
||||
git reset --hard origin/master
|
||||
CURRENT_COMMIT=$(git rev-parse HEAD)
|
||||
|
||||
echo "Syncing changes from $LAST_COMMIT to $CURRENT_COMMIT"
|
||||
|
||||
# 获取变更文件并同步
|
||||
rsync -av --delete --files-from=<(git diff --name-only $LAST_COMMIT $CURRENT_COMMIT) "$REPO_PATH/" "$WEB_ROOT/"
|
||||
|
||||
echo "Deployment completed!"
|
||||
|
Loading…
x
Reference in New Issue
Block a user