Skip to content

Commit

Permalink
Add code coverage to static analysis
Browse files Browse the repository at this point in the history
Closes #496
  • Loading branch information
baynezy committed Dec 19, 2024
1 parent 961c582 commit ee1240d
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Static Analysis
on:
push:
branches:
- develop
paths:
- 'src/**'
- 'test/**'
- '**.sln'
- '.github/workflows/static-analysis.yml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'src/**'
- 'test/**'
- '**.sln'
- '.github/workflows/static-analysis.yml'

env:
PROJECT_NAME: 'baynezy_Html2Markdown'
ORGANISATION: 'baynezy'
TEST_FILTER: "Category!=LocalTest"

jobs:
build:
name: Build and analyse
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- uses: actions/checkout@v4
with:
fetch-depth: 0 # This disables shallow clones. This allows SonarQube to access the history of the project to perform analysis.
- name: Cache SonarQube Cloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarQube Cloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarQube Cloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: bash
run: |
mkdir -p .sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path .sonar/scanner
- name: Install dotCover
shell: bash
run: |
dotnet tool install --global JetBrains.dotCover.GlobalTool
- name: Build, run code coverage, and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: bash
run: |
filter=""
if [ "${{ env.TEST_FILTER }}" != "" ]; then
filter="--filter ${{ env.TEST_FILTER }}"
fi
.sonar/scanner/dotnet-sonarscanner begin /k:"${{ env.PROJECT_NAME }}" /o:"${{ env.ORGANISATION }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths=dotCover.Output.html
dotnet build
dotnet dotcover test $filter --dcReportType=HTML
.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

0 comments on commit ee1240d

Please sign in to comment.