Scheduled SonarCloud #94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Scheduled SonarCloud" | |
on: | |
schedule: | |
- cron: '0 06 */7 * *' | |
jobs: | |
build-test: | |
name: "Build and Test" | |
runs-on: ubuntu-latest | |
steps: | |
### | |
# Checkout repository | |
### | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
lfs: true | |
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
### | |
# π§° Install .Net SDKs | |
# | |
# Configure the pipeline to use the correct .Net sdk versions | |
### | |
- name: π§° Install .Net SDKs | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 7.0.x | |
### | |
# π§° Setup .Net tools | |
# | |
# Register tools necessary to run the `test` pipeline-job | |
### | |
- name: π§° Setup .NET tools | |
run: |- | |
dotnet tool install --global dotnet-reportgenerator-globaltool | |
### | |
# π§° Setup SonarCloud scanner | |
# | |
# Installs and initializes the SonarCloud scanner | |
### | |
- name: π§° Setup SonarCloud scanner | |
shell: pwsh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: >- | |
[System.IO.Directory]::CreateDirectory('${{github.workspace}}/.sonar/scanner') | |
dotnet tool install dotnet-sonarscanner --tool-path '${{github.workspace}}/.sonar/scanner' | |
./.sonar/scanner/dotnet-sonarscanner begin | |
/k:"Marvin-Brouwer_FluentSerializer" | |
/o:"marvin-brouwer" | |
/d:sonar.login="${{ secrets.SONAR_TOKEN }}" | |
/d:sonar.host.url="https://sonarcloud.io" | |
/s:"${{github.workspace}}/SonarQube.Analysis.xml" | |
### | |
# π Restore dependencies | |
# | |
# Fill the NuGet store with necessary libraries | |
### | |
- name: π Restore dependencies | |
run: dotnet restore | |
### | |
# π Build | |
# | |
# Build the library code for later use | |
### | |
- name: π Build | |
run: dotnet build --no-restore --nologo --configuration "Release" | |
### | |
# π§ͺ Run unit tests | |
# | |
# Run the unit tests of category `UnitTest` and generate a code coverage report. | |
### | |
- name: π§ͺ Run unit tests | |
run: >- | |
dotnet test --verbosity:normal | |
--no-build --no-restore --nologo | |
--configuration="Release" | |
--logger:"console;verbosity=detailed" | |
--logger:"GitHubActions" | |
--logger "trx;LogFileName=test-results.trx" | |
--collect "DotnetCodeCoverage" | |
--collect "XPlat Code coverage" | |
--results-directory:"${{github.workspace}}/test-results" | |
--filter:"Category=UnitTest" | |
/p:CollectCoverage="true" | |
/p:CoverletOutputFormat="opencover" | |
/p:CoverletOutput="${{github.workspace}}/test-results/coverage/" | |
/p:MergeWith="${{github.workspace}}/test-results/coverage/" | |
/p:Exclude="[*Tests]*%2c[*TestUtils]*%2c[*UseCase*]*" | |
/clp:forceconsolecolor | |
"${{github.workspace}}/FluentSerializer.sln"; | |
reportgenerator | |
-reports:"${{github.workspace}}/test-results/*/coverage.cobertura.xml" | |
-targetdir:"${{github.workspace}}/test-results/coverage" | |
-reporttypes:SonarQube; | |
working-directory: ${{github.workspace}} | |
### | |
# π§ͺ Run integration tests | |
# | |
# Run the unit tests of category `IntegrationTest` to verify the integration of various unit-tests. | |
### | |
- name: π§ͺ Run integration tests | |
run: >- | |
dotnet test --verbosity:normal | |
--no-build --no-restore --nologo | |
--configuration="Release" | |
--logger:"console;verbosity=detailed" | |
--logger:"GitHubActions" | |
--filter:"Category=IntegrationTest" | |
/clp:forceconsolecolor | |
"${{github.workspace}}/FluentSerializer.sln"; | |
working-directory: ${{github.workspace}} | |
### | |
# π§ͺ Run use-case tests | |
# | |
# Run the unit tests of category `UseCase` to illustrate the library still works as intended. | |
# This is basically a kind of integration test. | |
### | |
- name: π§ͺ Run use-case tests | |
run: >- | |
dotnet test --verbosity:normal | |
--no-build --no-restore --nologo | |
--configuration="Release" | |
--logger:"console;verbosity=detailed" | |
--logger:"GitHubActions" | |
--filter:"Category=UseCase" | |
/clp:forceconsolecolor | |
"${{github.workspace}}/FluentSerializer.sln"; | |
working-directory: ${{github.workspace}} | |
### | |
# π¬ Perform SonarCloud Analysis | |
### | |
- name: π¬ Perform SonarCloud Analysis | |
shell: pwsh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: >- | |
./.sonar/scanner/dotnet-sonarscanner end | |
/d:sonar.login="${{ secrets.SONAR_TOKEN }}" |