ci: Move SonarCloud logic into a pwsh script

This allows running locally for testing purposes.
json-serializing-nullable-fields-issue
Robert Dailey 8 months ago
parent 40dda4dfa3
commit 8d18f98901

@ -29,10 +29,11 @@ jobs:
fetch-depth: 0 # avoid shallow clone for GitVersion
# GH Runners come with Java 11, which is deprecated by Sonarcloud
- name: Set up JDK 17
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 20
java-package: jre
distribution: temurin
- name: Setup dotnet
@ -40,38 +41,10 @@ jobs:
with:
dotnet-version: ${{ env.dotnetVersion }}
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: 5.x
- name: Determine Version
uses: gittools/actions/gitversion/execute@v0
id: gitversion
- name: Install Sonar Scanner
run: dotnet tool install --global dotnet-sonarscanner
- name: Begin Sonar Scanner
run: >
dotnet sonarscanner begin
-o:"recyclarr"
-k:"recyclarr_recyclarr"
-n:"Recyclarr"
-v:"${{ steps.gitversion.outputs.fullSemVer }}"
-d:sonar.token="${{ secrets.SONAR_TOKEN }}"
-d:sonar.host.url="https://sonarcloud.io"
-d:sonar.cs.opencover.reportsPaths="**/TestResults/*/coverage.opencover.xml"
# Run a full build command because if we just do the tests, it will not build everything.
# Building everything is important to ensure we analyze all code in the solution.
- name: Build
run: dotnet build src
- name: Test
run: dotnet test src --no-build --collect:"XPLat Code Coverage;Format=opencover"
- name: Install Tooling
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global GitVersion.Tool
- name: End Sonar Scanner
run: >
dotnet sonarscanner end
-d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Perform Scan
run: pwsh ci/RunSonarScan.ps1 -SonarToken "${{ secrets.SONAR_TOKEN }}"

19
.gitignore vendored

@ -1,5 +1,5 @@
# Created by https://www.toptal.com/developers/gitignore/api/windows,jetbrains,csharp,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,jetbrains,csharp,macos
# Created by https://www.toptal.com/developers/gitignore/api/windows,jetbrains,csharp,macos,sonarqube
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,jetbrains,csharp,macos,sonarqube
### Csharp ###
## Ignore Visual Studio temporary files, build results, and
@ -545,6 +545,19 @@ Temporary Items
# iCloud generated files
*.icloud
### SonarQube ###
# SonarQube ignore files.
#
# https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
# Sonar Scanner working directories
.sonar/
.sonarqube/
.scannerwork/
# http://www.sonarlint.org/commandline/
# SonarLint working directories, configuration files (including credentials)
.sonarlint/
### Windows ###
# Windows thumbnail cache files
Thumbs.db
@ -566,4 +579,4 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
# End of https://www.toptal.com/developers/gitignore/api/windows,jetbrains,csharp,macos
# End of https://www.toptal.com/developers/gitignore/api/windows,jetbrains,csharp,macos,sonarqube

@ -1,2 +1,3 @@
dotnet tool update --global GitVersion.Tool
Install-Module -Force -Name ChangelogManagement
dotnet tool update --global dotnet-sonarscanner

@ -1,5 +1,7 @@
$ErrorActionPreference = "Stop"
$gitIgnorePath = "$PSScriptRoot/.gitignore"
Function gig {
param(
[Parameter(Mandatory=$true)]
@ -8,7 +10,12 @@ Function gig {
$params = ($list | ForEach-Object { [uri]::EscapeDataString($_) }) -join ","
Invoke-WebRequest -Uri "https://www.toptal.com/developers/gitignore/api/$params" | `
Select-Object -ExpandProperty content | `
Out-File -FilePath $(Join-Path -path $pwd -ChildPath ".gitignore") -Encoding ascii
Set-Content -Path $gitIgnorePath -Encoding utf8 -NoNewline
}
gig windows,rider,csharp,macos
gig windows,jetbrains,csharp,macos,sonarqube
# Replace specific ignore patterns
$(Get-Content $gitIgnorePath) `
-replace '^\.idea', '**/.idea' `
| Set-Content -Path $gitIgnorePath

@ -0,0 +1,42 @@
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $SonarToken,
[switch] $Details
)
$version = $(dotnet-gitversion /showvariable semver)
if ($LASTEXITCODE -ne 0) { throw "Failed: dotnet gitversion" }
$beginArgs = @(
"-o:recyclarr"
"-k:recyclarr_recyclarr"
"-n:Recyclarr"
"-v:$version"
"-d:sonar.token=$SonarToken"
"-d:sonar.host.url=https://sonarcloud.io"
"-d:sonar.cs.opencover.reportsPaths=**/TestResults/*/coverage.opencover.xml"
)
if ($Details) {
$beginArgs += "-d:sonar.verbose=true"
}
"Args: $beginArgs"
dotnet sonarscanner begin @beginArgs
if ($LASTEXITCODE -ne 0) { throw "Failed: sonarscanner begin" }
try {
# Run a full build command because if we just do the tests, it will not build everything.
# Building everything is important to ensure we analyze all code in the solution.
dotnet build src
if ($LASTEXITCODE -ne 0) { throw "Failed: dotnet build" }
dotnet test src --no-build --collect:"XPLat Code Coverage;Format=opencover"
if ($LASTEXITCODE -ne 0) { throw "Failed: dotnet test" }
}
finally {
dotnet sonarscanner end "-d:sonar.token=$SonarToken"
if ($LASTEXITCODE -ne 0) { throw "Failed: sonarscanner end" }
}
Loading…
Cancel
Save