Skip to content

Commit 6958ad6

Browse files
authored
Merge pull request #12 from PFalkowski/ci/sonar-badge
SonarCloud: CI-based analysis with coverage + badges
2 parents 4ef550a + 74506be commit 6958ad6

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

.github/workflows/sonar.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SonarCloud analysis with test coverage (CI-based scanner).
2+
# Requires a GitHub org-level secret SONAR_TOKEN, and Automatic Analysis turned OFF for
3+
# project PFalkowski_LoggerLite (SonarCloud > Administration > Analysis Method).
4+
name: SonarCloud
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
sonar:
14+
name: Build, test & analyze
15+
runs-on: ubuntu-latest
16+
# Skip PRs from forks — they can't access the SONAR_TOKEN secret.
17+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up JDK (required by the scanner)
25+
uses: actions/setup-java@v4
26+
with:
27+
distribution: temurin
28+
java-version: 17
29+
30+
- name: Setup .NET
31+
uses: actions/setup-dotnet@v5
32+
with:
33+
dotnet-version: 8.0.x
34+
35+
- name: Cache SonarCloud packages
36+
uses: actions/cache@v4
37+
with:
38+
path: ~/.sonar/cache
39+
key: ${{ runner.os }}-sonar
40+
restore-keys: ${{ runner.os }}-sonar
41+
42+
- name: Install scanner + coverage tools
43+
run: |
44+
dotnet tool install --global dotnet-sonarscanner
45+
dotnet tool install --global dotnet-coverage
46+
47+
- name: Build, test (with coverage) & analyze
48+
env:
49+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
50+
run: |
51+
dotnet-sonarscanner begin \
52+
/k:"PFalkowski_LoggerLite" /o:"pfalkowski" \
53+
/d:sonar.host.url="https://sonarcloud.io" \
54+
/d:sonar.token="$SONAR_TOKEN" \
55+
/d:sonar.exclusions="**/*TestHarness/**" \
56+
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
57+
dotnet build --configuration Release
58+
dotnet-coverage collect "dotnet test --configuration Release --no-build" -f xml -o coverage.xml
59+
dotnet-sonarscanner end /d:sonar.token="$SONAR_TOKEN"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# LoggerLite
22

33
[![CI](https://github.com/PFalkowski/LoggerLite/actions/workflows/ci.yml/badge.svg)](https://github.com/PFalkowski/LoggerLite/actions/workflows/ci.yml)
4+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=PFalkowski_LoggerLite&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=PFalkowski_LoggerLite)
5+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=PFalkowski_LoggerLite&metric=coverage)](https://sonarcloud.io/summary/new_code?id=PFalkowski_LoggerLite)
46
[![NuGet](https://img.shields.io/nuget/v/LoggerLite.svg)](https://www.nuget.org/packages/LoggerLite)
57
[![Downloads](https://img.shields.io/nuget/dt/LoggerLite.svg)](https://www.nuget.org/packages/LoggerLite)
68
[![License: MIT](https://img.shields.io/github/license/PFalkowski/LoggerLite.svg)](License.txt)
9+
[![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-FFDD00?logo=buymeacoffee&logoColor=black)](https://buymeacoffee.com/piotrfalkowski)
710

811
Lightweight, dependency-free logging for .NET — a thin, easy-to-read wrapper around `Console`,
912
file streaming, `XDocument` and friends, behind a single `ILoggerLite` interface. Targets

0 commit comments

Comments
 (0)