Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build-test-snar-ps/build-test-sonar.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
if ([string]::IsNullOrWhiteSpace($env:SONAR_TOKEN)) {
Write-Error "SONAR_TOKEN is not set. Without it the scanner authenticates anonymously and the analysis fails later with 'Not authorized or project not found'."
exit 1
}

dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-coverage
dotnet restore Ploch.Common.sln
dotnet sonarscanner begin /k:"mrploch_ploch-common" /o:"mrploch" /d:sonar.login="$sonarToken" /d:sonar.cs.opencover.reportsPaths=**/CoverageResults/coverage.opencover.xml /d:sonar.host.url="https://sonarcloud.io"
dotnet sonarscanner begin /k:"mrploch_ploch-common" /o:"mrploch" /d:sonar.token="$env:SONAR_TOKEN" /d:sonar.cs.opencover.reportsPaths=**/CoverageResults/coverage.opencover.xml /d:sonar.host.url="https://sonarcloud.io"
Comment thread
kploch marked this conversation as resolved.
dotnet build Ploch.Common.sln --no-incremental --no-restore
dotnet test Ploch.Common.sln --verbosity normal --no-build --logger "trx;LogFileName=TestOutputResults.xml" /p:CollectCoverage=true /p:CoverletOutput=./CoverageResults/ "/p:CoverletOutputFormat=cobertura%2copencover"
dotnet sonarscanner end /d:sonar.login="$env:SONAR_TOKEN"
dotnet sonarscanner end /d:sonar.token="$env:SONAR_TOKEN"
Comment thread
kploch marked this conversation as resolved.
37 changes: 26 additions & 11 deletions build-test-sonar/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ description: 'Build and Test .NET Solution with SonarCloud'
author: 'Kris Ploch'
inputs:
dotnet-version:
description: '.NET version'
description: >-
.NET SDK version to install, in actions/setup-dotnet syntax. This value is
always passed to actions/setup-dotnet, which therefore never falls back to
a global.json in the consuming repository. Consumers targeting a different
framework (for example net10.0) must set this explicitly rather than
relying on whichever SDK the runner image happens to ship.
required: false
default: 9.0.x
default: 9.0.x
Comment thread
coderabbitai[bot] marked this conversation as resolved.
solution-path:
description: 'Solution path to build'
required: true
Expand All @@ -22,25 +27,31 @@ inputs:
description: 'SonarQube Url, defaults to SonarCloud'
default: 'https://sonarcloud.io'
required: false
outputs:
random-number:
description: "Random number"
value: ${{ steps.random-number-generator.outputs.random-number }}
runs:
using: "composite"
steps:
- name: Validate SonarCloud Token
shell: pwsh
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
run: |
if ([string]::IsNullOrWhiteSpace($env:SONAR_TOKEN)) {
Write-Output "::error::The 'sonar-token' input is empty. SonarCloud analysis would run anonymously and then fail during post-processing with a misleading 'Not authorized or project not found'. Check that the calling workflow passes a non-empty secret and that the secret is available to this job."
exit 1
}
Write-Output "SonarCloud token supplied ($($env:SONAR_TOKEN.Length) characters)."
- name: Action Properties
shell: pwsh
run: |
$InformationPreference="Continue"
Write-Information "Building ${{ inputs.solution-path }} with .NET ${{ inputs.dotnet-version }}"
Write-Information "SonarCloud Organization: ${{ inputs.sonar-organization }} Project Key: ${{ inputs.sonar-project-key }} Login: ${{ inputs.sonar-token }}"
- uses: actions/setup-java@v4
Write-Information "SonarCloud Organization: ${{ inputs.sonar-organization }} Project Key: ${{ inputs.sonar-project-key }}"
- uses: actions/setup-java@v5
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17'
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ inputs.dotnet-version }}
- name: Restore dependencies
Expand All @@ -54,7 +65,9 @@ runs:
run: dotnet tool install --global dotnet-coverage
- name: SonarScanner Begin
shell: pwsh
run: dotnet sonarscanner begin /k:"${{ inputs.sonar-project-key }}" /o:"${{ inputs.sonar-organization }}" /d:sonar.login="${{ inputs.sonar-token }}" /d:sonar.cs.opencover.reportsPaths=**/CoverageResults/coverage.opencover.xml /d:sonar.host.url="${{ inputs.sonar-url }}"
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
run: dotnet sonarscanner begin /k:"${{ inputs.sonar-project-key }}" /o:"${{ inputs.sonar-organization }}" /d:sonar.token="$env:SONAR_TOKEN" /d:sonar.cs.opencover.reportsPaths=**/CoverageResults/coverage.opencover.xml /d:sonar.host.url="${{ inputs.sonar-url }}"
- name: Build
shell: pwsh
run: dotnet build ${{ inputs.solution-path }} --no-restore
Expand All @@ -63,4 +76,6 @@ runs:
run: dotnet test ${{ inputs.solution-path }} --verbosity normal --no-build --logger "trx;LogFileName=test-results.trx" /p:CollectCoverage=true /p:CoverletOutput=./CoverageResults/ "/p:CoverletOutputFormat=cobertura%2copencover"
- name: SonarScanner End
shell: pwsh
run: dotnet sonarscanner end /d:sonar.login="${{ inputs.sonar-token }}"
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
run: dotnet sonarscanner end /d:sonar.token="$env:SONAR_TOKEN"