Update assets.yml

This commit is contained in:
2025-08-11 12:26:08 +08:00
committed by GitHub
parent f6f4b945d6
commit 3b3856972a

View File

@@ -8,56 +8,84 @@ jobs:
sync:
runs-on: ubuntu-latest
steps:
# 步骤1拉取 A 仓库代码
# 步骤1拉取 A 仓库代码完整历史确保所有文件可访问
- name: Checkout A Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-depth: 0 # 拉取完整历史避免浅克隆导致文件缺失
# 步骤2准备同步文件
# 步骤2准备同步文件校验源目录并复制
- name: Prepare files for B Repo
run: |
# 创建临时目录存放待同步文件
mkdir -p temp-b-repo/out/assets
# 校验并复制需要同步的资产目录
# 校验源资产目录是否存在
if [ -d "common/data/xml/assets" ]; then
# 复制assets目录下的所有内容到目标out/assets目录
cp -r common/data/xml/assets/* temp-b-repo/out/assets/
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 # 输出文件列表用于调试
else
echo "Error: common/data/xml/assets directory not found!" && exit 1
fi
# 步骤3推送到私有 B 仓库
# 步骤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"
# 克隆B仓库如果尚未克隆
if [ ! -d "b-repo" ]; then
git clone https://$B_REPO_TOKEN@github.com/TO-teams/flash.git b-repo
fi
# 清理旧目录若存在确保环境干净
rm -rf b-repo
# 克隆 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
git checkout $B_BRANCH
git pull origin $B_BRANCH
echo "Checking out branch $B_BRANCH..."
git checkout $B_BRANCH || {
echo "Failed to checkout branch $B_BRANCH!";
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
# 复制准备好的文件
cp -r ../temp-b-repo/out/assets/* 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 # 输出目标目录文件列表用于调试
# 检查是否有变更
if git diff --quiet; then
echo "No changes to sync to B repo."
# 检查是否有变更仅关注 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 https://$B_REPO_TOKEN@github.com/TO-teams/flash.git $B_BRANCH
git push origin $B_BRANCH || {
echo "Failed to push changes to B repo!";
exit 1;
}
echo "Sync completed successfully."
fi