name: Tests

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

# Cancel any in-progress CI runs for a PR if it is updated
concurrency:
  group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
  cancel-in-progress: true


jobs:
  tests:
    name: ${{ matrix.os }} ${{ matrix.flavor }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - flavor: nvim-0.7
            runner: ubuntu-20.04
            os: linux
            nvim_version: v0.7.0
          - flavor: nvim-0.8
            runner: ubuntu-20.04
            os: linux
            nvim_version: v0.8.0
          - flavor: nvim-0.9
            runner: ubuntu-20.04
            os: linux
            nvim_version: v0.9.0
          - flavor: nvim-nightly
            runner: ubuntu-20.04
            os: linux
            nvim_version: nightly
    runs-on: ${{ matrix.runner }}
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v2
      - name: Setup Test Environment
        run: |
          mkdir -p ./tmp_home/nvim/pack/vendor/start
          git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ./tmp_home/nvim/pack/vendor/start/plenary.nvim
          git clone --depth 1 https://github.com/nvim-tree/nvim-web-devicons ./tmp_home/nvim/pack/vendor/start/nvim-web-devicons
          ln -s $(pwd) ./tmp_home/nvim/pack/vendor/start
      - name: Setup neovim ${{matrix.nvim_version}}
        uses: rhysd/action-setup-vim@v1
        with:
            neovim: true
            version: ${{matrix.nvim_version}}
      - name: Run tests
        run: |
          make test
  lint:
    runs-on: ubuntu-20.04
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v2
      - name: Setup linters
        run: |
          sudo apt-get update
          sudo apt-get install luarocks
          sudo luarocks install luacheck
      - name: Run luacheck
        run: |
          make lint
