Skip to content

Build and analyze

Build and analyze #22

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:
DOTNET_CLI_TELEMETRY_OPTOUT: 1 # Opt out of telemetry to speed up the build
DOTNET_NOLOGO: 1 # Prevents the dotnet CLI logo from displaying that speeds up build times
libraryPath: './src/DurationMancer/DurationMancer.csproj'
testsPath: './tests/DurationMancer.Tests/DurationMancer.Tests.csproj'
buildConfiguration: 'Release'
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
jobs:
build:
name: Build and analyze
runs-on: ubuntu-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 installation ---
- name: Install SonarQube Cloud scanner
run: dotnet tool install dotnet-sonarscanner --global
# --- Restore ---
- name: Restore library
run: dotnet restore ${{ env.libraryPath }}
- name: Restore tests
run: dotnet restore ${{ env.testsPath }}
# --- SonarCloud begin ---
- name: Prepare SonarQube analyze
run: >
dotnet-sonarscanner begin /k:"HaGGi13_DurationMancer" /o:"haggi13"
/d:sonar.host.url="https://sonarcloud.io"
/v:"${{ env.GitVersion_FullSemVer }}"
/d:sonar.token="$SONAR_TOKEN"
/d:sonar.cs.opencover.reportsPaths=./TestResults/coverage*.opencover.xml
/d:sonar.exclusions="benchmarks/**"
/d:sonar.coverage.exclusions="benchmarks/**"
# --- Build ---
- name: Build library ${{ env.GitVersion_FullSemVer }}
run: >
dotnet build ${{ env.libraryPath }}
--no-restore
-c ${{ env.buildConfiguration }}
- name: Build tests
run: >
dotnet build ${{ env.testsPath }}
--no-restore
-c ${{ env.buildConfiguration }}
# --- Test ---
- name: Test
run: >
dotnet test ${{ env.testsPath }} --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: 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
run: dotnet-sonarscanner end /d:sonar.token="$SONAR_TOKEN"
# --- NuGet Pack + Upload ---
- name: Pack NuGet package
run: >
dotnet pack ${{ env.libraryPath }}
--no-build
-c ${{ env.buildConfiguration }}
-o ./nupkg
/p:PackageVersion=${{ env.GitVersion_FullSemVer }}
- name: Upload NuGet package artifact
uses: actions/upload-artifact@v4
with:
name: NuGetPackage
path: ./nupkg/*.nupkg
retention-days: 3