Files
errors.bitreport.pt/docs/CI_PIPELINE.md
David Santos 0bd13bac5b feat(ci): implement Gitea Actions CI/CD pipeline
Add automated test, build, and validation pipeline:
- Test stages: npm test for ingest-api and api (Vitest)
- Lint/typecheck: admin-ui (Next.js ESLint + TypeScript)
- Docker build validation: validate all service containers
- Parallel jobs with Node 20, npm cache for fast iteration
- Documentation: docs/CI_PIPELINE.md with setup and troubleshooting

Addresses BIT-2498, BIT-2481 acceptance criteria for CI pipeline.

Paperclip-Agent: Patrícia Santos (urlKey patr-cia-santos; id 0f76874a-ad67-4a54-86f1-68a54dd1996f)
Paperclip-Issue: BIT-2498
2026-04-12 09:23:04 +00:00

157 lines
4.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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)