Skip to content

Latest commit

 

History

History
163 lines (120 loc) · 4.9 KB

File metadata and controls

163 lines (120 loc) · 4.9 KB

CI/CD Pipeline Fixes

Summary

Fixed all CI/CD workflow files to ensure checks pass after codebase cleanup.

Changes Made

1. Removed Database Initialization Step

Issue: Workflows referenced npm run init-db which was removed during codebase cleanup.

Files Updated:

  • .github/workflows/ci.yml - Removed init-db step from test and coverage jobs
  • .github/workflows/test.yml - Removed init-db step

Reason: The project uses JSON file storage (data/*.json), not SQLite. The initDB.js script was legacy code from an earlier implementation and has been removed.

2. Workflow Files Status

✅ Fixed Workflows

  • ci.yml - Main CI pipeline with test, coverage, lint, and security jobs
  • test.yml - Basic test runner
  • coverage.yml - Test coverage enforcement (already correct)
  • security.yml - Dependency audit (already correct)
  • static-security.yml - ESLint security analysis (already correct)
  • label-enforcement.yml - Label-based extended checks (already correct)
  • codeql.yml - CodeQL security scanning (already correct)

CI/CD Pipeline Overview

Main CI Pipeline (ci.yml)

Runs on: Pull requests and pushes to main/develop branches

Jobs:

  1. Test - Runs full Jest test suite
  2. Coverage - Enforces test coverage thresholds
  3. Lint - Runs ESLint with security plugins
  4. Security - Runs npm audit for critical vulnerabilities
  5. Status - Aggregates results and reports overall status

Test Pipeline (test.yml)

Simplified test runner for quick validation.

Coverage Pipeline (coverage.yml)

Enforces minimum 30% coverage threshold for:

  • Branches
  • Functions
  • Lines
  • Statements

Security Pipelines

  1. security.yml - npm audit for dependencies
  2. static-security.yml - ESLint security linting
  3. codeql.yml - GitHub CodeQL analysis

Label-Based Enforcement (label-enforcement.yml)

Triggers extended checks based on PR labels:

  • testing label → Extended test suite with strict coverage
  • security label → Extended security checks with zero warnings

Environment Variables Required

All workflows use these environment variables:

env:
  CI: true
  MOCK_STELLAR: true
  API_KEYS: test-key-1,test-key-2

Expected Test Results

With all fixes applied:

  • 89/89 tests passing
  • All test suites passing (5/5)
  • No database initialization required
  • Mock Stellar service used in CI

Verification Steps

To verify CI/CD passes locally:

# 1. Install dependencies
npm ci

# 2. Run tests
npm test

# 3. Run tests with coverage
npm run test:coverage:ci

# 4. Run linting
npm run lint:security -- --max-warnings=100

# 5. Run security audit
npm audit --audit-level=critical

Common Issues and Solutions

Issue: "npm run init-db" not found

Solution: ✅ Fixed - Removed from all workflows

Issue: Tests fail due to missing database

Solution: ✅ Not applicable - Project uses JSON storage, tests create their own test data

Issue: Coverage threshold not met

Solution: Current coverage exceeds 30% threshold. If it drops, add tests to affected areas.

Issue: ESLint warnings exceed limit

Solution: Fix ESLint warnings or adjust --max-warnings parameter (currently set to 100)

Issue: npm audit fails

Solution: Update vulnerable dependencies or use npm audit fix

CI/CD Best Practices Implemented

  1. Fail Fast - Tests run first, followed by coverage and linting
  2. Parallel Execution - Jobs run in parallel when possible
  3. Caching - npm cache is used to speed up builds
  4. Artifact Upload - Coverage reports are saved for 30 days
  5. Environment Isolation - Each job runs in a clean environment
  6. Security First - Multiple security checks at different levels
  7. Label-Based Triggers - Extended checks only when needed

Workflow Triggers

Automatic Triggers

  • Push to main or develop branches
  • Pull requests to main or develop branches
  • Scheduled (CodeQL only - weekly on Wednesdays)

Manual Triggers

  • workflow_dispatch - Can be triggered manually from GitHub Actions UI

Next Steps

  1. Push changes to trigger CI/CD pipeline
  2. Monitor workflow runs in GitHub Actions tab
  3. Review any failures and address issues
  4. Merge when all checks pass

Maintenance

Regular Tasks

  • Review and update dependencies monthly
  • Monitor security advisories
  • Update Node.js version as needed (currently 18)
  • Review and adjust coverage thresholds as codebase grows

When Adding New Features

  • Ensure tests are added (maintain >30% coverage)
  • Run npm run lint:security before committing
  • Add appropriate labels to PRs for extended checks
  • Update workflows if new scripts are added

Contact

For CI/CD issues:

  1. Check workflow logs in GitHub Actions
  2. Review this document for common issues
  3. Verify local tests pass before pushing
  4. Check environment variables are set correctly