From 7a21f910c80e183019a71d1af9ddc931de9bde5a Mon Sep 17 00:00:00 2001 From: gaojie Date: Wed, 20 May 2026 23:12:40 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20Gitea=20Actions=20wo?= =?UTF-8?q?rkflow=EF=BC=8Cpush=20=E5=90=8E=E8=87=AA=E5=8A=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=88=B0=20site1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/sync-to-site1.yml | 98 ++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .gitea/workflows/sync-to-site1.yml diff --git a/.gitea/workflows/sync-to-site1.yml b/.gitea/workflows/sync-to-site1.yml new file mode 100644 index 0000000..e667010 --- /dev/null +++ b/.gitea/workflows/sync-to-site1.yml @@ -0,0 +1,98 @@ +# ============================================================ +# Gitea Actions Workflow: 同步 worldmodel 内容到 site1 +# ============================================================ +# 触发条件:push 到 main 分支 +# 功能:将 worldmodel 仓库内容同步到 admin/site1 的 +# content/posts/worldmodel/ 目录,并触发 Hugo 构建 +# +# 前置条件(用户需手动操作): +# 在 Gitea 仓库 gaojie/worldmodel 的 +# Settings → Secrets → Actions 里添加: +# Name: SITE1_PASSWORD +# Value: 你的 git.plantshero.com 账号 gaojie 的密码 +# ============================================================ + +name: Sync to site1 + +on: + push: + branches: + - main + +jobs: + sync: + runs-on: ubuntu-latest + + steps: + - name: Checkout worldmodel + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Clone site1 + env: + SITE1_PASSWORD: ${{ secrets.SITE1_PASSWORD }} + run: | + git clone \ + https://gaojie:${SITE1_PASSWORD}@git.plantshero.com/admin/site1.git \ + /tmp/site1 + # 立即清除 remote URL 中的凭据,避免凭据残留在 git 配置里 + git -C /tmp/site1 remote set-url origin \ + https://git.plantshero.com/admin/site1.git + + - name: Sync content to site1 + run: | + # 若目标目录已存在,先用 git rm 清理(保持 git 历史干净) + if [ -d /tmp/site1/content/posts/worldmodel ]; then + git -C /tmp/site1 rm -rf content/posts/worldmodel + fi + mkdir -p /tmp/site1/content/posts/worldmodel + + # rsync:排除 .git 及 .gitignore 中列出的产物 + rsync -a \ + --exclude='.git/' \ + --exclude='node_modules/' \ + --exclude='.venv/' \ + --exclude='__pycache__/' \ + --exclude='*.pyc' \ + --exclude='.DS_Store' \ + --exclude='.pytest_cache/' \ + --exclude='.mypy_cache/' \ + --exclude='.ruff_cache/' \ + --exclude='.idea/' \ + --exclude='.vscode/' \ + --exclude='*.log' \ + --exclude='plans/PRISM/.build/' \ + --exclude='PRISM_*.pdf' \ + --exclude='research/lyra2_paper.pdf' \ + --exclude='.gitea/' \ + ./ /tmp/site1/content/posts/worldmodel/ + + - name: Commit and push site1 + env: + SITE1_PASSWORD: ${{ secrets.SITE1_PASSWORD }} + run: | + cd /tmp/site1 + git config user.name "gitea-actions" + git config user.email "actions@plantshero.com" + + git add content/posts/worldmodel + + # 若无变更则跳过,workflow 正常退出(exit 0) + if git diff --cached --quiet; then + echo "No changes to commit, skipping push." + exit 0 + fi + + git commit -m "chore(sync): 从 worldmodel 同步内容 @ ${{ github.sha }}" + + # 推送时临时注入凭据 + git remote set-url origin \ + https://gaojie:${SITE1_PASSWORD}@git.plantshero.com/admin/site1.git + git push origin main + + # 推送完成后立即清除凭据 + git remote set-url origin \ + https://git.plantshero.com/admin/site1.git + + echo "Sync complete. site1 post-receive hook will trigger Hugo build."