# ============================================================ # 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."