Skip to content

Commit

Permalink
Update backend-ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
pdr21001 authored Apr 28, 2025
1 parent e7beee4 commit ea87f44
Showing 1 changed file with 52 additions and 109 deletions.
161 changes: 52 additions & 109 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
@@ -1,144 +1,87 @@
name: Backend CI Pipeline
name: CI Backend Workflow

on:
push:
branches: [main, develop]
branches: [ "main" ]
pull_request:
branches: [main, develop]
branches: [ "main" ]

jobs:
lint:
backend-ci:
runs-on: self-hosted
defaults:
run:
working-directory: backend
working-directory: ./backend

steps:
- name: Checkout code without submodules
uses: actions/checkout@v2 # Using v2 for actions/checkout
with:
submodules: false # Skips submodule initialization

- name: Set up Python
uses: actions/setup-python@v2 # Using v2 for setup-python
with:
python-version: '3.11'

- name: Install dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt # Ensure all dependencies are installed, including requests
- name: Cache Python dependencies
uses: actions/cache@v2 # Using v2 for actions/cache
with:
path: venv
key: ${{ runner.os }}-python-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-python-
- name: Run pylint (backend only on changed files)
run: |
source venv/bin/activate
changed_files=$(git diff --name-only origin/main...HEAD | grep '\.py$' || true)
if [ -n "$changed_files" ]; then
pylint $changed_files --exit-zero | tee pylint.log
SCORE=$(tail -n 2 pylint.log | grep -oP '[0-9]+\.[0-9]+(?=/10)')
echo "Pylint score: $SCORE"
python -c "import sys; sys.exit(0 if float('$SCORE') >= 8.0 else 1)"
else
echo "No Python files changed, skipping pylint."
exit 0 # Exit with status 0 (success) if no Python files changed
fi
test:
runs-on: self-hosted
needs: lint
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword
POSTGRES_DB: testdb
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code without submodules
uses: actions/checkout@v2 # Using v2 for actions/checkout
with:
submodules: false # Skips submodule initialization
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2 # Using v2 for setup-python
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install dependencies
- name: Install backend dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install -r backend/requirements.txt # Ensure all dependencies are installed, including requests
pip install pytest-html
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint pytest requests
- name: Cache Python dependencies
uses: actions/cache@v2 # Using v2 for actions/cache
with:
path: venv
key: ${{ runner.os }}-python-${{ hashFiles('backend/requirements.txt') }}
restore-keys: |
${{ runner.os }}-python-
- name: Run pylint on backend
run: |
pylint $(git ls-files '*.py')
- name: Start Flask API server
- name: Start backend server (background)
run: |
nohup python backend/main.py > flask.log 2>&1 &
for i in {1..10}; do
if curl --silent --fail http://127.0.0.1:5000/; then
echo "Flask is ready"
break
fi
echo "Waiting for Flask... Attempt $i/10"
sleep 5
done
uvicorn main:app --host 0.0.0.0 --port 8000 &
sleep 5 # Wait for server to start
- name: Run backend tests with pytest
env:
BASE_URL: http://127.0.0.1:5000
- name: Run pytest on backend (HTTP API tests)
run: |
source venv/bin/activate # Activate the virtual environment before running tests
pytest backend/tests --html=backend/test-report.html --self-contained-html
pytest tests/
- name: Upload test report
uses: actions/upload-artifact@v2 # Using v2 for actions/upload-artifact
- name: Upload Test Results (optional)
if: always()
uses: actions/upload-artifact@v4
with:
name: backend-test-report
path: backend/test-report.html
name: backend-test-results
path: backend/tests

- name: Kill Flask server
run: |
pkill -f "python backend/main.py" || echo "Flask already exited"
build-frontend:
frontend-build:
runs-on: self-hosted
needs: [lint, test]
defaults:
run:
working-directory: ./frontend

steps:
- name: Checkout repository without submodules
uses: actions/checkout@v2 # Using v2 for actions/checkout
with:
submodules: false # Skips submodule initialization
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3 # Using the latest stable version for Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Cache node modules
uses: actions/cache@v2 # Using v2 for actions/cache
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install frontend dependencies
working-directory: frontend
run: npm install
run: |
npm install
- name: Build frontend app
working-directory: frontend
run: npm run build
- name: Build frontend
run: |
npm run build

0 comments on commit ea87f44

Please sign in to comment.