Skip to content

Delete .github/workflows/dependabot-auto-merge.yml #67

Delete .github/workflows/dependabot-auto-merge.yml

Delete .github/workflows/dependabot-auto-merge.yml #67

name: Sync Folders to Another Repo
on:
push:
branches: [ main ] # 或你需要同步的分支
workflow_dispatch: # 手动触发
jobs:
sync-md-files:
runs-on: ubuntu-latest
steps:
- name: Checkout source repo
uses: actions/checkout@v4
with:
path: source
fetch-depth: 0
- name: Checkout target repo
uses: actions/checkout@v4
with:
repository: Navyum/Knowledge
token: ${{ secrets.TARGET_REPO_TOKEN }}
path: target
persist-credentials: false
fetch-depth: 0
- name: Sync folders
run: |
echo "=== 同步文件夹 ==="
# 删除目标仓库中第一层的非隐藏文件夹
delete_dirs=$(find target -maxdepth 1 -mindepth 1 -type d ! -name '.*')
echo "删除的文件夹:"
echo "$delete_dirs"
if [ -n "$delete_dirs" ]; then
echo "$delete_dirs" | while read -r dir; do
if [ -n "$dir" ]; then
echo "删除: $dir"
rm -rf "$dir"
fi
done
fi
# 复制源仓库的docs目录下的符合规则的文件夹到目标仓库
DIRS=($(find source/docs -mindepth 1 -maxdepth 1 -type d ! -name '.' ! -name '.*' ! -name '_*' -printf '%f\n'))
echo "要同步的文件夹: ${DIRS[@]}"
for d in "${DIRS[@]}"; do
echo "复制: source/docs/$d -> target/$d"
cp -r "source/docs/$d" target/
done
echo "=== 同步后的目标仓库结构 ==="
ls -la target/
# rm -rf source/
echo "=== 提交并推送 ==="
cd target
git config --global user.name "Sync Bot"
git config --global user.email "sync-bot@example.com"
git add -A
git commit -m "[sync] Force update from source repo" || exit 0
# 设置远程 URL 使用 token
git remote set-url origin https://${{ secrets.TARGET_REPO_TOKEN }}@github.com/Navyum/Knowledge.git
echo "=== 开始推送 ==="
git push origin main