95 lines
2.3 KiB
YAML
95 lines
2.3 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: host
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
echo "Code already available in workspace"
|
|
pwd
|
|
ls -la
|
|
echo "Checking for backend and frontend directories:"
|
|
ls -la backend/ 2>/dev/null || echo "backend directory not found"
|
|
ls -la frontend/ 2>/dev/null || echo "frontend directory not found"
|
|
|
|
- name: Check Node.js version
|
|
run: |
|
|
which node || echo "Node.js not found in PATH"
|
|
node --version || echo "Node.js not available"
|
|
which npm || echo "npm not found in PATH"
|
|
npm --version || echo "npm not available"
|
|
|
|
- name: Install backend dependencies
|
|
run: |
|
|
if [ -d "backend" ]; then
|
|
cd backend
|
|
npm ci
|
|
else
|
|
echo "Backend directory not found, skipping backend dependencies"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Run backend tests
|
|
env:
|
|
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/nfoguard_test
|
|
JWT_SECRET: test-secret-key-for-ci
|
|
NODE_ENV: test
|
|
run: |
|
|
if [ -d "backend" ]; then
|
|
cd backend
|
|
npm run test
|
|
else
|
|
echo "Backend directory not found, skipping backend tests"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Install frontend dependencies
|
|
run: |
|
|
if [ -d "frontend" ]; then
|
|
cd frontend
|
|
npm ci
|
|
else
|
|
echo "Frontend directory not found, skipping frontend dependencies"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Run frontend tests
|
|
run: |
|
|
if [ -d "frontend" ]; then
|
|
cd frontend
|
|
npm run test
|
|
else
|
|
echo "Frontend directory not found, skipping frontend tests"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Build frontend
|
|
run: |
|
|
if [ -d "frontend" ]; then
|
|
cd frontend
|
|
npm run build
|
|
else
|
|
echo "Frontend directory not found, skipping frontend build"
|
|
exit 1
|
|
fi
|
|
|
|
deploy:
|
|
needs: test
|
|
runs-on: host
|
|
if: github.ref == 'refs/heads/main'
|
|
|
|
steps:
|
|
- name: Deploy application
|
|
run: |
|
|
echo "Deploying to production..."
|
|
echo "Current directory: $(pwd)"
|
|
echo "Available files:"
|
|
ls -la |