Skip to content

Add tests for .NET Framework #147

Add tests for .NET Framework

Add tests for .NET Framework #147

name: Continuous Integration
on: [push, pull_request]
env:
Configuration: Release
ContinuousIntegrationBuild: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
jobs:
package:
strategy:
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
dotnet-version: ['481', '6.0', '8.0']
framework-version: ['netstandard2.0', 'net6.0']
exclude:
- os: macos-latest
dotnet-version: 481
- os: ubuntu-latest
dotnet-version: 481
- dotnet-version: 481
framework-version: net6.0
- dotnet-version: 6.0
framework-version: netstandard2.0
- dotnet-version: 8.0
framework-version: netstandard2.0
fail-fast: false
runs-on: ${{ matrix.os }}
name: Build and run tests
steps:
- name: Checkout git repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Restore NuGet packages for CoreTest
run: dotnet restore --no-dependencies -p:TargetFramework=net${{ matrix.dotnet-version }} --verbosity normal CoreTest
- name: Restore library Core
run: dotnet restore --verbosity normal Core
- name: Build library Core
run: dotnet build --configuration Release --no-restore --verbosity normal Core
- name: Build test project CoreTest
run: dotnet build --configuration Release --no-restore -p:TargetFramework=net${{ matrix.dotnet-version }} --verbosity normal CoreTest
- name: Run tests CoreTest
run: dotnet test --configuration Release --no-build -P:TargetFramework=net${{ matrix.dotnet-version }} --logger:"html;LogFileName=../../TestResults-CoreTest-${{ matrix.os }}-dotnet_${{ matrix.dotnet-version }}.html" --verbosity normal CoreTest
- name: Restore NuGet packages for PixelCanvasTest
run: dotnet restore --no-dependencies -p:TargetFramework=net${{ matrix.dotnet-version }} --verbosity normal PixelCanvasTest
- name: Restore library PixelCanvas
run: dotnet restore --verbosity normal PixelCanvas
- name: Build library PixelCanvas
run: dotnet build --configuration Release --no-restore --verbosity normal PixelCanvas
- name: Build test project PixelCanvasTest
run: dotnet build --configuration Release --no-restore -p:TargetFramework=net${{ matrix.dotnet-version }} --verbosity normal PixelCanvasTest
- name: Run tests PixelCanvasTest
run: dotnet test --configuration Release --no-build -P:TargetFramework=net${{ matrix.dotnet-version }} --logger:"html;LogFileName=../../TestResults-PixelCanvasTest-${{ matrix.os }}-dotnet_${{ matrix.dotnet-version }}.html" --verbosity normal PixelCanvasTest
- name: Restore NuGet packages for WindowsTest
run: dotnet restore --no-dependencies -p:TargetFramework=net${{ matrix.dotnet-version }} --verbosity normal WindowsTest
if: startsWith(matrix.os,'windows')
- name: Restore library Windows
run: dotnet restore --verbosity normal Windows
if: startsWith(matrix.os,'windows')
- name: Build library Windows
run: dotnet build --configuration Release --no-restore --verbosity normal Windows
if: startsWith(matrix.os,'windows')
- name: Build test project WindowsTest
run: dotnet build --configuration Release --no-restore -p:TargetFramework=net${{ matrix.dotnet-version }} --verbosity normal WindowsTest
if: startsWith(matrix.os,'windows')
- name: Run tests WindowsTest
run: dotnet test --configuration Release --no-build -P:TargetFramework=net${{ matrix.dotnet-version }} --logger:"html;LogFileName=../../TestResults-WindowsTest-${{ matrix.os }}-dotnet_${{ matrix.dotnet-version }}.html" --verbosity normal WindowsTest
if: startsWith(matrix.os,'windows')
- name: Upload received files from failing tests
uses: actions/upload-artifact@v4
if: failure()
with:
name: Received-${{ runner.os }}-${{ matrix.dotnet-version }}
path: "**/*.received.*"
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: TestResults-${{ runner.os }}-${{ matrix.dotnet-version }}
path: TestResults-*.html
- name: Create and validate NuGet package for Core
run: dotnet pack --no-build --verbosity normal Core/Core.csproj
if: startsWith(matrix.os,'windows')
- name: Create and validate NuGet package for PixelCanvas
run: dotnet pack --no-build --verbosity normal PixelCanvas/PixelCanvas.csproj
if: startsWith(matrix.os,'windows')
- name: Create and validate NuGet package for Windows
run: dotnet pack --no-build --verbosity normal WindowsTest/WindowsTest.csproj
if: startsWith(matrix.os,'windows')
- name: Set up JDK 17 (for SonarQube)
if: startsWith(matrix.os,'windows') && matrix.dotnet-version == '8.0'
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- name: Cache SonarCloud packages
if: startsWith(matrix.os,'windows') && matrix.dotnet-version == '8.0'
uses: actions/cache@v4
with:
path: ~\.sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
if: startsWith(matrix.os,'windows') && matrix.dotnet-version == '8.0'
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 SonarCloud scanner
if: startsWith(matrix.os,'windows') && matrix.dotnet-version == '8.0' && 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
- name: Cache dotnet-coverage
if: startsWith(matrix.os,'windows') && matrix.dotnet-version == '8.0'
id: cache-dotnet-coverage
uses: actions/cache@v4
with:
path: .\.dotnet-coverage
key: ${{ runner.os }}-dotnet-coverage
restore-keys: ${{ runner.os }}-dotnet-coverage
- name: Install dotnet-coverage
if: startsWith(matrix.os,'windows') && matrix.dotnet-version == '8.0' && steps.cache-dotnet-coverage.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.dotnet-coverage -ItemType Directory
dotnet tool update dotnet-coverage --tool-path .\.dotnet-coverage
- name: Build and analyze
if: startsWith(matrix.os,'windows') && matrix.dotnet-version == '8.0'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
dotnet clean
.\.sonar\scanner\dotnet-sonarscanner begin /k:"manuelbl_SwissQRBill.NET" /o:"manuelbl-github" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet build --no-incremental
.\.dotnet-coverage\dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"