name: Update Wiki

on:
  push:
    branches: [ master ]
    tags: ['*']
  workflow_dispatch:

jobs:
  update-wiki:
    if: ${{ github.repository == 'fabiangreffrath/woof' }}
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          path: code

      - name: Checkout wiki
        uses: actions/checkout@v4
        with:
          repository: ${{github.repository}}.wiki
          path: wiki

      - name: Generate files
        run: |
          python3 "./code/man/docgen" -M "./code/man/CMDLINE.template.md" \
                  "./code/src/" > "./wiki/Command-Line-Parameters.md"
          cp -af "./code/docs/cheats.md" "./wiki/Cheats.md"

      - name: Push to wiki
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
        run: |
          cd wiki
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add .
          git diff-index --quiet HEAD || git commit -m "Update wiki" && git push
