|
| 1 | +name: Test Suite |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + frontend-tests: |
| 11 | + name: Frontend Tests |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + defaults: |
| 15 | + run: |
| 16 | + working-directory: ./frontend |
| 17 | + |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + node-version: [18.x, 20.x] |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: ${{ matrix.node-version }} |
| 30 | + cache: 'npm' |
| 31 | + cache-dependency-path: frontend/package-lock.json |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: npm ci |
| 35 | + |
| 36 | + - name: Run type checking |
| 37 | + run: npm run typecheck |
| 38 | + |
| 39 | + - name: Run tests |
| 40 | + run: npm run test:run |
| 41 | + |
| 42 | + - name: Run tests with coverage |
| 43 | + run: npm run test:coverage |
| 44 | + |
| 45 | + - name: Upload frontend coverage to Codecov |
| 46 | + uses: codecov/codecov-action@v4 |
| 47 | + with: |
| 48 | + file: ./frontend/coverage/lcov.info |
| 49 | + flags: frontend |
| 50 | + name: frontend-coverage |
| 51 | + fail_ci_if_error: false |
| 52 | + |
| 53 | + backend-tests: |
| 54 | + name: Backend Tests |
| 55 | + runs-on: ubuntu-latest |
| 56 | + |
| 57 | + defaults: |
| 58 | + run: |
| 59 | + working-directory: ./backend |
| 60 | + |
| 61 | + strategy: |
| 62 | + matrix: |
| 63 | + node-version: [18.x, 20.x] |
| 64 | + |
| 65 | + steps: |
| 66 | + - name: Checkout code |
| 67 | + uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 70 | + uses: actions/setup-node@v4 |
| 71 | + with: |
| 72 | + node-version: ${{ matrix.node-version }} |
| 73 | + cache: 'npm' |
| 74 | + cache-dependency-path: backend/package-lock.json |
| 75 | + |
| 76 | + - name: Install dependencies |
| 77 | + run: npm ci |
| 78 | + |
| 79 | + - name: Run tests |
| 80 | + run: npm test |
| 81 | + |
| 82 | + - name: Run tests with coverage |
| 83 | + run: npm run test:coverage |
| 84 | + |
| 85 | + - name: Upload backend coverage to Codecov |
| 86 | + uses: codecov/codecov-action@v4 |
| 87 | + with: |
| 88 | + file: ./backend/coverage/lcov.info |
| 89 | + flags: backend |
| 90 | + name: backend-coverage |
| 91 | + fail_ci_if_error: false |
| 92 | + |
| 93 | + integration-tests: |
| 94 | + name: Integration Tests |
| 95 | + runs-on: ubuntu-latest |
| 96 | + needs: [frontend-tests, backend-tests] |
| 97 | + |
| 98 | + steps: |
| 99 | + - name: Checkout code |
| 100 | + uses: actions/checkout@v4 |
| 101 | + |
| 102 | + - name: Setup Node.js |
| 103 | + uses: actions/setup-node@v4 |
| 104 | + with: |
| 105 | + node-version: '20.x' |
| 106 | + cache: 'npm' |
| 107 | + |
| 108 | + - name: Install backend dependencies |
| 109 | + working-directory: ./backend |
| 110 | + run: npm ci |
| 111 | + |
| 112 | + - name: Install frontend dependencies |
| 113 | + working-directory: ./frontend |
| 114 | + run: npm ci |
| 115 | + |
| 116 | + - name: Start backend server |
| 117 | + working-directory: ./backend |
| 118 | + run: | |
| 119 | + npm start & |
| 120 | + sleep 10 |
| 121 | + curl -f http://localhost:8000/api/health || exit 1 |
| 122 | + env: |
| 123 | + PORT: 8000 |
| 124 | + |
| 125 | + - name: Build frontend |
| 126 | + working-directory: ./frontend |
| 127 | + run: npm run build |
| 128 | + env: |
| 129 | + VITE_API_URL: http://localhost:8000 |
| 130 | + |
| 131 | + python-ml-tests: |
| 132 | + name: Python ML Pipeline Tests |
| 133 | + runs-on: ubuntu-latest |
| 134 | + |
| 135 | + steps: |
| 136 | + - name: Checkout code |
| 137 | + uses: actions/checkout@v4 |
| 138 | + |
| 139 | + - name: Setup Python |
| 140 | + uses: actions/setup-python@v4 |
| 141 | + with: |
| 142 | + python-version: '3.9' |
| 143 | + cache: 'pip' |
| 144 | + |
| 145 | + - name: Install Python dependencies |
| 146 | + run: | |
| 147 | + python -m pip install --upgrade pip |
| 148 | + pip install -r requirements.txt |
| 149 | + pip install pytest pytest-cov |
| 150 | + |
| 151 | + - name: Run Python tests (if they exist) |
| 152 | + run: | |
| 153 | + if [ -d "tests" ] || [ -f "test_*.py" ] || find . -name "*_test.py" | grep -q .; then |
| 154 | + python -m pytest --cov=src --cov-report=xml --cov-report=term |
| 155 | + else |
| 156 | + echo "No Python tests found, skipping..." |
| 157 | + fi |
| 158 | + |
| 159 | + - name: Validate Python syntax |
| 160 | + run: | |
| 161 | + python -m py_compile main.py |
| 162 | + python -m py_compile config.py |
| 163 | + find src -name "*.py" -exec python -m py_compile {} \; |
| 164 | +
|
| 165 | + security-scan: |
| 166 | + name: Security Scan |
| 167 | + runs-on: ubuntu-latest |
| 168 | + |
| 169 | + steps: |
| 170 | + - name: Checkout code |
| 171 | + uses: actions/checkout@v4 |
| 172 | + |
| 173 | + - name: Setup Node.js |
| 174 | + uses: actions/setup-node@v4 |
| 175 | + with: |
| 176 | + node-version: '20.x' |
| 177 | + |
| 178 | + - name: Run npm audit for frontend |
| 179 | + working-directory: ./frontend |
| 180 | + run: npm audit --audit-level=moderate |
| 181 | + continue-on-error: true |
| 182 | + |
| 183 | + - name: Run npm audit for backend |
| 184 | + working-directory: ./backend |
| 185 | + run: npm audit --audit-level=moderate |
| 186 | + continue-on-error: true |
0 commit comments