From 03cf79005562effeb658a67c9021e07b322d4d6f Mon Sep 17 00:00:00 2001 From: Prince D Rusweka Rwabongoya Date: Wed, 23 Apr 2025 19:17:11 -0400 Subject: [PATCH] Update backend-ci.yml --- backend/.github/workflows/backend-ci.yml | 69 +++++++++++++++++------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/backend/.github/workflows/backend-ci.yml b/backend/.github/workflows/backend-ci.yml index 93a0191..607d9b2 100644 --- a/backend/.github/workflows/backend-ci.yml +++ b/backend/.github/workflows/backend-ci.yml @@ -1,39 +1,68 @@ -name: Backend CI +name: Backend CI Pipeline +# Trigger workflow on push or pull request to develop and main branches on: push: - paths: - - 'backend/**' + branches: + - develop + - main pull_request: - paths: - - 'backend/**' + branches: + - develop + - main jobs: - backend-ci: - runs-on: ubuntu-latest + lint: + runs-on: self-hosted steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v2 + with: + python-version: '3.11' # Adjust Python version if needed + + - name: Install dependencies + run: | + python -m venv venv + source venv/bin/activate + pip install -r backend/requirements.txt + + - name: Run pylint on Python code + run: | + source venv/bin/activate + pylint backend/main.py backend/db.py backend/init_db.py # Add more files as needed + + test: + runs-on: self-hosted + needs: lint # Ensure this job runs after linting + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 with: python-version: '3.11' - name: Install dependencies - working-directory: ./backend run: | - pip install -r requirements.txt + python -m venv venv + source venv/bin/activate + pip install -r backend/requirements.txt - - name: Run pylint on backend - working-directory: ./backend + - name: Start the API server run: | - pylint main.py db.py init_db.py + # Start the API server in the background + nohup python backend/main.py & # Replace with the command to start your API + sleep 5 # Wait for the server to be ready (adjust this if needed) - - name: Run Pytest - working-directory: ./backend + - name: Run tests with pytest + env: + BASE_URL: http://127.0.0.1:5000 # Assuming your API is running on this address run: | - python main.py & # Run server - sleep 5 # Give it time to start - pytest tests/ + source venv/bin/activate + pytest backend/tests --maxfail=1 --disable-warnings -q