name: docgen

on:
  push:
    branches:
      - main

jobs:
  docgen:
    runs-on: ubuntu-latest
    steps:
      - name: Install Neovim
        uses: rhysd/action-setup-vim@v1
        id: neovim
        with:
          neovim: true
          version: nightly
      - uses: actions/checkout@v2
      - name: Install Mini.nvim
        uses: actions/checkout@v2
        with:
          repository: echasnovski/mini.nvim
          path: mini.nvim
      - name: Generate vim docs
        run: make documentation
      - name: Commit changes
        env:
          COMMIT_MSG: |
            [docgen] Update doc/neogen.txt
            skip-checks: true
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add doc/neogen.txt
          # Only commit and push if we have changes
          git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push)
