|
| 1 | +name: Frontend Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, dev] |
| 6 | + paths: |
| 7 | + - 'frontend/**' |
| 8 | + - '.github/workflows/frontend-tests.yml' |
| 9 | + pull_request: |
| 10 | + branches: [main, dev] |
| 11 | + paths: |
| 12 | + - 'frontend/**' |
| 13 | + - '.github/workflows/frontend-tests.yml' |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +jobs: |
| 17 | + unit-tests: |
| 18 | + name: Unit Tests |
| 19 | + runs-on: ubuntu-latest |
| 20 | + defaults: |
| 21 | + run: |
| 22 | + working-directory: frontend |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Setup Node.js |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: '22' |
| 30 | + cache: 'npm' |
| 31 | + cache-dependency-path: frontend/package-lock.json |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: npm ci |
| 35 | + |
| 36 | + - name: Run unit tests |
| 37 | + run: npm test |
| 38 | + |
| 39 | + - name: Run tests with coverage |
| 40 | + run: npm run test:coverage |
| 41 | + |
| 42 | + - name: Upload coverage report |
| 43 | + uses: actions/upload-artifact@v4 |
| 44 | + if: always() |
| 45 | + with: |
| 46 | + name: frontend-coverage |
| 47 | + path: frontend/coverage/ |
| 48 | + |
| 49 | + e2e-tests: |
| 50 | + name: E2E Tests |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: unit-tests |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Setup Docker Buildx |
| 57 | + uses: docker/setup-buildx-action@v3 |
| 58 | + |
| 59 | + - name: Install yq |
| 60 | + run: | |
| 61 | + sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq |
| 62 | + sudo chmod +x /usr/local/bin/yq |
| 63 | +
|
| 64 | + - name: Setup Kubernetes (k3s) |
| 65 | + run: | |
| 66 | + curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable=traefik --tls-san host.docker.internal" sh - |
| 67 | + mkdir -p $HOME/.kube |
| 68 | + sudo k3s kubectl config view --raw > $HOME/.kube/config |
| 69 | + sudo chmod 600 $HOME/.kube/config |
| 70 | + timeout 90 bash -c 'until sudo k3s kubectl cluster-info; do sleep 5; done' |
| 71 | +
|
| 72 | + - name: Create kubeconfig for CI |
| 73 | + run: | |
| 74 | + cat > backend/kubeconfig.yaml <<EOF |
| 75 | + apiVersion: v1 |
| 76 | + kind: Config |
| 77 | + clusters: |
| 78 | + - name: ci-cluster |
| 79 | + cluster: |
| 80 | + server: https://host.docker.internal:6443 |
| 81 | + insecure-skip-tls-verify: true |
| 82 | + users: |
| 83 | + - name: ci-user |
| 84 | + user: |
| 85 | + token: "ci-token" |
| 86 | + contexts: |
| 87 | + - name: ci |
| 88 | + context: |
| 89 | + cluster: ci-cluster |
| 90 | + user: ci-user |
| 91 | + current-context: ci |
| 92 | + EOF |
| 93 | +
|
| 94 | + - name: Pre-pull base images |
| 95 | + run: | |
| 96 | + docker pull python:3.12-slim & |
| 97 | + docker pull ghcr.io/astral-sh/uv:0.9.18 & |
| 98 | + docker pull node:22-alpine & |
| 99 | + docker pull confluentinc/cp-kafka:7.5.0 & |
| 100 | + docker pull confluentinc/cp-zookeeper:7.5.0 & |
| 101 | + docker pull mongo:8.0 & |
| 102 | + docker pull redis:7-alpine & |
| 103 | + wait |
| 104 | +
|
| 105 | + - name: Modify Docker Compose for CI |
| 106 | + run: | |
| 107 | + cp docker-compose.yaml docker-compose.ci.yaml |
| 108 | + yq eval '.services.backend.environment += ["TESTING=true"]' -i docker-compose.ci.yaml |
| 109 | + yq eval '.services.backend.environment += ["MONGO_ROOT_USER=root"]' -i docker-compose.ci.yaml |
| 110 | + yq eval '.services.backend.environment += ["MONGO_ROOT_PASSWORD=rootpassword"]' -i docker-compose.ci.yaml |
| 111 | + yq eval '.services.backend.environment += ["OTEL_SDK_DISABLED=true"]' -i docker-compose.ci.yaml |
| 112 | + yq eval '.services.backend.volumes = [.services.backend.volumes[] | select(. != "./backend:/app")]' -i docker-compose.ci.yaml |
| 113 | + yq eval '.services."k8s-worker".volumes = [.services."k8s-worker".volumes[] | select(. != "./backend:/app:ro")]' -i docker-compose.ci.yaml |
| 114 | + yq eval '.services."pod-monitor".volumes = [.services."pod-monitor".volumes[] | select(. != "./backend:/app:ro")]' -i docker-compose.ci.yaml |
| 115 | + yq eval '.services."result-processor".volumes = [.services."result-processor".volumes[] | select(. != "./backend:/app:ro")]' -i docker-compose.ci.yaml |
| 116 | + yq eval 'del(.services.kafka.environment.KAFKA_OPTS)' -i docker-compose.ci.yaml |
| 117 | + yq eval 'del(.services.zookeeper.environment.KAFKA_OPTS)' -i docker-compose.ci.yaml |
| 118 | + yq eval 'del(.services.zookeeper.environment.ZOOKEEPER_AUTH_PROVIDER_1)' -i docker-compose.ci.yaml |
| 119 | + yq eval '.services.kafka.volumes = [.services.kafka.volumes[] | select(. | contains("jaas.conf") | not)]' -i docker-compose.ci.yaml |
| 120 | + yq eval '.services.zookeeper.volumes = [.services.zookeeper.volumes[] | select(. | contains("/etc/kafka") | not)]' -i docker-compose.ci.yaml |
| 121 | + yq eval '.services.zookeeper.environment.ZOOKEEPER_4LW_COMMANDS_WHITELIST = "ruok,srvr"' -i docker-compose.ci.yaml |
| 122 | + yq eval 'del(.services.zookeeper.healthcheck)' -i docker-compose.ci.yaml |
| 123 | + yq eval '.services.kafka.depends_on.zookeeper.condition = "service_started"' -i docker-compose.ci.yaml |
| 124 | + yq eval 'select(.services."cert-generator".extra_hosts == null).services."cert-generator".extra_hosts = []' -i docker-compose.ci.yaml |
| 125 | + yq eval '.services."cert-generator".extra_hosts += ["host.docker.internal:host-gateway"]' -i docker-compose.ci.yaml |
| 126 | + yq eval '.services."cert-generator".environment += ["CI=true"]' -i docker-compose.ci.yaml |
| 127 | + yq eval '.services."cert-generator".volumes += [env(HOME) + "/.kube/config:/root/.kube/config:ro"]' -i docker-compose.ci.yaml |
| 128 | +
|
| 129 | + - name: Build services |
| 130 | + uses: docker/bake-action@v6 |
| 131 | + with: |
| 132 | + source: . |
| 133 | + files: docker-compose.ci.yaml |
| 134 | + load: true |
| 135 | + set: | |
| 136 | + *.cache-from=type=gha,scope=buildkit-${{ github.repository }}-${{ github.ref_name }} |
| 137 | + *.cache-from=type=gha,scope=buildkit-${{ github.repository }}-main |
| 138 | + *.cache-to=type=gha,mode=max,scope=buildkit-${{ github.repository }}-${{ github.ref_name }} |
| 139 | + env: |
| 140 | + BUILDKIT_PROGRESS: plain |
| 141 | + |
| 142 | + - name: Start services |
| 143 | + run: | |
| 144 | + docker compose -f docker-compose.ci.yaml up -d --remove-orphans |
| 145 | + docker compose -f docker-compose.ci.yaml ps |
| 146 | +
|
| 147 | + - name: Wait for backend |
| 148 | + run: | |
| 149 | + curl --retry 60 --retry-delay 5 --retry-all-errors -ksf https://127.0.0.1:443/api/v1/health/live |
| 150 | +
|
| 151 | + - name: Wait for frontend |
| 152 | + run: | |
| 153 | + curl --retry 30 --retry-delay 5 --retry-all-errors -ksf https://127.0.0.1:5001/ || true |
| 154 | +
|
| 155 | + - name: Setup Node.js |
| 156 | + uses: actions/setup-node@v4 |
| 157 | + with: |
| 158 | + node-version: '22' |
| 159 | + cache: 'npm' |
| 160 | + cache-dependency-path: frontend/package-lock.json |
| 161 | + |
| 162 | + - name: Install frontend dependencies |
| 163 | + working-directory: frontend |
| 164 | + run: npm ci |
| 165 | + |
| 166 | + - name: Install Playwright browsers |
| 167 | + working-directory: frontend |
| 168 | + run: npx playwright install chromium |
| 169 | + |
| 170 | + - name: Run E2E tests |
| 171 | + working-directory: frontend |
| 172 | + env: |
| 173 | + CI: true |
| 174 | + run: npx playwright test --reporter=html |
| 175 | + |
| 176 | + - name: Upload Playwright report |
| 177 | + uses: actions/upload-artifact@v4 |
| 178 | + if: always() |
| 179 | + with: |
| 180 | + name: playwright-report |
| 181 | + path: frontend/playwright-report/ |
| 182 | + |
| 183 | + - name: Collect logs on failure |
| 184 | + if: failure() |
| 185 | + run: | |
| 186 | + mkdir -p logs |
| 187 | + docker compose -f docker-compose.ci.yaml logs > logs/docker-compose.log |
| 188 | + docker compose -f docker-compose.ci.yaml logs frontend > logs/frontend.log |
| 189 | + docker compose -f docker-compose.ci.yaml logs backend > logs/backend.log |
| 190 | +
|
| 191 | + - name: Upload logs |
| 192 | + if: failure() |
| 193 | + uses: actions/upload-artifact@v4 |
| 194 | + with: |
| 195 | + name: e2e-test-logs |
| 196 | + path: logs/ |
0 commit comments