name: Update SillyTavern-Docs

on:
  push:
    branches:
      - main

jobs:
  update_docs:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout current repository
      uses: actions/checkout@v2

    - name: Checkout SillyTavern-Docs repository
      uses: actions/checkout@v2
      with:
        repository: SillyTavern/SillyTavern-Docs
        path: SillyTavern-Docs

    - name: Clone SillyTavern wiki into SillyTavern-Docs/extensions
      run: rm -rf SillyTavern-Docs/extensions && git clone https://github.com/SillyTavern/SillyTavern.wiki.git SillyTavern-Docs/extensions && rm -rf SillyTavern-Docs/extensions/.git

    - name: Copy files
      run: |
        cp public/notes/content.md SillyTavern-Docs/guidebook.md
        cp faq.md SillyTavern-Docs/faq.md
        cp readme.md SillyTavern-Docs/readme.md
        cp public/notes/update.md SillyTavern-Docs/update.md

    - name: Deploy to external repository
      uses: cpina/github-action-push-to-another-repository@main
      env:
        SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
      with:
          # GitHub Action output files
          source-directory: SillyTavern-Docs/
          destination-github-username: SillyTavern
          destination-repository-name: SillyTavern-Docs
          user-email: github-actions[bot]@users.noreply.github.com
          user-name: "GitHub Actions"
          target-branch: "main"
