Skip to content

Commit 0ea3724

Browse files
HandyS11claude
andauthored
CI: add SonarQube analysis workflow + Codecov badge (#24)
Add Sonar.yml running dotnet-sonarscanner on develop pushes (and workflow_dispatch). Community-Edition Sonar has no branch/PR support, so analysis is scoped to the long-lived develop branch; PR build/test feedback stays in CI.yml. Build/test run in Release with an explicit restore to mirror CI.yml, coverage is collected via coverlet (opencover) and uploaded to Codecov. Add the Codecov badge to the README. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0bd467a commit 0ea3724

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/Sonar.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: SonarQube Analysis
2+
3+
permissions:
4+
contents: read
5+
6+
# Analyze only the long-lived branch. Community-Edition Sonar has no branch/PR
7+
# support — every analysis writes to the single main branch. PR build/test feedback
8+
# is covered by CI.yml.
9+
on:
10+
push:
11+
branches:
12+
- develop
13+
workflow_dispatch:
14+
15+
jobs:
16+
build:
17+
name: Build and analyze
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 15
20+
21+
steps:
22+
- uses: actions/checkout@v6
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up JDK 17
27+
uses: actions/setup-java@v5
28+
with:
29+
java-version: 17
30+
distribution: 'zulu'
31+
32+
- name: Setup .NET
33+
uses: actions/setup-dotnet@v5
34+
with:
35+
dotnet-version: 10.0.x
36+
37+
- name: Cache SonarQube packages
38+
uses: actions/cache@v5
39+
with:
40+
path: ~/.sonar/cache
41+
key: ${{ runner.os }}-sonar
42+
restore-keys: ${{ runner.os }}-sonar
43+
44+
- name: Cache SonarQube scanner
45+
id: cache-sonar-scanner
46+
uses: actions/cache@v5
47+
with:
48+
path: ./.sonar/scanner
49+
key: ${{ runner.os }}-sonar-scanner
50+
restore-keys: ${{ runner.os }}-sonar-scanner
51+
52+
- name: Install SonarQube scanner
53+
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
54+
run: |
55+
mkdir -p ./.sonar/scanner
56+
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
57+
58+
- name: Restore dependencies
59+
run: dotnet restore
60+
61+
- name: Build and analyze
62+
run: |
63+
./.sonar/scanner/dotnet-sonarscanner begin /k:"${{ secrets.SONAR_PROJECT_KEY }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" /d:sonar.coverage.exclusions="**/tests/**" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml"
64+
dotnet build --no-restore --configuration Release
65+
dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage;Format=opencover" --blame-hang-timeout 60s
66+
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
67+
68+
- name: Upload coverage reports to Codecov
69+
uses: codecov/codecov-action@v7
70+
with:
71+
token: ${{ secrets.CODECOV_TOKEN }}
72+
73+
- name: Upload test results to Codecov
74+
if: ${{ !cancelled() }}
75+
uses: codecov/codecov-action@v7
76+
with:
77+
token: ${{ secrets.CODECOV_TOKEN }}
78+
report_type: test_results

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RustPlusBot
22

3+
[![codecov](https://codecov.io/gh/HandyS11/RustPlusBot/graph/badge.svg?token=jH6L7dDRrq)](https://codecov.io/gh/HandyS11/RustPlusBot)
4+
35
A self-hosted Discord bot for the Rust+ companion app.
46

57
## Status

0 commit comments

Comments
 (0)