Skip to content

Add cargo test step to CI pipeline #20

@cbaugus

Description

@cbaugus

Summary

The current CI pipeline (build-cicd.yaml) builds Docker images and generates SBOMs but does not run any tests. PRs can be merged with failing tests, and there's no gate to prevent broken code from being deployed.

Current CI Pipeline

# Current workflow only does:
1. Checkout code
2. Setup Docker Buildx
3. Build Docker images (Ubuntu + Chainguard)
4. Generate SBOMs
5. Push to Docker Hub

Proposed Changes

Add a test job that runs before the build job:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install Rust toolchain
        uses: dtolnay/rust-action@stable
        
      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
            
      - name: Run tests
        run: cargo test --verbose
        
      - name: Run tests (release mode)
        run: cargo test --release --verbose

  build:
    needs: test  # Only build if tests pass
    runs-on: ubuntu-latest
    # ... existing build steps

Acceptance Criteria

  • cargo test runs on every push and PR
  • Build job depends on test job (won't run if tests fail)
  • Cargo registry/target cached for faster builds
  • Test output visible in GitHub Actions logs
  • Failed tests block PR merge (with branch protection)
  • Both debug and release test configurations run

Additional Recommendations

Branch Protection Rules

After implementing this, enable branch protection on main:

  • Require status checks to pass before merging
  • Require "test" job to pass
  • Require PR reviews (optional)

Test Matrix (Optional Enhancement)

strategy:
  matrix:
    rust: [stable, beta]
    os: [ubuntu-latest, macos-latest]

Minimum Rust Version Check

- name: Check MSRV
  run: |
    rustup install 1.77
    cargo +1.77 check

Implementation

Update .github/workflows/build-cicd.yaml:

name: CI/CD

on:
  push:
    branches: ["*"]
  pull_request:
    branches: [main]

jobs:
  test:
    name: Run Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install Rust toolchain
        uses: dtolnay/rust-action@stable
        with:
          components: rustfmt, clippy
          
      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2
        
      - name: Run tests
        run: cargo test --all-features --verbose
        
  build:
    name: Build and Push
    needs: test
    runs-on: ubuntu-latest
    if: github.event_name == 'push'
    # ... existing build configuration

Priority

Critical - Without CI tests, there's no automated quality gate. Broken code can be merged and deployed.

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions