name: Check
on: [push, pull_request]
jobs:
  check:
    strategy:
      fail-fast: false
      matrix:
        vimFlavor: [neovim, vim]
        vimVersion: [stable, unstable]
        exclude:
          - vimFlavor: vim
            vimVersion: unstable
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Enable Universe package repository
        run: |
          sudo add-apt-repository ${{ matrix.vimVersion == 'stable' && 'universe' || 'ppa:neovim-ppa/unstable' }}
          sudo apt-get update
      - name: Install tmux and ${{ matrix.vimFlavor }}
        run: |
          sudo apt-get install tmux ${{ matrix.vimFlavor }}
      - name: Review versions
        run: |
          tmux -V
          ${{ matrix.vimFlavor == 'neovim' && 'nvim' || 'vim' }} --version
      # This tests looks for two thigs:
      # * That VIM doesn't hang. If it succedes it will quit quickly. If 5
      #   seconds later the tmux session is still running either the runner pane
      #   didn't get closed or (more likely) we threw some error and VIM is
      #   sitting there expecting us to acknowledge the message(s).
      # * That VIM exited normally. This check isn't very useful since :qa
      #   never bubbles up an error, but if someday we use :cq for a test being
      #   ready to check the exit code seems like a good thing.
      - name: "Try Vimux"
        run: |
          ec="$(mktemp)"
          tmux new -s ci -d "${{ matrix.vimFlavor == 'neovim' && 'nvim -u /dev/null --headless' || 'vim' }} -i NONE \"+so plugin/vimux.vim\" \"+VimuxRunCommand('date')\" \"+VimuxCloseRunner | qa\"; echo \$? > '$ec'"
          sleep 5
          tmux kill-session -t ci && exit 1
          exit "$(cat $ec)"
