name: CI/CD Pipeline on: push: branches: [ main, develop ] pull_request: branches: [ main, develop ] jobs: backend: name: Backend Tests runs-on: ubuntu-latest services: postgres: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: test_db options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 steps: - name: Checkout code uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - name: Cache cargo registry uses: actions/cache@v3 with: path: ~/.cargo/registry key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v3 with: path: ~/.cargo/git key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo build uses: actions/cache@v3 with: path: target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y libpq-dev - name: Run cargo fmt run: cd backend && cargo fmt -- --check - name: Run cargo clippy run: cd backend && cargo clippy -- -D warnings - name: Run tests env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db run: cd backend && cargo test -- --nocapture - name: Build env: DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db run: cd backend && cargo build --release frontend: name: Frontend Tests runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' cache-dependency-path: frontend/package-lock.json - name: Install dependencies run: cd frontend && npm ci - name: Run ESLint run: cd frontend && npm run lint - name: Run tests run: cd frontend && npm test -- --coverage --watchAll=false - name: Build run: cd frontend && npm run build docker: name: Docker Build runs-on: ubuntu-latest needs: [backend, frontend] steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and push Docker images run: | docker-compose build echo "Docker images built successfully" security: name: Security Scan runs-on: ubuntu-latest needs: [backend, frontend] steps: - name: Checkout code uses: actions/checkout@v4 - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master with: scan-type: 'fs' scan-ref: '.' format: 'sarif' output: 'trivy-results.sarif' - name: Upload Trivy results to GitHub Security uses: github/codeql-action/upload-sarif@v2 if: always() with: sarif_file: 'trivy-results.sarif'