diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..733b545 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,94 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test-ingest-api: + name: Test ingest-api + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: 'ingest-api/package-lock.json' + + - name: Install dependencies + working-directory: ingest-api + run: npm ci + + - name: Run tests + working-directory: ingest-api + run: npm test + + test-api: + name: Test api + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: 'api/package-lock.json' + + - name: Install dependencies + working-directory: api + run: npm ci + + - name: Run tests + working-directory: api + run: npm test + + lint-admin-ui: + name: Lint and typecheck admin-ui + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: 'admin-ui/package-lock.json' + + - name: Install dependencies + working-directory: admin-ui + run: npm ci + + - name: Run linter + working-directory: admin-ui + run: npm run lint + + - name: Type check + working-directory: admin-ui + run: npm run typecheck + + docker-build: + name: Validate Docker build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker images + run: docker compose build + env: + ER_MYSQL_ROOT_PASSWORD: devrootchange + ER_MYSQL_USER: er_app + ER_MYSQL_PASSWORD: er_app_secret + ER_MYSQL_DATABASE: error_reporting diff --git a/docs/CI_PIPELINE.md b/docs/CI_PIPELINE.md new file mode 100644 index 0000000..13abc1f --- /dev/null +++ b/docs/CI_PIPELINE.md @@ -0,0 +1,156 @@ +# CI/CD Pipeline — BitReport Error Reporting + +## Overview + +This document describes the Gitea Actions CI/CD pipeline for the `errors.bitreport.pt` project. The pipeline automatically tests, validates, and builds all services on every commit to the `master` branch and on pull requests. + +## Pipeline Structure + +The CI pipeline runs four independent validation jobs in parallel: + +### 1. **Test ingest-api** (`test-ingest-api`) + +Tests the Node.js ingest API service using Vitest. + +- **Service:** `ingest-api/` +- **Steps:** + - Node.js 20 setup with npm cache + - `npm ci` — install dependencies with exact versions + - `npm test` — runs Vitest unit tests + Python validation of error reporter context contract +- **Purpose:** Validates ingest API logic and contract with client SDKs + +### 2. **Test api** (`test-api`) + +Tests the Node.js admin API service using Vitest. + +- **Service:** `api/` +- **Steps:** + - Node.js 20 setup with npm cache + - `npm ci` — install dependencies + - `npm test` — runs Vitest unit tests +- **Purpose:** Validates admin API logic and type safety + +### 3. **Lint and Typecheck admin-ui** (`lint-admin-ui`) + +Validates frontend code quality and type safety. + +- **Service:** `admin-ui/` +- **Steps:** + - Node.js 20 setup with npm cache + - `npm ci` — install dependencies + - `npm run lint` — Next.js ESLint validation + - `npm run typecheck` — TypeScript type checking +- **Purpose:** Ensures admin UI code quality before runtime testing + +### 4. **Validate Docker Build** (`docker-build`) + +Builds all Docker images defined in `docker-compose.yml`. + +- **Services:** ingest-api, collector-worker, admin-ui +- **Steps:** + - Docker Buildx setup for multi-platform builds + - `docker compose build` — validates all Dockerfiles and layers + - Environment variables provided for build-time configuration +- **Purpose:** Ensures production container images build cleanly + +## Trigger Events + +The pipeline runs automatically on: + +1. **Push to master** — every commit merged to main branch +2. **Pull requests** — on creation and on new pushes to PR branches + +## Dependencies and Runtime + +- **Node.js version:** 20 (as specified in `ingest-api/package.json` and `api/package.json`) +- **Runtime:** Ubuntu latest +- **Parallel execution:** All four jobs run in parallel; no job waits for another +- **Total runtime:** ~5–10 minutes (depending on dependency installation and test suite size) + +## Caching + +NPM package caches are built per service based on their `package-lock.json` files: +- `ingest-api/package-lock.json` +- `api/package-lock.json` +- `admin-ui/package-lock.json` + +This accelerates dependency installation on subsequent runs. + +## Configuration + +### Workflow file + +Location: `.gitea/workflows/ci.yml` + +Modify this file to: +- Add or remove services +- Change trigger branches +- Adjust Node.js version +- Add new jobs (e.g., integration tests, security scanning) + +### Environment Variables (Docker Build) + +The `docker-build` job provides standard dev environment values: + +```yaml +ER_MYSQL_ROOT_PASSWORD: devrootchange +ER_MYSQL_USER: er_app +ER_MYSQL_PASSWORD: er_app_secret +ER_MYSQL_DATABASE: error_reporting +``` + +To change defaults (e.g., for staging builds), update these in the workflow file. + +## Failure Handling + +If any job fails, the entire pipeline is marked as failed. Pull requests will show a **red check** and cannot be merged until all jobs pass. + +### Common Failure Causes + +| Job | Cause | Resolution | +|-----|-------|-----------| +| `test-ingest-api` | Failed Vitest or Python validation | Check ingest API tests and client SDK contract | +| `test-api` | Failed Vitest | Check API tests and type safety | +| `lint-admin-ui` | Lint errors or type errors | Fix ESLint violations and TypeScript errors | +| `docker-build` | Layer build failure, missing Dockerfile | Check Dockerfile syntax and base image availability | + +## Local Testing + +To replicate the CI pipeline locally: + +```bash +# Test ingest-api +cd ingest-api +npm ci && npm test +cd .. + +# Test api +cd api +npm ci && npm test +cd .. + +# Test admin-ui +cd admin-ui +npm ci && npm run lint && npm run typecheck +cd .. + +# Validate Docker build +docker compose build +``` + +## Future Enhancements + +Potential pipeline extensions: + +1. **Integration Tests** — Run full stack with docker-compose (requires longer runtime) +2. **Performance Benchmarks** — Track API response times over time +3. **Security Scanning** — SAST, dependency vulnerability checks +4. **Coverage Reports** — Publish code coverage metrics +5. **Artifact Publishing** — Push built images to registry on master merges +6. **Staged Deployments** — Auto-deploy to staging/production environments + +--- + +**Last updated:** 2026-04-12 +**Maintained by:** Planner Agent (Patrícia Santos) +**Related issues:** [BIT-2481](/BIT/issues/BIT-2481), [BIT-2498](/BIT/issues/BIT-2498)