Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 41 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
name: CI Pipeline

on:
on: # yamllint disable-line rule:truthy
push:
branches: [ main, develop ]
branches: [main, develop]
pull_request:
branches: [ main, develop ]
branches: [main, develop]

env:
PYTHON_VERSION: '3.9'
Expand All @@ -16,7 +17,7 @@ jobs:
backend:
name: Backend CI
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15-alpine
Expand All @@ -31,7 +32,7 @@ jobs:
--health-retries 5
ports:
- 5432:5432

redis:
image: redis:7-alpine
options: >-
Expand Down Expand Up @@ -60,21 +61,21 @@ jobs:
${{ runner.os }}-pip-

- name: Install dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest pytest-cov pytest-asyncio black flake8 mypy bandit safety
pip install pytest pytest-cov pytest-asyncio black flake8 mypy \
bandit safety

- name: Run linting
working-directory: ./backend
run: |
echo "Running Black formatter check..."
black --check app/

echo "Running Flake8 linter..."
flake8 app/ --max-line-length=120 --extend-ignore=E203,W503

echo "Running type checking with mypy..."
mypy app/ --ignore-missing-imports || true

Expand All @@ -83,22 +84,24 @@ jobs:
run: |
echo "Running Bandit security linter..."
bandit -r app/ -f json -o bandit-report.json || true

echo "Checking dependencies for vulnerabilities..."
safety check --json || true

- name: Run tests
working-directory: ./backend
env:
DATABASE_URL: postgresql://openwatch:openwatch_test@localhost:5432/openwatch_test
DATABASE_URL: >
postgresql://openwatch:openwatch_test@localhost:5432/openwatch_test
REDIS_URL: redis://localhost:6379
JWT_SECRET_KEY: test_secret_key_for_ci
ENVIRONMENT: test
run: |
# Check if tests directory exists
if [ -d "tests" ] && [ "$(find tests -name '*.py' | head -1)" ]; then
echo "Running pytest tests..."
pytest tests/ -v --cov=app --cov-report=xml --cov-report=html || echo "Some tests failed but continuing..."
pytest tests/ -v --cov=app --cov-report=xml \
--cov-report=html || echo "Some tests failed but continuing..."
else
echo "No test files found in tests/ directory, skipping pytest"
echo "This is normal for early development stages"
Expand All @@ -113,13 +116,14 @@ jobs:

- name: Build Docker image
run: |
docker build -f docker/Dockerfile.backend -t openwatch-backend:${{ github.sha }} .
docker build -f docker/Dockerfile.backend \
-t openwatch-backend:${{ github.sha }} .

# Frontend Testing and Building
frontend:
name: Frontend CI
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -146,7 +150,7 @@ jobs:
run: |
echo "Running ESLint..."
npm run lint || true

echo "Running TypeScript type check..."
npx tsc --noEmit

Expand All @@ -168,14 +172,15 @@ jobs:

- name: Build Docker image
run: |
docker build -f docker/Dockerfile.frontend -t openwatch-frontend:${{ github.sha }} .
docker build -f docker/Dockerfile.frontend \
-t openwatch-frontend:${{ github.sha }} .

# Integration Tests
integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: [backend, frontend]

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -190,28 +195,29 @@ jobs:
# Start services with docker compose
echo "Starting services with docker-compose..."
docker compose up -d

# Wait for services to be ready
echo "Waiting for services to be ready..."
sleep 45

# Check if health check script exists and use it
if [ -f "./scripts/production-health-check.sh" ]; then
echo "Running health checks..."
./scripts/production-health-check.sh --local || echo "Health checks completed with warnings"
./scripts/production-health-check.sh --local || \
echo "Health checks completed with warnings"
else
echo "Running basic connectivity tests..."
# Check basic connectivity with retries
for i in {1..3}; do
if curl -f --max-time 10 http://localhost:3001 >/dev/null 2>&1; then
echo "Frontend connectivity: OK"
echo "Frontend OK"
break
else
echo "Frontend connectivity attempt $i failed, retrying..."
sleep 10
fi
done

for i in {1..3}; do
if curl -f --max-time 10 http://localhost:8000/health >/dev/null 2>&1; then
echo "Backend connectivity: OK"
Expand All @@ -222,15 +228,15 @@ jobs:
fi
done
fi

# Show service status
echo "Service status:"
docker compose ps

# Show logs for debugging
echo "Recent logs:"
docker compose logs --tail=20

# Clean up
docker compose down -v

Expand All @@ -239,7 +245,7 @@ jobs:
name: E2E Tests
runs-on: ubuntu-latest
needs: [backend, frontend]

services:
postgres:
image: postgres:15-alpine
Expand All @@ -254,7 +260,7 @@ jobs:
--health-retries 5
ports:
- 5432:5432

redis:
image: redis:7-alpine
options: >-
Expand All @@ -264,7 +270,7 @@ jobs:
--health-retries 5
ports:
- 6379:6379

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -288,22 +294,22 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install backend dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Start backend service
working-directory: ./backend
env:
DATABASE_URL: postgresql://openwatch:openwatch_test@localhost:5432/openwatch_test
DATABASE_URL: >
postgresql://openwatch:openwatch_test@localhost:5432/openwatch_test
REDIS_URL: redis://localhost:6379
JWT_SECRET_KEY: test_secret_key_for_e2e
ENVIRONMENT: test
run: |
# Start backend in background
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 &

# Wait for backend to start
timeout 60 bash -c 'until curl -f http://localhost:8000/health; do sleep 2; done'

Expand All @@ -326,10 +332,10 @@ jobs:
run: |
# Start frontend in background
npm run dev &

# Wait for frontend to be ready
timeout 60 bash -c 'until curl -f http://localhost:3001; do sleep 2; done'

# Run E2E tests
npx playwright test --reporter=html,junit

Expand All @@ -356,7 +362,7 @@ jobs:
runs-on: ubuntu-latest
needs: [backend, frontend, integration, e2e]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -393,4 +399,4 @@ jobs:
ghcr.io/${{ github.repository_owner }}/openwatch-frontend:latest
ghcr.io/${{ github.repository_owner }}/openwatch-frontend:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
4 changes: 2 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install black flake8 pylint mypy bandit vulture radon
cd backend && pip install -r requirements.txt
pip install -r requirements.txt

- name: Black formatter
run: |
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
- name: Generate Python coverage
working-directory: ./backend
run: |
pip install -r requirements.txt
pip install -r ../requirements.txt
pip install pytest pytest-cov
pytest tests/ --cov=app --cov-report=xml --cov-report=term || true

Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/test-ci-fixes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test CI Fixes

on:
workflow_dispatch:

jobs:
test-backend-deps:
name: Test Backend Dependencies
runs-on: ubuntu-latest

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

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

- name: Test requirements.txt location
run: |
echo "Checking if requirements.txt exists at root..."
if [ -f requirements.txt ]; then
echo "βœ“ requirements.txt found at root"
else
echo "βœ— requirements.txt not found at root"
exit 1
fi

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
echo "βœ“ Dependencies installed successfully"

- name: Test backend directory
run: |
echo "Checking backend directory structure..."
ls -la backend/
echo "βœ“ Backend directory verified"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ nginx.conf

# Gitignore analysis files
gitignore_*.md
.github/
# .github/ # Needed for GitHub Actions

# ======================================
# RPM PACKAGE BUILDING FILES
Expand Down
Loading
Loading