Skip to content

ci: add comprehensive GitHub Actions CI/CD pipeline#2

Merged
zakariaf merged 14 commits into
mainfrom
claude/add-ci-cd-pipeline-011CV1ikZvJppaVyWuzfpN1b
Nov 11, 2025
Merged

ci: add comprehensive GitHub Actions CI/CD pipeline#2
zakariaf merged 14 commits into
mainfrom
claude/add-ci-cd-pipeline-011CV1ikZvJppaVyWuzfpN1b

Conversation

@zakariaf
Copy link
Copy Markdown
Owner

Summary

This PR adds a professional CI/CD pipeline following 2025 best practices for Python/FastAPI projects.

What's Included

CI/CD Pipeline Features

  • Code Quality: Black, isort, Flake8, MyPy
  • Unit Tests: Pytest with 70% coverage minimum
  • Integration Tests: Redis & Qdrant service containers
  • Docker Build: Multi-stage validation
  • Security Scanning: Safety & Bandit
  • Dependabot: Automated weekly updates
  • PR Title Validation: Conventional Commits enforcement

Workflow Jobs

  1. Code Quality Checks → Formatting, linting, type checking
  2. Unit Tests → All unit tests with coverage
  3. Integration Tests → With service containers
  4. Docker Build → Dev & prod targets
  5. Security Scan → Vulnerability detection
  6. Deployment Summary → Aggregated status

Required Secrets

For integration tests to fully work, add these repository secrets:

  • OPENAI_API_KEY - Your OpenAI API key
  • ANTHROPIC_API_KEY - Your Anthropic API key (optional)
  • CODECOV_TOKEN - Codecov token (optional)

Testing

Once this PR is created, the CI/CD pipeline will automatically run and validate:

  • ✅ Code formatting and linting
  • ✅ Type checking
  • ✅ All unit tests pass
  • ✅ Integration tests pass (with Redis/Qdrant)
  • ✅ Docker builds successfully
  • ✅ No security vulnerabilities

All checks must pass before merging!

Next Steps

After this is merged, all future PRs will automatically:

  1. Run code quality checks
  2. Execute test suite
  3. Validate Docker builds
  4. Scan for security issues
  5. Show clear pass/fail status

Implements: Issue #12 (GitHub Actions CI/CD)

Implemented professional CI/CD workflow following 2025 best practices.

## Workflows Added

### 1. Main CI/CD Pipeline (ci.yml)
**Code Quality Checks:**
- Black: Code formatting validation (88 char line length)
- isort: Import statement organization
- Flake8: Linting with E203, W503 ignored
- MyPy: Static type checking

**Unit Tests:**
- Pytest execution for tests/unit/
- Coverage reporting with 70% minimum threshold
- XML coverage reports for Codecov integration
- Parallel test execution

**Integration Tests:**
- Redis 7.2-alpine service container
- Qdrant v1.6.1 service container
- Health check validation for services
- Wait-for-ready logic with retry
- Environment variable configuration

**Docker Build:**
- Multi-stage build validation
- Development target build
- Production target build
- Docker layer caching via GitHub Actions cache

**Security Scanning:**
- Safety: Dependency vulnerability checking
- Bandit: Python code security analysis
- Report artifacts upload

**Deployment Summary:**
- Aggregated status of all jobs
- Deployment readiness validation
- Clear pass/fail indicators

### 2. PR Title Check (pr-title-check.yml)
- Enforces Conventional Commits format
- Validates commit types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
- Optional scope validation
- Subject case validation

### 3. Dependabot Configuration (dependabot.yml)
- Weekly pip dependency updates
- Weekly GitHub Actions updates
- Weekly Docker image updates
- Auto-assignment to reviewers
- Automatic labeling

## Key Features

**Performance:**
- Pip dependency caching with actions/setup-python@v5
- Docker BuildKit layer caching
- Parallel job execution where possible

**Service Containers:**
- Redis with health checks and retry logic
- Qdrant with health checks and retry logic
- Proper networking and port mapping

**Quality Gates:**
- All code quality checks must pass
- 70% minimum test coverage enforced
- All unit tests must pass
- Integration tests must pass
- Docker builds must succeed

**Security:**
- Automated vulnerability scanning
- Security report artifacts
- Continue-on-error for non-blocking scans

