Skip to content

chore: speed-up of CI tests #103

chore: speed-up of CI tests

chore: speed-up of CI tests #103

Workflow file for this run

name: Backend CI
on:
push:
branches: [main, dev]
paths:
- 'backend/**'
- '.github/workflows/backend-ci.yml'
- 'docker-compose.ci.yaml'
pull_request:
branches: [main, dev]
paths:
- 'backend/**'
- '.github/workflows/backend-ci.yml'
- 'docker-compose.ci.yaml'
workflow_dispatch:
# Pin image versions for cache key consistency
env:
MONGO_IMAGE: mongo:8.0
REDIS_IMAGE: redis:7-alpine
KAFKA_IMAGE: apache/kafka:3.9.0
SCHEMA_REGISTRY_IMAGE: confluentinc/cp-schema-registry:7.5.0
jobs:
unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "backend/uv.lock"
- name: Install Python dependencies
run: |
cd backend
uv python install 3.12
uv sync --frozen
- name: Run unit tests
timeout-minutes: 5
run: |
cd backend
uv run pytest tests/unit -v -rs \
--cov=app \
--cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: backend/coverage.xml
flags: backend-unit
name: backend-unit-coverage
fail_ci_if_error: false
verbose: true
integration:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Cache and load Docker images
uses: ./.github/actions/docker-cache
with:
images: ${{ env.MONGO_IMAGE }} ${{ env.REDIS_IMAGE }} ${{ env.KAFKA_IMAGE }} ${{ env.SCHEMA_REGISTRY_IMAGE }}
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "backend/uv.lock"
- name: Install Python dependencies
run: |
cd backend
uv python install 3.12
uv sync --frozen
- name: Start infrastructure services
run: |
docker compose -f docker-compose.ci.yaml up -d --wait --wait-timeout 120
docker compose -f docker-compose.ci.yaml ps
- name: Run integration tests
timeout-minutes: 10
env:
MONGO_ROOT_USER: root
MONGO_ROOT_PASSWORD: rootpassword
MONGODB_HOST: 127.0.0.1
MONGODB_PORT: 27017
MONGODB_URL: mongodb://root:[email protected]:27017/?authSource=admin
KAFKA_BOOTSTRAP_SERVERS: localhost:9092
SCHEMA_REGISTRY_URL: http://localhost:8081
REDIS_HOST: localhost
REDIS_PORT: 6379
SCHEMA_SUBJECT_PREFIX: "ci.${{ github.run_id }}."
run: |
cd backend
uv run pytest tests/integration -v -rs \
--ignore=tests/integration/k8s \
--cov=app \
--cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: backend/coverage.xml
flags: backend-integration
name: backend-integration-coverage
fail_ci_if_error: false
verbose: true
- name: Collect logs
if: failure()
run: |
mkdir -p logs
docker compose -f docker-compose.ci.yaml logs > logs/docker-compose.log 2>&1
docker compose -f docker-compose.ci.yaml logs kafka > logs/kafka.log 2>&1
docker compose -f docker-compose.ci.yaml logs schema-registry > logs/schema-registry.log 2>&1
- name: Upload logs
if: failure()
uses: actions/upload-artifact@v6
with:
name: backend-logs
path: logs/
e2e:
name: E2E Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Cache and load Docker images
uses: ./.github/actions/docker-cache
with:
images: ${{ env.MONGO_IMAGE }} ${{ env.REDIS_IMAGE }} ${{ env.KAFKA_IMAGE }} ${{ env.SCHEMA_REGISTRY_IMAGE }}
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "backend/uv.lock"
- name: Install Python dependencies
run: |
cd backend
uv python install 3.12
uv sync --frozen
- name: Start infrastructure services
run: |
docker compose -f docker-compose.ci.yaml up -d --wait --wait-timeout 120
docker compose -f docker-compose.ci.yaml ps
- name: Setup Kubernetes (k3s)
run: |
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable=traefik" sh -
mkdir -p /home/runner/.kube
sudo k3s kubectl config view --raw > /home/runner/.kube/config
sudo chmod 600 /home/runner/.kube/config
export KUBECONFIG=/home/runner/.kube/config
timeout 90 bash -c 'until sudo k3s kubectl cluster-info; do sleep 5; done'
kubectl create namespace integr8scode --dry-run=client -o yaml | kubectl apply -f -
- name: Run E2E tests
timeout-minutes: 10
env:
MONGO_ROOT_USER: root
MONGO_ROOT_PASSWORD: rootpassword
MONGODB_URL: mongodb://root:[email protected]:27017/?authSource=admin
KAFKA_BOOTSTRAP_SERVERS: localhost:9092
SCHEMA_REGISTRY_URL: http://localhost:8081
REDIS_HOST: localhost
REDIS_PORT: 6379
SCHEMA_SUBJECT_PREFIX: "ci.${{ github.run_id }}."
KUBECONFIG: /home/runner/.kube/config
K8S_NAMESPACE: integr8scode
run: |
cd backend
uv run pytest tests/integration/k8s -v -rs \
--cov=app \
--cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: backend/coverage.xml
flags: backend-e2e
name: backend-e2e-coverage
fail_ci_if_error: false
verbose: true
- name: Collect logs
if: failure()
run: |
mkdir -p logs
docker compose -f docker-compose.ci.yaml logs > logs/docker-compose.log 2>&1
kubectl get events --sort-by='.metadata.creationTimestamp' -A > logs/k8s-events.log 2>&1 || true
kubectl describe pods -A > logs/k8s-describe-pods.log 2>&1 || true
- name: Upload logs
if: failure()
uses: actions/upload-artifact@v6
with:
name: k8s-logs
path: logs/