Files
bl/.github/workflows/assets.yml
2025-08-11 12:40:43 +08:00

61 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Sync Assets to Private B Repo
on:
push:
branches: [ main ]
# 仅监听 assets 目录的变更精确匹配路径
paths:
- 'common/data/xml/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
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:"
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"
rm -rf b-repo
git clone https://$B_REPO_TOKEN@${B_REPO_URL#https://} b-repo || { echo "Failed to clone B repo"; exit 1; }
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