## Branch Triggers
- Push: main, develop, claude/*
- Pull Request: main, develop

## Required Secrets
- CODECOV_TOKEN (optional, for coverage reporting)
- OPENAI_API_KEY (for integration tests)
- ANTHROPIC_API_KEY (for integration tests)

This CI/CD pipeline ensures code quality, test coverage, and security
before any code is merged to protected branches.

Implements: Issue #12 (GitHub Actions CI/CD)
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @zakariaf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes a robust and modern CI/CD workflow using GitHub Actions, designed to enhance the development process for Python/FastAPI projects. It automates critical aspects such as code quality enforcement, comprehensive testing (unit and integration), secure Docker image building, and proactive dependency management, ensuring that all future contributions meet high standards before integration.

Highlights

  • Comprehensive CI/CD Pipeline: Implements a professional GitHub Actions CI/CD pipeline for Python/FastAPI projects, following 2025 best practices.
  • Automated Quality Checks: Integrates code quality tools like Black, isort, Flake8, and MyPy for formatting, linting, and type checking.
  • Robust Testing: Includes unit tests with a 70% coverage minimum using Pytest, and integration tests leveraging Redis and Qdrant service containers.
  • Security & Build Validation: Incorporates multi-stage Docker build validation and security scanning with Safety and Bandit.
  • Dependency Management: Sets up Dependabot for automated weekly updates across "pip", "github-actions", and "docker" ecosystems.
  • PR Title Enforcement: Adds validation for PR titles to enforce Conventional Commits.
Ignored Files
  • Ignored by pattern: .github/workflows/** (2)
    • .github/workflows/ci.yml
    • .github/workflows/pr-title-check.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a dependabot.yml configuration to automate dependency updates for pip, github-actions, and docker. The configuration is well-structured. I've provided a couple of suggestions to improve maintainability by using teams for reviewers and grouping pip dependencies to reduce pull request noise. Please note that while the PR description outlines a comprehensive CI/CD pipeline, this review only covers the dependabot.yml file, as it's the only change included in the pull request.

Comment thread .github/dependabot.yml
Comment on lines +4 to +13
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
reviewers:
- "zakariaf"
labels:
- "dependencies"
- "python"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To reduce pull request noise from Dependabot, consider grouping related pip dependencies. This creates a single PR for a set of updates, which can be easier to manage and test. For example, you can group all pytest-related packages together.

  - package-ecosystem: "pip"
    directory: "/"
    schedule:
      interval: "weekly"
    open-pull-requests-limit: 10
    reviewers:
      - "zakariaf"
    labels:
      - "dependencies"
      - "python"
    groups:
      pytest:
        patterns:
          - "pytest*"

Comment thread .github/dependabot.yml
Comment on lines +9 to +10
reviewers:
- "zakariaf"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better maintainability, consider assigning a team to reviewers instead of an individual user (e.g., your-org/your-team-name). This prevents PRs from being blocked if the assigned individual is unavailable. This suggestion also applies to the other reviewers sections in this file (lines 21-22 and 33-34).

    reviewers:
      - "your-org/your-team-name"

Fix CI/CD pipeline failures by adding proper tool configurations.

Changes:
- Add typing-extensions to requirements.txt for Python 3.11 compatibility
- Add type stubs (types-redis, types-requests) for mypy
- Create setup.cfg with flake8, mypy, isort, pytest configurations
- Create pyproject.toml with black, isort, pytest, coverage settings
- Configure mypy to ignore missing imports for third-party packages
- Set proper exclude patterns for all linters

This ensures:
- Dependencies install without conflicts
- Linters run with consistent configurations
- Type checking doesn't fail on third-party packages
- Test discovery works correctly

Fixes failing Code Quality Checks job in PR #2
Fix all Black, isort, Flake8, and MyPy errors to pass CI checks.

Changes:
- Break long lines in app/config.py to comply with 88 char limit
- Split long function signature in app/models/llm.py
- Remove unused imports (pytest, TestClient) from test files
- Add type: ignore comment for redis_pool.disconnect()
- Add return type hint to ApplicationState.__init__()
- Auto-format all code with Black
- Auto-sort all imports with isort

All linters now pass:
✅ Black: All files formatted correctly
✅ isort: All imports sorted correctly
✅ Flake8: No linting errors
✅ MyPy: Type checking passed

Verified locally with:
- python -m black --check app/ tests/
- python -m isort --check-only app/ tests/
- python -m flake8 app/ tests/ --max-line-length=88 --extend-ignore=E203,W503
- python -m mypy app/ --ignore-missing-imports

Fixes Code Quality Checks in PR #2
Update packages to resolve urllib3 version conflict between
qdrant-client and types-requests.

Changes:
- Upgrade qdrant-client: 1.6.4 → 1.15.1
  - Now supports urllib3>=1.26.14,<3 (includes urllib3 2.x)
  - Latest stable release (July 2025)

- Update types-redis: 4.6.0.11 → 4.6.0.20
  - Latest type stubs for redis

- Update types-requests: 2.31.0.10 → 2.32.0.20240914
  - Latest type stubs for requests
  - Compatible with urllib3>=2

Resolves dependency conflict:
  - OLD: qdrant-client 1.6.4 requires urllib3<2.0.0
  - OLD: types-requests 2.31.0.10 requires urllib3>=2
  - NEW: All packages now compatible with urllib3 2.x

This ensures pip can resolve all dependencies without conflicts.

Fixes dependency resolution error in PR #2
Fix types-redis version to use correct date format.

Change:
- types-redis==4.6.0.20 → types-redis==4.6.0.20241004

The types-redis package uses date-based versioning (YYYYMMDD format).
Version 4.6.0.20 does not exist. The latest available version is
4.6.0.20241004 (released October 4, 2024).

Available versions from PyPI:
4.6.0.20240106, 4.6.0.20240218, ..., 4.6.0.20241004

This ensures pip can find and install the correct package version.

Fixes package installation error in PR #2
MyPy requires explicit values for optional fields in Pydantic model
instantiation. Added explicit None values to:
- CacheInfo.miss() factory method
- CacheInfo.exact_hit() factory method
- CacheEntry instantiation in QueryService

This resolves MyPy errors about missing named arguments.
Add unit tests for previously untested modules:
- Cache layer (RedisCache): 8 tests covering get, set, delete, exists, health check
- Repository layer (RedisRepository): 11 tests covering fetch, store, delete, exists, ping with error handling
- LLM provider (OpenAIProvider): 5 tests covering completion, error handling, custom parameters
- Query service (QueryService): 8 tests covering cache hits/misses, error handling, metrics
- API routes (health, query): 9 tests covering endpoints, validation, error handling

These tests use mocking to isolate units and test behavior without external dependencies.
Expected to increase coverage from ~40% to >70% to meet CI requirements.
API route tests:
- Use FastAPI dependency_overrides instead of patching
- Properly inject mock query service via dependency injection

Query service tests:
- Fix mock LLM provider to use Mock() instead of AsyncMock()
- get_name() is synchronous, only complete() is async
- Prevents 'coroutine object' validation errors in Pydantic models
Mark completed tasks:
- Repository initialized
- Docker environment running
- FastAPI health check working
- Unit tests passing
- MVP fully functional
- Redis caching implemented
- LLM integration complete (OpenAI)
- /api/v1/query endpoint working
- Test coverage > 70% (achieved 80.36%)
- GitHub Actions CI/CD pipeline
- Code quality checks (Black, isort, flake8, mypy)

Add future improvements section:
- Docker image optimization
- Anthropic LLM provider
- Qdrant semantic caching
- Prometheus metrics
- Performance optimization
from_cache is a Python @Property, not a Pydantic field, so it's not
included in JSON serialization. Test now checks the actual JSON field
cache_info.cache_hit instead.
Marked completed tasks across all epics:
- Epic 1: 16/25 tasks completed (project setup, config, FastAPI, CI/CD)
- Epic 2: 7/15 tasks completed (models and validation)
- Epic 3: 14/20 tasks completed (Redis cache layer)
- Epic 4: 0/25 tasks completed (Qdrant - not started)
- Epic 5: 6/30 tasks completed (OpenAI provider implemented)
- Epic 6: 8/25 tasks completed (query service orchestration)
- Epic 7: 5/15 tasks completed (API endpoints)
- Epic 8: 7/30 tasks completed (unit tests with 82.54% coverage)
- Epics 9-12: Not started (monitoring, docs, optimization, production)

Total progress: 63/230 tasks completed (~27%)
@zakariaf zakariaf merged commit e60e210 into main Nov 11, 2025
11 of 13 checks passed
zakariaf pushed a commit that referenced this pull request Nov 13, 2025
…rformance improvements

Fix all issues identified in PR review by gemini-code-assist bot.

HIGH PRIORITY FIXES:

1. EmbeddingVector validation (Issue #1)
   - Replace no-op field_validator with @model_validator
   - Move dimension matching validation from factory to model validator
   - Move NaN/Inf detection from factory to model validator
   - Now validates on direct instantiation, not just via create()

2. RateLimitInfo validation (Issue #2)
   - Replace no-op field_validator with @model_validator
   - Enforce requests_remaining <= limit constraint
   - Validation now happens on all instantiation paths

3. CacheStatistics validation (Issue #3)
   - Replace field_validator with @model_validator
   - Validate total_queries = cache_hits + cache_misses
   - Validate cache_hits = exact_hits + semantic_hits
   - Proper cross-field validation with model_validator

MEDIUM PRIORITY FIXES:

4. AuditLogSummary performance (Issue #4)
   - Consolidate 6 separate list iterations into single loop
   - Major performance improvement for large audit log datasets
   - Reduced from O(6n) to O(n) complexity

5. ProviderRegistry mutability (Issue #5)
   - Remove unconventional object.__setattr__() usage
   - Use direct mutation (Pydantic models are mutable)
   - Cleaner, more idiomatic code in register() and set_default()

6. Test consistency (Issue #6)
   - Replace try/except blocks with pytest.raises context manager
   - Updated 5 test methods in test_cache_entry.py
   - Consistent with other test files in the project

BENEFITS:
- Validates on all instantiation paths, not just factory methods
- Better performance with consolidated iterations
- More maintainable code without object.__setattr__
- Consistent testing patterns across all test files
- Proper Pydantic validation best practices

Files modified:
- app/models/embedding.py: model_validator for dimensions + NaN/Inf
- app/models/ratelimit.py: model_validator for requests_remaining
- app/models/statistics.py: model_validator for cross-field validation
- app/models/audit.py: single-loop optimization
- app/models/provider.py: removed object.__setattr__
- tests/unit/models/test_cache_entry.py: pytest.raises pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants