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:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
# 仅监听 assets 目录的变更(精确匹配路径)
|
|
||||||
paths:
|
paths:
|
||||||
- 'common/data/xml/assets/**' # 监听该目录下所有文件和子目录的变更
|
- 'common/data/xml/assets/**' # 仅监听assets目录变更
|
||||||
workflow_dispatch: # 保留手动触发功能
|
workflow_dispatch: # 保留手动触发
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sync:
|
sync:
|
||||||
@@ -16,13 +15,23 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Prepare files for B Repo
|
- name: Prepare files for B Repo (and remove XML comments)
|
||||||
run: |
|
run: |
|
||||||
|
# 创建临时目录用于处理文件
|
||||||
mkdir -p temp-b-repo/out/assets
|
mkdir -p temp-b-repo/out/assets
|
||||||
|
|
||||||
|
# 检查源目录是否存在
|
||||||
if [ -d "common/data/xml/assets" ]; then
|
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
|
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
|
ls -la temp-b-repo/out/assets
|
||||||
else
|
else
|
||||||
echo "Error: common/data/xml/assets directory not found!" && exit 1
|
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.name "GitHub Actions"
|
||||||
git config --global user.email "actions@github.com"
|
git config --global user.email "actions@github.com"
|
||||||
|
|
||||||
|
# 克隆仓库B
|
||||||
rm -rf b-repo
|
rm -rf b-repo
|
||||||
git clone https://$B_REPO_TOKEN@${B_REPO_URL#https://} b-repo || { echo "Failed to clone B repo"; exit 1; }
|
git clone https://$B_REPO_TOKEN@${B_REPO_URL#https://} b-repo || { echo "Failed to clone B repo"; exit 1; }
|
||||||
|
|
||||||
|
# 同步仓库B的目标分支
|
||||||
cd b-repo
|
cd b-repo
|
||||||
git checkout $B_BRANCH || { echo "Failed to checkout 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; }
|
git pull origin $B_BRANCH || { echo "Failed to pull B repo"; exit 1; }
|
||||||
|
|
||||||
|
# 创建目标目录并复制处理后的文件(已移除注释)
|
||||||
mkdir -p out/assets
|
mkdir -p out/assets
|
||||||
cp -rv ../temp-b-repo/out/assets/* ../temp-b-repo/out/assets/.* out/assets/ 2>/dev/null || true
|
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:"
|
echo "Files in B repo target directory after copy:"
|
||||||
ls -la out/assets
|
ls -la out/assets
|
||||||
|
|
||||||
# 检查是否有变更(包括新增、修改、删除)
|
# 提交并推送变更
|
||||||
# if git diff --quiet -- out/assets; then
|
git add out/assets
|
||||||
# echo "No changes to sync to B repo. Exiting."
|
git commit -m "Sync assets (without comments): $(date +'%Y-%m-%d %H:%M:%S')"
|
||||||
# else
|
git push origin $B_BRANCH || { echo "Failed to push to B repo"; exit 1; }
|
||||||
git add out/assets
|
echo "Sync completed successfully (XML comments removed)."
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user