name: test

on:
  push:
    branches-ignore:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.actor }}
  cancel-in-progress: true

jobs:
  test-base:
    name: Run base tests
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        neovim_version: ['v0.11.0']
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4
      - name: Setup neovim
        uses: rhysd/action-setup-vim@v1
        with:
          neovim: true
          version: ${{ matrix.neovim_version }}
      - name: Install ripgrep
        run: |
          mkdir -p deps/ripgrep
          cd deps/ripgrep
          wget -O - https://github.com/BurntSushi/ripgrep/releases/download/14.1.0/ripgrep-14.1.0-x86_64-unknown-linux-musl.tar.gz | tar zxf - --strip-component=1
      - name: Install astgrep
        run: |
          mkdir -p deps/astgrep
          cd deps/astgrep
          wget https://github.com/ast-grep/ast-grep/releases/download/0.35.0/app-x86_64-unknown-linux-gnu.zip
          unzip app-x86_64-unknown-linux-gnu.zip
      - name: Run tests
        run: | 
          make prepare
          make test dir=base
  test-astgrep:
    name: Run astgrep tests
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        neovim_version: ['v0.11.0']
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4
      - name: Setup neovim
        uses: rhysd/action-setup-vim@v1
        with:
          neovim: true
          version: ${{ matrix.neovim_version }}
      - name: Install ripgrep
        run: |
          mkdir -p deps/ripgrep
          cd deps/ripgrep
          wget -O - https://github.com/BurntSushi/ripgrep/releases/download/14.1.0/ripgrep-14.1.0-x86_64-unknown-linux-musl.tar.gz | tar zxf - --strip-component=1
      - name: Install astgrep
        run: |
          mkdir -p deps/astgrep
          cd deps/astgrep
          wget https://github.com/ast-grep/ast-grep/releases/download/0.35.0/app-x86_64-unknown-linux-gnu.zip
          unzip app-x86_64-unknown-linux-gnu.zip
      - name: Run tests
        run: | 
          make prepare
          make test dir=astgrep
  test-astgrep-rules:
    name: Run astgrep-rules tests
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        neovim_version: ['v0.11.0']
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4
      - name: Setup neovim
        uses: rhysd/action-setup-vim@v1
        with:
          neovim: true
          version: ${{ matrix.neovim_version }}
      - name: Install ripgrep
        run: |
          mkdir -p deps/ripgrep
          cd deps/ripgrep
          wget -O - https://github.com/BurntSushi/ripgrep/releases/download/14.1.0/ripgrep-14.1.0-x86_64-unknown-linux-musl.tar.gz | tar zxf - --strip-component=1
      - name: Install astgrep
        run: |
          mkdir -p deps/astgrep
          cd deps/astgrep
          wget https://github.com/ast-grep/ast-grep/releases/download/0.35.0/app-x86_64-unknown-linux-gnu.zip
          unzip app-x86_64-unknown-linux-gnu.zip
      - name: Run tests
        run: | 
          make prepare
          make test dir=astgrep-rules
