Repository navigation
91 lines (78 loc) Β· 2.79 KB
/
Copy pathsonarcloud.yml
File metadata and controls
91 lines (78 loc) Β· 2.79 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
name: Sonar Coverage
on:
push:
branches:
- develop
pull_request:
branches:
- develop
jobs:
sonar:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust Toolchain & Components
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, llvm-tools-preview
- name: Install grcov
run: cargo install grcov --force
- name: Run Tests with Coverage Instrumentation
env:
CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "%m.profraw"
run: cargo test --all --verbose
- name: Generate Coverage Report (lcov format)
run: |
grcov . \
--binary-path ./target/debug/deps/ \
-s . \
-t lcov \
--branch \
--ignore-not-existing \
--ignore "/*" \
-o lcov.info
- name: Convert lcov to SonarCloud Generic Coverage format
run: |
python3 << 'EOF'
import re
coverage = {}
current_file = None
with open('lcov.info', 'r') as f:
for line in f:
if line.startswith('SF:'):
current_file = line[3:].strip()
if current_file not in coverage:
coverage[current_file] = []
elif line.startswith('DA:') and current_file:
parts = line[3:].strip().split(',')
if len(parts) >= 2:
line_num = parts[0]
hits = parts[1]
coverage[current_file].append((line_num, hits))
with open('coverage.xml', 'w') as f:
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write('<coverage version="1">\n')
for filepath, lines in coverage.items():
if lines:
f.write(f' <file path="{filepath}">\n')
for line_num, hits in lines:
f.write(f' <lineToCover lineNumber="{line_num}" covered="{"true" if int(hits) > 0 else "false"}"/>\n')
f.write(' </file>\n')
f.write('</coverage>\n')
EOF
- name: Delete profraw files
run: find . -name "*.profraw" -type f -delete
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v2
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: >
-Dsonar.projectKey=MORUTINE_backend
-Dsonar.organization=morutine
-Dsonar.coverageReportPaths=coverage.xml