-
Notifications
You must be signed in to change notification settings - Fork 245
132 lines (114 loc) · 4.38 KB
/
rust-unit.yml
File metadata and controls
132 lines (114 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Rust Unit Tests
on:
push:
branches: [main]
paths:
- "crates/**"
- "Cargo.*"
- "justfile"
- ".github/workflows/rust-unit.yml"
pull_request:
branches: [main]
paths:
- "crates/**"
- "Cargo.*"
- "justfile"
- ".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: Install just
uses: extractions/setup-just@v3
- name: Run fmt and clippy
run: |
cargo fmt --all -- --check
cargo clippy -- -D warnings
- name: Build
run: just 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
env:
JUPITER_API_KEY: ${{ secrets.JUPITER_API_KEY }}
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 = ``;
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
});