name: sync-wiki
on:
  push:
    branches: [master]
    paths:
    - '.github/workflows/sync-wiki.yml'
    - 'docs/**'
concurrency:
  group: sync-wiki-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  sync-wiki:
    permissions:
      contents: write  # for Git to git push
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: sync
      run: |
        cp -r docs $GITHUB_WORKSPACE/ncnn.wiki
        cd $GITHUB_WORKSPACE/ncnn.wiki
        git config --global user.name "wiki-sync-bot"
        git config --global user.email "wiki-sync-bot@qq.com"
        git init
        git add .
        git commit -m "sync"
        git remote add upstream https://${{ secrets.WIKI_SYNC_BOT_TOKEN }}@github.com/Tencent/ncnn.wiki.git
        git push upstream master -f
