Skip to content

Build and analyze

Build and analyze #9

Workflow file for this run

name: Build and analyze
on:
push:
branches: [develop, master]
pull_request:
types: [opened, synchronize, reopened]
branches: [develop, master]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
env:
solutionPath: './DurationMancer.slnx'
buildConfiguration: 'Release'
jobs:
build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Code checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis and for GitVersion based versioning
# --- GitVersion ---
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v4.2.0
with:
versionSpec: '6.5.x'
- name: Determine Version
id: version_step # step id used as reference for output values
uses: gittools/actions/gitversion/command@v4.2.0
with:
arguments: '/output buildserver /l console /config GitVersion.yaml /updateprojectfiles' # have to self-define all arguments; /updateprojectfiles not impl. in execute task
# --- Tool setup ---
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
# --- SonarCloud caching & installation ---
- 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: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
# --- Restore ---
- name: Restore ${{ env.solutionPath }} dependencies
run: dotnet restore ${{ env.solutionPath }}
# --- SonarCloud begin ---
- name: Prepare SonarQube analyze
shell: powershell
run: >
.\.sonar\scanner\dotnet-sonarscanner begin /k:"HaGGi13_DurationMancer" /o:"haggi13"
/d:sonar.host.url="https://sonarcloud.io"
/v:"${{ env.GitVersion_FullSemVer }}"
/d:sonar.token="${{ secrets.SONAR_TOKEN }}"
/d:sonar.cs.opencover.reportsPaths=./TestResults/coverage.opencover.xml
/d:sonar.cs.opencover.reportsPaths=merged-coverage/opencover.xml
# --- Build ---
- name: Build ${{ env.solutionPath }} ${{ env.GitVersion_FullSemVer }}
run: >
dotnet build ${{ env.solutionPath }}
--no-restore
-c ${{ env.buildConfiguration }}
# --- Test ---
- name: Test ${{ env.solutionPath }}
run: >
dotnet test ${{ env.solutionPath }} --no-build -c ${{ env.buildConfiguration }}
--logger trx
--results-directory "./TestResults/"
--logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
/p:CollectCoverage=true
/p:CoverletOutputFormat="opencover"
/p:CoverletOutput="./../../TestResults/coverage"
- name: Install ReportGenerator
run: dotnet tool install --global dotnet-reportgenerator-globaltool
- name: Merge coverage reports
run: >
reportgenerator
-reports:"TestResults/coverage*.opencover.xml"
-targetdir:"merged-coverage"
-reporttypes:opencover
- name: Upload dotnet test results
uses: actions/upload-artifact@v4
with:
name: TestResults
path: ./TestResults/
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
# --- SonarCloud end ---
- name: Run SonarQube analyze
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
# --- NuGet Pack, Upload & Publish ---
- name: Pack NuGet package
run: >
dotnet pack ${{ env.solutionPath }}
--no-build
-c ${{ env.buildConfiguration }}
-o ./nupkg
/p:PackageVersion=${{ env.GitVersion_FullSemVer }}
- name: Upload NuGet package artifact
uses: actions/upload-artifact@v6
with:
name: NuGetPackage
path: ./nupkg/*.nupkg
retention-days: 3