使用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
|
name: Deploy Incremental Updates to NEUxiaozhan
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master # 触发分支,可以根据需要修改
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy Code to Web Root
|
- name: Deploy Incremental Updates
|
||||||
shell: bash # ← 这里添加 shell 类型
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
# 设置 Git 仓库目录和工作目录
|
REPO_PATH="/opt/gitea/data/gitea-repositories/ember/front"
|
||||||
GIT_DIR=/opt/gitea/data/gitea-repositories/ember/front
|
WEB_ROOT="/www/wwwroot/front/public"
|
||||||
WORK_TREE=/www/wwwroot/front/public
|
|
||||||
|
|
||||||
# 确保 GIT_DIR 目录存在(首次运行需要手动初始化)
|
# 进入仓库目录
|
||||||
if [ ! -d "$GIT_DIR" ]; then
|
cd "$REPO_PATH"
|
||||||
git clone --bare https://git.xn--xhq44jb2fzpc.com/ember/front.git $GIT_DIR
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 获取最新代码并强制检出到网站根目录
|
# 获取最新代码
|
||||||
git --git-dir=$GIT_DIR --work-tree=$WORK_TREE fetch origin master
|
git 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
|
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