Skip to content

Sync to LocoWiki

Sync to LocoWiki #6

name: Sync to LocoWiki
on:
workflow_dispatch:
push:
branches: [main]
paths:
- '01_数学/**'
- '02_基础/**'
- '03_SLAM/**'
- '04_移动机器人规控/**'
- '05_运动控制/**'
- '06_具身智能/**'
- 'SUMMARY.md'
- 'README.md'
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout Robotics_Tutorial
uses: actions/checkout@v4
with:
path: source
- name: Checkout LocoWiki fork
uses: actions/checkout@v4
with:
repository: Michael-Jetson/LocoWiki
token: ${{ secrets.LOCOWIKI_PAT }}
path: target
- name: Configure git
run: |
cd target
git config user.name "Michael-Jetson"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync upstream
run: |
cd target
git remote add upstream https://github.com/LocoWiki/LocoWiki.git || true
git fetch upstream main
git rebase upstream/main || {
echo "::error::Rebase conflict with upstream. Manual intervention needed."
git rebase --abort
exit 1
}
- name: Create sync branch
run: |
cd target
git checkout -B contrib/robotics-tutorial
- name: Copy docs (md + images only)
run: |
TARGET_DIR="target/wiki/【体系化进阶】Robotics Tutorial"
# Copy README and SUMMARY to target root
cp source/README.md "$TARGET_DIR/" 2>/dev/null || true
cp source/SUMMARY.md "$TARGET_DIR/" 2>/dev/null || true
# Sync completed directions
DEST="$TARGET_DIR/05_运动控制/足式"
mkdir -p "$DEST"
rsync -av --delete \
--include='*/' \
--include='*.md' \
--include='*.png' \
--include='*.jpg' \
--include='*.jpeg' \
--include='*.svg' \
--include='*.gif' \
--include='*.webp' \
--exclude='*' \
"source/05_运动控制/足式/" "$DEST/"
# Add more directions here as they complete:
# mkdir -p "$TARGET_DIR/05_运动控制/机械臂"
# rsync -av --delete ... "source/05_运动控制/机械臂/" "$TARGET_DIR/05_运动控制/机械臂/"
find "$TARGET_DIR" -type d -empty -delete
- name: Check for changes
id: changes
run: |
cd target
git add -A
if git diff --cached --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push
if: steps.changes.outputs.has_changes == 'true'
run: |
cd target
git commit -m "sync: update Robotics Tutorial docs from source repo
Auto-synced from Michael-Jetson/Robotics_Tutorial@${{ github.sha }}"
git push --force origin contrib/robotics-tutorial
- name: Create or update PR
if: steps.changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.LOCOWIKI_PAT }}
run: |
cd target
EXISTING_PR=$(gh pr list --repo LocoWiki/LocoWiki \
--head "contrib/robotics-tutorial" \
--state open --json number --jq '.[0].number' 2>/dev/null || echo "")
if [ -z "$EXISTING_PR" ] || [ "$EXISTING_PR" = "null" ]; then
gh pr create --repo LocoWiki/LocoWiki \
--head "Michael-Jetson:contrib/robotics-tutorial" \
--base main \
--title "【体系化进阶】Robotics Tutorial 文档同步" \
--body "$(cat <<'PREOF'
## Summary
自动同步来自 [Robotics_Tutorial](https://github.com/Michael-Jetson/Robotics_Tutorial) 的教学文档。
- 内容:机器人学系统化教学文档
- 作者:Pengfei Guo, DAMIAO Technology
- 协议:CC BY 4.0
- 同步范围:已完成方向的 .md 文档与图片
Auto-synced by GitHub Actions
PREOF
)"
echo "PR created"
else
echo "PR #$EXISTING_PR already exists, pushed new commits"
fi