name: CI Pipeline

on:
  pull_request:

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'

      - name: Install pre-commit
        run: |
          python -m pip install --upgrade pip
          pip install pre-commit

      - name: Run pre-commit
        run: SKIP="prettier, eslint" pre-commit run --all-files

  app-testing:
    runs-on: ubuntu-latest
    needs: pre-commit
    steps:
      - uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'


      - name: Install pnpm
        run: cd app && corepack enable pnpm

      - name: Install dependencies
        run: cd app && pnpm install

      - name: Run pnpm check
        run: cd app && pnpm check

      - name: Run pnpm lint
        run: cd app && pnpm lint

      - name: Run pnpm format
        run: cd app && pnpm format

      - name: Run pnpm test
        run: cd app && pnpm test:unit # running only unit tests, since integration costs money

  pytest:
    runs-on: ubuntu-latest
    needs: pre-commit # since installing all the stuff is slow, and precommit is fail-fast
    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.x'

      - name: Install dependencies
        run: |
          cd kernel
          sudo apt-get install ffmpeg
          curl -sSL https://install.python-poetry.org | python -
          poetry install

      - name: Run pytest
        run: |
          cd kernel
          poetry run pytest
