Create assets.yml
This commit is contained in:
63
.github/workflows/assets.yml
vendored
Normal file
63
.github/workflows/assets.yml
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
name: Sync Assets to Private B Repo
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
workflow_dispatch: # 支持手动触发
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sync:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# 步骤1:拉取 A 仓库代码
|
||||||
|
- name: Checkout A Repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# 步骤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/
|
||||||
|
else
|
||||||
|
echo "Error: common/data/xml/assets directory not found!" && exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 步骤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 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
|
||||||
|
|
||||||
|
cd b-repo
|
||||||
|
git checkout $B_BRANCH
|
||||||
|
git pull origin $B_BRANCH
|
||||||
|
|
||||||
|
# 确保目标目录存在
|
||||||
|
mkdir -p out/assets
|
||||||
|
|
||||||
|
# 复制准备好的文件
|
||||||
|
cp -r ../temp-b-repo/out/assets/* out/assets/
|
||||||
|
|
||||||
|
# 检查是否有变更
|
||||||
|
if git diff --quiet; then
|
||||||
|
echo "No changes to sync to B repo."
|
||||||
|
else
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
|
||||||
Reference in New Issue
Block a user