name: Test on main branch
env:
  PYTHON_VERSION: "3.10"

on:
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      mysql:
        image: mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: root
        ports:
          - 3306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3


    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.PYTHON_VERSION }}
          cache: "pip"

      - name: Install dependencies
        run: pip install -r requirements.test.txt  # Replace with your dependencies installation command

      - name: Set up env
        run: cp .env.sample .env

      - name: Run tests
        run: python -m unittest discover -s tests -p "*_tests.py"  # Replace with your test command

  lint_and_types:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.PYTHON_VERSION }}
          cache: "pip"

      - name: Install dependencies
        run: pip install -r requirements.dev.txt

      - name: Lint with pyright
        run: pyright

      - name: Lint with black
        run: black -t py310 --check .
