-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (163 loc) · 6.58 KB
/
code-coverage.yml
File metadata and controls
199 lines (163 loc) · 6.58 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Code Coverage
on:
push:
branches: [main, dev]
paths:
- "**.rs"
- "**/Cargo.toml"
- "**/Cargo.lock"
- ".github/workflows/code-coverage.yml"
pull_request:
branches: [main, dev]
paths:
- "**.rs"
- "**/Cargo.toml"
- "**/Cargo.lock"
- ".github/workflows/code-coverage.yml"
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
coverage:
name: Code Coverage
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@1.88
with:
components: llvm-tools-preview
- name: Log environment info
run: |
echo "Rust toolchain information:"
rustup show
echo "Rust version: $(rustc --version)"
echo "Cargo version: $(cargo --version)"
echo "LLVM tools: $(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/bin/"
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Free up disk space
run: |
# Remove unnecessary tools and files to free up ~10GB
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
df -h
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-coverage-only-1.88-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }}
restore-keys: |
${{ runner.os }}-cargo-coverage-only-1.88-
- name: Clean previous coverage artifacts
run: |
# Remove previous coverage data but keep compiled dependencies
cargo llvm-cov clean --workspace
# Show disk space before coverage generation
df -h
- name: Generate code coverage
run: |
# Run tests with coverage for all packages (excluding same files as Codecov)
# Use debug mode for coverage (release mode can interfere with coverage instrumentation)
cargo llvm-cov test --all-features --workspace --lcov --output-path lcov.info \
--ignore-filename-regex="examples/.*|.*/build\.rs"
# Also run integration tests
cargo llvm-cov test --all-features --package pulseengine-mcp-integration-tests --lcov --output-path lcov-integration.info
# Merge coverage files
cargo llvm-cov report --lcov --output-path lcov-merged.info
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
files: lcov-merged.info
flags: unittests
name: pulseengine-mcp
fail_ci_if_error: true
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Generate coverage summary
run: |
# Generate a human-readable summary (with same exclusions as Codecov)
cargo llvm-cov report --summary-only \
--ignore-filename-regex="examples/.*|.*/build\.rs" \
> coverage-summary.txt
cat coverage-summary.txt
# Extract coverage percentage for PR comment (use tail -1 to get TOTAL line, not first file)
COVERAGE=$(grep -oP '\d+\.\d+(?=%)' coverage-summary.txt | tail -1)
echo "COVERAGE_PERCENT=$COVERAGE" >> $GITHUB_ENV
# Note: Coverage validation is now handled by Codecov, not locally
echo "ℹ️ Coverage validation delegated to Codecov - see https://codecov.io/gh/${{ github.repository }}"
- name: Cleanup cache before saving
run: |
echo "📊 Disk usage before cleanup:"
du -sh target || true
# Remove coverage-specific artifacts that shouldn't be cached
rm -rf target/llvm-cov-target
rm -rf target/debug/.fingerprint/*-llvm-cov*
rm -rf target/*/debug/coverage*
# Remove test binaries (large and rebuilt every time)
find target -type f -name '*-????????????????' -executable -delete 2>/dev/null || true
# Remove incremental compilation data (doesn't help across runs)
rm -rf target/debug/incremental
rm -rf target/release/incremental
# Keep: compiled dependencies in target/debug/deps/*.rlib
# Keep: build script outputs in target/debug/build/*/out
echo "📊 Disk usage after cleanup:"
du -sh target || true
- name: Post coverage comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const coverage = process.env.COVERAGE_PERCENT;
const comment = `## Code Coverage Report 📊
**Local Coverage**: ${coverage}%
**Validation**: Handled by [Codecov](https://codecov.io/gh/${{ github.repository }})
> **Note**: Coverage validation is now performed by Codecov to ensure consistency across all platforms.
<details>
<summary>Coverage Details</summary>
\`\`\`
${require('fs').readFileSync('coverage-summary.txt', 'utf8')}
\`\`\`
</details>
**📋 Full Report**: [View on Codecov](https://codecov.io/gh/${{ github.repository }})`;
// Find existing coverage comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('Code Coverage Report')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: comment
});
}
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
lcov-merged.info
coverage-summary.txt