Skip to content

docs(memory): Memory bank optimization - 52.5% reduction achieved #16

docs(memory): Memory bank optimization - 52.5% reduction achieved

docs(memory): Memory bank optimization - 52.5% reduction achieved #16

Workflow file for this run

name: Coverage
on:
# Only run coverage on release tags to reduce CI/CD load
push:
tags:
- 'v*.*.*'
# Manual trigger for testing
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g., v0.4.6)'
required: false
type: string
# Cancel outdated workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libpcap-dev pkg-config
# Use Swatinem/rust-cache for optimal Rust caching (same as CI workflow)
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: "coverage"
cache-targets: "true"
cache-on-failure: "true"
- name: Install cargo-tarpaulin
run: |
# Check if already installed to save time
if ! command -v cargo-tarpaulin &> /dev/null; then
cargo install cargo-tarpaulin
else
echo "cargo-tarpaulin already installed"
fi
- name: Generate coverage report
id: tarpaulin
run: |
# Run tarpaulin and capture output
OUTPUT=$(cargo tarpaulin --workspace \
--timeout 600 \
--out Lcov --out Html --out Json \
--output-dir coverage \
--exclude-files "crates/prtip-cli/src/main.rs" 2>&1)
# Display the output
echo "$OUTPUT"
# Extract coverage percentage from output (format: "XX.XX% coverage, N/M lines covered")
COVERAGE=$(echo "$OUTPUT" | grep -oP '\d+\.\d+(?=% coverage)' | tail -1)
if [ -z "$COVERAGE" ]; then
echo "Error: Could not extract coverage percentage from tarpaulin output"
exit 1
fi
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "Extracted coverage: $COVERAGE%"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: coverage/lcov.info
flags: rust
name: codecov-prtip
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
retention-days: 30
- name: Extract coverage percentage
id: coverage
run: |
# Get coverage from tarpaulin step output
COVERAGE=${{ steps.tarpaulin.outputs.coverage }}
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
echo "Current coverage: $COVERAGE%"
- name: Check coverage threshold
run: |
COVERAGE=${{ steps.coverage.outputs.percentage }}
THRESHOLD=50.0
echo "Current coverage: $COVERAGE%"
echo "Required threshold: $THRESHOLD%"
# Use awk for floating point comparison (bc not always available)
if awk -v cov="$COVERAGE" -v thr="$THRESHOLD" 'BEGIN {exit !(cov < thr)}'; then
echo "❌ Coverage $COVERAGE% is below threshold $THRESHOLD%"
echo "::error::Coverage regression detected. Current: $COVERAGE%, Required: $THRESHOLD%"
exit 1
fi
echo "✅ Coverage $COVERAGE% meets threshold $THRESHOLD%"
echo "::notice::Coverage check passed: $COVERAGE% >= $THRESHOLD%"
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const coverage = '${{ steps.coverage.outputs.percentage }}';
const threshold = '50.0';
const passed = parseFloat(coverage) >= parseFloat(threshold);
const emoji = passed ? '✅' : '❌';
const comment = `## ${emoji} Coverage Report
**Current Coverage:** ${coverage}%
**Threshold:** ${threshold}%
**Status:** ${passed ? 'PASSED' : 'FAILED'}
${passed ?
'✅ Coverage meets the minimum threshold.' :
'❌ Coverage is below the minimum threshold. Please add more tests.'}
📊 [View detailed coverage report in artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});