69 lines
2.7 KiB
Go
69 lines
2.7 KiB
Go
name: Sync Assets to Private B Repo
|
||
on:
|
||
push:
|
||
branches: [ main ]
|
||
paths:
|
||
- 'common/data/xml/assets/**' # 仅监听assets目录变更
|
||
workflow_dispatch: # 保留手动触发
|
||
|
||
jobs:
|
||
sync:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout A Repo
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- 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 (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
|
||
fi
|
||
|
||
- 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 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
|
||
|
||
# 提交并推送变更
|
||
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)."
|