Update assets.yml

This commit is contained in:
2025-08-11 12:40:43 +08:00
committed by GitHub
parent 3b3856972a
commit a9d94b80e3

View File

@@ -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