name: ci

on:
  push:
    branches: [main]
    paths:
      - 'embedchain/**'
      - 'tests/**'
      - 'examples/**'
  pull_request:
    paths:
      - 'embedchain/**'
      - 'tests/**'
      - 'examples/**'

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.9", "3.10", "3.11"]

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install poetry
        uses: snok/install-poetry@v1
        with:
          version: 1.4.2
          virtualenvs-create: true
          virtualenvs-in-project: true
      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v2
        with:
          path: .venv
          key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
      - name: Install dependencies
        run: poetry install --all-extras
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
      - name: Lint with ruff
        run: make lint
      - name: Run tests and generate coverage report
        run: make coverage
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v3
        with:
          file: coverage.xml
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
