Update assets.yml
This commit is contained in:
36
.github/workflows/assets.yml
vendored
36
.github/workflows/assets.yml
vendored
@@ -2,10 +2,9 @@ name: Sync Assets to Private B Repo
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
# 仅监听 assets 目录的变更(精确匹配路径)
|
||||
paths:
|
||||
- 'common/data/xml/assets/**' # 监听该目录下所有文件和子目录的变更
|
||||
workflow_dispatch: # 保留手动触发功能
|
||||
- 'common/data/xml/assets/**' # 仅监听assets目录变更
|
||||
workflow_dispatch: # 保留手动触发
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
@@ -16,13 +15,23 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Prepare files for B Repo
|
||||
- name: Prepare files for B Repo (and remove XML comments)
|
||||
run: |
|
||||
# 创建临时目录用于处理文件
|
||||
mkdir -p temp-b-repo/out/assets
|
||||
|
||||
# 检查源目录是否存在
|
||||
if [ -d "common/data/xml/assets" ]; then
|
||||
# 复制源文件到临时目录(包括隐藏文件)
|
||||
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:"
|
||||
echo "Files copied to temp directory (before comment removal):"
|
||||
ls -la temp-b-repo/out/assets
|
||||
|
||||
# 关键步骤:删除临时目录中所有XML文件的注释(<!-- ... -->)
|
||||
# 匹配规则:删除从<!--开始到-->结束的所有内容(包括多行注释)
|
||||
find temp-b-repo/out/assets -name "*.xml" -exec sed -i '/<!--/,/-->/d' {} +
|
||||
|
||||
echo "Files in temp directory after comment removal:"
|
||||
ls -la temp-b-repo/out/assets
|
||||
else
|
||||
echo "Error: common/data/xml/assets directory not found!" && exit 1
|
||||
@@ -37,24 +46,23 @@ jobs:
|
||||
git config --global user.name "GitHub Actions"
|
||||
git config --global user.email "actions@github.com"
|
||||
|
||||
# 克隆仓库B
|
||||
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的目标分支
|
||||
cd b-repo
|
||||
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; }
|
||||
|
||||
# 创建目标目录并复制处理后的文件(已移除注释)
|
||||
mkdir -p out/assets
|
||||
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 -- out/assets; then
|
||||
# echo "No changes to sync to B repo. Exiting."
|
||||
# else
|
||||
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 to B repo"; exit 1; }
|
||||
echo "Sync completed successfully."
|
||||
#fi
|
||||
# 提交并推送变更
|
||||
git add out/assets
|
||||
git commit -m "Sync assets (without comments): $(date +'%Y-%m-%d %H:%M:%S')"
|
||||
git push origin $B_BRANCH || { echo "Failed to push to B repo"; exit 1; }
|
||||
echo "Sync completed successfully (XML comments removed)."
|
||||
|
||||
Reference in New Issue
Block a user