From a9d94b80e3107f7d019458c7c93d2bc768272411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Mon, 11 Aug 2025 12:40:43 +0800 Subject: [PATCH] Update assets.yml --- .github/workflows/assets.yml | 55 ++++++++---------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/.github/workflows/assets.yml b/.github/workflows/assets.yml index 5b30d1801..645b53ba3 100644 --- a/.github/workflows/assets.yml +++ b/.github/workflows/assets.yml @@ -2,90 +2,59 @@ name: Sync Assets to Private B Repo on: push: branches: [ main ] - workflow_dispatch: # 支持手动触发 + # 仅监听 assets 目录的变更(精确匹配路径) + paths: + - 'common/data/xml/assets/**' # 监听该目录下所有文件和子目录的变更 + workflow_dispatch: # 保留手动触发功能 jobs: sync: runs-on: ubuntu-latest steps: - # 步骤1:拉取 A 仓库代码(完整历史,确保所有文件可访问) - name: Checkout A Repo uses: actions/checkout@v4 with: - fetch-depth: 0 # 拉取完整历史,避免浅克隆导致文件缺失 + fetch-depth: 0 - # 步骤2:准备同步文件(校验源目录并复制) - name: Prepare files for B Repo run: | - # 创建临时目录存放待同步文件 mkdir -p temp-b-repo/out/assets - # 校验源资产目录是否存在 if [ -d "common/data/xml/assets" ]; then - echo "Found assets directory, starting copy..." - # 复制所有文件(包括隐藏文件)到临时目录 cp -rv common/data/xml/assets/* common/data/xml/assets/.* temp-b-repo/out/assets/ 2>/dev/null || true echo "Files copied to temp directory:" - ls -la temp-b-repo/out/assets # 输出文件列表用于调试 + ls -la temp-b-repo/out/assets else echo "Error: common/data/xml/assets directory not found!" && exit 1 fi - # 步骤3:推送到私有 B 仓库(优化克隆逻辑和错误处理) - name: Push to Private B Repo env: B_REPO_TOKEN: ${{ secrets.B_REPO_TOKEN }} B_REPO_URL: https://github.com/TO-teams/flash.git B_BRANCH: main run: | - # 配置 Git 身份 git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" - # 清理旧目录(若存在),确保环境干净 rm -rf b-repo + git clone https://$B_REPO_TOKEN@${B_REPO_URL#https://} b-repo || { echo "Failed to clone B repo"; exit 1; } - # 克隆 B 仓库(带错误捕获) - echo "Cloning B repo..." - git clone https://$B_REPO_TOKEN@${B_REPO_URL#https://} b-repo || { - echo "Failed to clone B repository!"; - exit 1; - } - - # 进入 B 仓库目录并同步最新代码 cd b-repo - echo "Checking out branch $B_BRANCH..." - git checkout $B_BRANCH || { - echo "Failed to checkout branch $B_BRANCH!"; - exit 1; - } + git checkout $B_BRANCH || { echo "Failed to checkout B branch"; exit 1; } + git pull origin $B_BRANCH || { echo "Failed to pull B repo"; exit 1; } - echo "Pulling latest changes from $B_BRANCH..." - git pull origin $B_BRANCH || { - echo "Failed to pull latest changes!"; - exit 1; - } - - # 确保目标目录存在 mkdir -p out/assets - - # 复制临时目录的文件到 B 仓库(包括隐藏文件) - echo "Copying assets to B repo..." cp -rv ../temp-b-repo/out/assets/* ../temp-b-repo/out/assets/.* out/assets/ 2>/dev/null || true echo "Files in B repo target directory after copy:" - ls -la out/assets # 输出目标目录文件列表用于调试 + ls -la out/assets - # 检查是否有变更(仅关注 out/assets 目录) + # 检查是否有变更(包括新增、修改、删除) if git diff --quiet -- out/assets; then echo "No changes to sync to B repo. Exiting." else - # 提交并推送变更 - echo "Detected changes, pushing to B repo..." git add out/assets git commit -m "Sync assets: $(date +'%Y-%m-%d %H:%M:%S')" - git push origin $B_BRANCH || { - echo "Failed to push changes to B repo!"; - exit 1; - } + git push origin $B_BRANCH || { echo "Failed to push to B repo"; exit 1; } echo "Sync completed successfully." fi