Skip to content

release: Feature Freeze for Audit #39

release: Feature Freeze for Audit

release: Feature Freeze for Audit #39

Workflow file for this run

name: Rust Unit Tests
on:
push:
branches: [main, "release/*"]
paths:
- "crates/**"
- "Cargo.*"
- "Makefile"
- ".github/workflows/rust-unit.yml"
pull_request:
branches: [main, "release/*"]
paths:
- "crates/**"
- "Cargo.*"
- "Makefile"
- ".github/workflows/rust-unit.yml"
env:
CARGO_TERM_COLOR: always
RUST_LOG: info
CI: true
jobs:
test:
name: Rust Unit Tests & Coverage
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy, llvm-tools-preview
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: make check
- name: Run clippy
run: make lint
- name: Build
run: make build
- name: Setup Solana CLI
uses: ./.github/actions/setup-solana
- name: Install cargo-llvm-cov for coverage
run: cargo install cargo-llvm-cov
- name: Run unit tests with coverage
run: |
echo "🧪 Running unit tests with coverage instrumentation..."
cargo llvm-cov clean --workspace
cargo llvm-cov test --no-report --workspace --lib
- name: Generate coverage reports
run: |
echo "📊 Generating coverage reports..."
mkdir -p coverage
cargo llvm-cov report --lcov --output-path coverage/lcov.info
- name: Display coverage summary
run: |
echo "📊 Coverage Summary:"
if [ -f "coverage/lcov.info" ]; then
echo "✅ Coverage report generated successfully"
echo "📄 Generated: coverage/lcov.info"
else
echo "❌ Coverage report not found"
fi
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: rust-unit-coverage-report
path: coverage/
retention-days: 30
- name: Update PR description with coverage badge
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v7
with:
script: |
// Extract coverage percentage from lcov.info
const fs = require('fs');
let coverage = '0';
try {
const lcov = fs.readFileSync('coverage/lcov.info', 'utf8');
const linesFound = lcov.match(/^LF:(\d+)$/gm)?.reduce((sum, line) => sum + parseInt(line.split(':')[1]), 0) || 0;
const linesHit = lcov.match(/^LH:(\d+)$/gm)?.reduce((sum, line) => sum + parseInt(line.split(':')[1]), 0) || 0;
coverage = linesFound > 0 ? ((linesHit / linesFound) * 100).toFixed(1) : '0';
} catch (error) {
console.log('Error reading coverage:', error);
}
// Determine badge color
let color = 'red';
if (parseFloat(coverage) >= 80) color = 'green';
else if (parseFloat(coverage) >= 60) color = 'yellow';
// Get current PR
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
// Create coverage badge section
const coverageBadge = `![Coverage](https://img.shields.io/badge/coverage-${coverage}%25-${color})`;
const coverageSection = `\n\n## 📊 Unit Test Coverage\n${coverageBadge}\n\n**Unit Test Coverage: ${coverage}%**\n\n[View Detailed Coverage Report](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
// Update PR body
let newBody = pr.body || '';
// Remove existing coverage section if present
newBody = newBody.replace(/\n## 📊 Unit Test Coverage[\s\S]*?(?=\n## |\n$|$)/g, '');
// Add new coverage section
newBody += coverageSection;
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: newBody
});