Skip to content

ci: change sync content #10

ci: change sync content

ci: change sync content #10

Workflow file for this run

name: Sync Demo Branch
on:
push:
branches:
- main
workflow_dispatch:
jobs:
sync-demo:
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create demo branch if it doesn't exist
run: |
if ! git ls-remote --heads origin demo | grep -q demo; then
echo "Creating demo branch..."
git checkout -b demo
git push origin demo
else
echo "Demo branch already exists"
fi
- name: Checkout demo branch
uses: actions/checkout@v4
with:
ref: demo
token: ${{ secrets.GITHUB_TOKEN }}
path: demo
- name: Clean demo directory
run: |
cd demo
# 删除所有文件/文件夹,但保留 .git
find . -mindepth 1 -path './.git' -prune -o -exec rm -rf {} + 2>/dev/null || true
- name: Copy files using config
run: |
while IFS= read -r line; do
source=$(echo $line | cut -d: -f1 | xargs)
dest=$(echo $line | cut -d: -f2 | xargs)
if [ -e "$source" ]; then
mkdir -p "demo/$(dirname $dest)"
cp -r "$source" "demo/$dest"
echo "Copied $source to $dest"
fi
done < <(grep -E '^\s*-\s+source:' .github/sync-config.yml | sed 's/.*source: //' | paste -d: - <(grep -E '^\s*-\s+dest:' .github/sync-config.yml | sed 's/.*dest: //'))
- name: Commit and push changes
run: |
cd demo
git config --global user.email "[email protected]"
git config --global user.name "github-actions[bot]"
# 检查是否有变化
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "Auto-sync demo branch with main branch"
git push origin demo
echo "Changes pushed to demo branch"
else
echo "No changes to sync"
fi
push-hf:
needs: sync-demo
uses: ./.github/workflows/push-to-hf.yml
secrets:
HF_TOKEN: ${{ secrets.HF_TOKEN }}