name: CI Pipeline

on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - reopened
      - ready_for_review

jobs:
  build-and-test:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest

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

      - name: Set up Python
        uses: actions/setup-python@v5

      - name: Install Pipenv
        run: pip install pipenv

      - name: Install Dependencies from Pipfile
        run: pipenv install --dev

      - name: Run API
        run: pipenv run python -c "import api.app"

      - name: Run Pytests
        run: pipenv run pytest

      - name: Run Pytest Code Coverage
        run: pipenv run pytest --cov=api --cov-report=term-missing --cov-fail-under=80
