Skip to content

[DevOps] Add GitHub Actions CI Workflow to Automatically Run Tests on Push and Pull Requests #739

Description

@Pcmhacker-piro

Description

Agri-Vision has a comprehensive test suite (12 test files, 89%+ code coverage) that can run in under 2 seconds. However, there is no CI/CD pipeline configured to automatically run these tests when changes are pushed or pull requests are opened. This means:

  1. Contributors can accidentally merge code that breaks existing tests
  2. Maintainers must manually clone and test PRs before merging
  3. There is no visible status check on PRs indicating pass/fail
  4. Code quality regressions go undetected until someone runs tests locally

Steps to Reproduce

  1. Open any pull request on the repository
  2. Observe there are no CI checks, status badges, or automated test runs
  3. Merge a PR with broken tests — the broken code enters the main branch undetected

Expected Behavior

  • CI Pipeline: A GitHub Actions workflow (.github/workflows/tests.yml) triggers on push and pull_request to the main branch
  • Job Steps:
    1. Checkout the code
    2. Set up Python 3.10
    3. Install dependencies from requirements.txt
    4. Run python -m pytest with coverage
    5. Upload coverage report as an artifact
  • Badge: Add a test status badge to the README.md showing pass/fail

Implementation Hints

File (.github/workflows/tests.yml):

name: Run Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python 3.10
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      
      - name: Run tests with coverage
        run: python -m pytest --cov=app --cov-report=xml --cov-report=html
      
      - name: Upload coverage artifact
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: htmlcov/

README.md badge:

[![Tests](https://github.com/neeru24/Agri-Vision/actions/workflows/tests.yml/badge.svg)](https://github.com/neeru24/Agri-Vision/actions/workflows/tests.yml)

Affected Files

  • .github/workflows/tests.yml (new)
  • README.md (add status badge)

Labels

type:devops, level:beginner, type:testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions