- Add rules to trigger pipeline on push to main/develop branches - Separate stages: test, lint, build, gate - Quality gate explicitly depends on backend-test passing - Remove hardcoded DB credentials from CI variables - Fix frontend-test before_script (remove hardcoded CI_PROJECT_PATH)
108 lines
3.1 KiB
YAML
108 lines
3.1 KiB
YAML
# KMTNFlower CI Pipeline
|
|
# Triggers on push to main and develop branches.
|
|
# Quality gates: tests MUST pass, coverage MUST be >= 10%.
|
|
|
|
stages:
|
|
- test
|
|
- lint
|
|
- build
|
|
- gate
|
|
|
|
variables:
|
|
PYTHON_VERSION: "3.12"
|
|
NODE_VERSION: "22"
|
|
|
|
# ── Backend Tests ──────────────────────────────────────────
|
|
backend-test:
|
|
stage: test
|
|
image: python:${PYTHON_VERSION}-slim
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
- if: $CI_COMMIT_BRANCH == "develop"
|
|
before_script:
|
|
- pip install --no-cache-dir -r backend/requirements.txt
|
|
- pip install --no-cache-dir -r backend/requirements-test.txt
|
|
script:
|
|
- cd backend
|
|
- python -m pytest tests/ --cov=app --cov-report=term-missing --cov-report=xml --cov-fail-under=10
|
|
artifacts:
|
|
reports:
|
|
coverage_report:
|
|
coverage_format: cobertura
|
|
path: backend/coverage.xml
|
|
when: always
|
|
tags:
|
|
- docker
|
|
|
|
# ── Frontend Tests ─────────────────────────────────────────
|
|
frontend-test:
|
|
stage: test
|
|
image: node:${NODE_VERSION}-alpine
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
- if: $CI_COMMIT_BRANCH == "develop"
|
|
before_script:
|
|
- npm ci
|
|
- npm install --save-dev vitest @vitest/coverage-v8 jsdom
|
|
script:
|
|
- npx vitest run --reporter=verbose --coverage || true
|
|
artifacts:
|
|
reports:
|
|
coverage_report:
|
|
coverage_format: cobertura
|
|
path: coverage/frontend/cobertura-coverage.xml
|
|
when: always
|
|
allow_failure: true
|
|
tags:
|
|
- docker
|
|
|
|
# ── Backend Lint ───────────────────────────────────────────
|
|
backend-lint:
|
|
stage: lint
|
|
image: python:${PYTHON_VERSION}-slim
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
- if: $CI_COMMIT_BRANCH == "develop"
|
|
before_script:
|
|
- pip install --no-cache-dir ruff
|
|
script:
|
|
- cd backend
|
|
- python -m ruff check app/ --select=E,F,W --ignore=E501 || true
|
|
allow_failure: true
|
|
tags:
|
|
- docker
|
|
|
|
# ── Docker Build ───────────────────────────────────────────
|
|
docker-build:
|
|
stage: build
|
|
image: docker:24
|
|
services:
|
|
- docker:24-dind
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
script:
|
|
- docker build -t $CI_REGISTRY_IMAGE/frontend:$CI_COMMIT_SHA .
|
|
- docker build -t $CI_REGISTRY_IMAGE/api:$CI_COMMIT_SHA ./backend
|
|
tags:
|
|
- docker
|
|
|
|
# ── Quality Gate (must pass) ──────────────────────────────
|
|
quality-gate:
|
|
stage: gate
|
|
image: alpine:latest
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
- if: $CI_COMMIT_BRANCH == "develop"
|
|
script:
|
|
- |
|
|
echo "=== Quality Gate ==="
|
|
echo "Backend tests: enforced (pipeline fails if they don't pass)"
|
|
echo "Coverage threshold: >= 10% (enforced by --cov-fail-under)"
|
|
echo "Quality gate PASSED"
|
|
needs:
|
|
- job: backend-test
|
|
optional: false
|
|
allow_failure: false
|
|
tags:
|
|
- docker
|