1212 - ' **'
1313 pull_request :
1414 branches :
15- - ' master '
15+ - ' main '
1616 - ' develop'
1717 paths-ignore :
1818 - ' **.md'
1919 tags-ignore :
2020 - ' **'
21+ pull_request_target :
22+ branches :
23+ - ' main'
24+ - ' develop'
25+ paths-ignore :
26+ - ' **.md'
27+ tags-ignore :
28+ - ' **'
29+
30+ env :
31+ COREHOST_TRACE : false
32+ DOTNET_CLI_TELEMETRY_OPTOUT : 1 # Disable sending usage data to Microsoft
33+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : 1 # prevent the caching of the packages on the build machine
34+ DOTNET_NOLOGO : true # removes logo and telemetry message from first run of dotnet cli
35+ NUGET_XMLDOC_MODE : skip # prevent the download of the XML documentation for the packages
36+ COVERAGE_PATH : SignNow.Net.Test/bin/Debug
37+ # Do not generate summary otherwise it leads to duplicate errors in build log
38+ DOTNET_BUILD_ARGS : /consoleloggerparameters:NoSummary /property:GenerateFullPaths=true
39+
40+ defaults :
41+ run :
42+ shell : pwsh
2143
2244# Workflow
2345jobs :
@@ -31,49 +53,39 @@ jobs:
3153 matrix :
3254 include :
3355 # Ubuntu
34- - { name: 'Linux .NET 8', os: ubuntu-22.04, framework: 'net8.0' }
56+ - { name: 'Linux .NET 8', os: ubuntu-22.04, framework: 'net8.0', net-sdk: '8.0.x', target: 'netstandard2.1' }
3557 # macOs - disabled due to the same behavior as in Ubuntu
3658 # - { name: 'macOS .NET 8', os: macos-13, framework: 'net8.0' }
3759 # Windows
38- - { name: 'Windows .NET 7', os: windows-latest, framework: 'net7.0' }
39- - { name: 'Windows .NET 8', os: windows-latest, framework: 'net8.0' }
40- - { name: 'Windows .NET 4.6', os: windows-latest, framework: 'net462' }
41-
42- env :
43- COREHOST_TRACE : false
44- DOTNET_CLI_TELEMETRY_OPTOUT : 1 # Disable sending usage data to Microsoft
45- DOTNET_SKIP_FIRST_TIME_EXPERIENCE : 1 # prevent the caching of the packages on the build machine
46- DOTNET_NOLOGO : true # removes logo and telemetry message from first run of dotnet cli
47- NUGET_XMLDOC_MODE : skip # prevent the download of the XML documentation for the packages
48- COVERAGE_PATH : SignNow.Net.Test/bin/Debug
49- # Do not generate summary otherwise it leads to duplicate errors in build log
50- DOTNET_BUILD_ARGS : /consoleloggerparameters:NoSummary /property:GenerateFullPaths=true
51-
52- defaults :
53- run :
54- shell : pwsh
60+ - { name: 'Windows .NET 7', os: windows-latest, framework: 'net7.0', net-sdk: '7.0.x', target: 'netstandard2.0' }
61+ - { name: 'Windows .NET 8', os: windows-latest, framework: 'net8.0', net-sdk: '8.0.x', target: 'netstandard2.1' }
62+ - { name: 'Windows .NET 4.6', os: windows-latest, framework: 'net462', net-sdk: '8.0.x', target: 'net462' }
5563
5664 steps :
5765 - uses : actions/checkout@v4
5866 with :
5967 fetch-depth : 1
68+ # For pull_request_target (dependabot), checkout the PR head SHA
69+ ref : ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
6070
61- - name : Setup .NET SDK Version for Target Framework
71+ - name : Get SDK Version
72+ id : props
6273 run : |
63- If ("${{ matrix.framework }}" -eq "net7.0") {
64- Write-Output "DOTNET_SDK_VERSION=7.0.x" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
65- Write-Output "TARGET_FRAMEWORK=netstandard20" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
66- } ElseIf ("${{ matrix.framework }}" -eq "net8.0") {
67- Write-Output "DOTNET_SDK_VERSION=8.0.x" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
68- Write-Output "TARGET_FRAMEWORK=netstandard21" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
69- } Else {
70- Write-Output "TARGET_FRAMEWORK=462" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
71- }
74+ $Props = [xml](Get-Content ./SignNow.props)
75+ $Version = $Props.Project.PropertyGroup.Version
76+ Write-Output "version=${Version}" >> $Env:GITHUB_OUTPUT
77+ Write-Host "✓ Found SignNow.NET SDK project version: $Version"
78+
79+ - name : Setup JDK 17 (SonarQube requirement)
80+ uses : actions/setup-java@v4
81+ with :
82+ distribution : ' zulu'
83+ java-version : ' 17'
7284
7385 - name : Setup .NET SDK
7486 uses : actions/setup-dotnet@v4
7587 with :
76- dotnet-version : ${{ env.DOTNET_SDK_VERSION }}
88+ dotnet-version : ${{ matrix.net-sdk }}
7789
7890 - name : Setup Nuget Cache
7991 uses : actions/cache@v4
@@ -83,41 +95,94 @@ jobs:
8395 key : ${{ runner.os }}-nuget-${{ matrix.framework }}-${{ hashFiles('**/*.csproj') }}
8496 restore-keys : ${{ runner.os }}-nuget-
8597
98+ - name : Install SonarQube Scanner
99+ run : dotnet tool install --global dotnet-sonarscanner
100+
86101 - name : Restore Nuget packages
87102 run : dotnet restore -v:n
88103
89104 - name : Configure signNow API
90105 run : echo '${{ secrets.TEST_CREDITS_JSON }}' >> ${{ github.workspace }}/api-eval.signnow.com.json
91106
92- - name : Build and Pack Solution
107+ - name : Get SonarQube Project Key
108+ id : sonar
93109 run : |
94- dotnet build SignNow.Net --configuration Debug ${{ env.DOTNET_BUILD_ARGS }}
95- dotnet pack --configuration Release --output ./SignNow.Net/bin/Publish SignNow.Net
110+ $SonarConfigPath = "${{ github.workspace }}/SonarQube.Analysis.xml"
111+ if (Test-Path $SonarConfigPath) {
112+ [xml]$SonarConfig = Get-Content $SonarConfigPath
113+ $ProjectKey = $SonarConfig.SonarQubeAnalysisProperties.Property | Where-Object { $_.Name -eq "sonar.projectKey" } | Select-Object -ExpandProperty '#text'
114+ if (-not [string]::IsNullOrWhiteSpace($ProjectKey)) {
115+ Write-Host "✓ Found SonarQube project key: $ProjectKey"
116+ Write-Output "project-key=${ProjectKey}" >> $Env:GITHUB_OUTPUT
117+ Write-Output "has-project-key=true" >> $Env:GITHUB_OUTPUT
118+ } else {
119+ Write-Warning "SonarQube project key is empty in configuration file"
120+ }
121+ } else {
122+ Write-Warning "SonarQube configuration file not found: $SonarConfigPath"
123+ }
96124
97- - name : Run Tests on ${{ matrix.framework }} with Coverage
125+ - name : SonarQube begin
126+ if : steps.sonar.outputs.has-project-key == 'true'
127+ run : |
128+ dotnet-sonarscanner begin `
129+ /key:${{ steps.sonar.outputs.project-key }} `
130+ /s:${{ github.workspace }}/SonarQube.Analysis.xml `
131+ /v:"${{ steps.props.outputs.version }}" `
132+ /d:sonar.projectBaseDir="${{ github.workspace }}" `
133+ /d:sonar.token="${{ secrets.SONAR_SECRET }}" `
134+ /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" `
135+ /d:sonar.scanner.skipJreProvisioning=true
136+
137+ - name : Run Tests on ${{ matrix.framework }} for TargetFramework ${{ matrix.target }} with Coverage
98138 run : |
99- dotnet test SignNow.Net.Test `
100- --configuration Debug --framework ${{ matrix.framework }} `
139+ # Build the main library with framework targeting for SonarQube
140+ dotnet build SignNow.Net --configuration Debug --no-incremental `
141+ /p:TargetFramework=${{ matrix.target }} `
142+ ${{ env.DOTNET_BUILD_ARGS }}
143+
144+ # Build the test project for the specific framework
145+ dotnet build SignNow.Net.Test --configuration Debug --no-incremental `
146+ --framework ${{ matrix.framework }} `
147+ ${{ env.DOTNET_BUILD_ARGS }}
148+
149+ dotnet test SignNow.Net.Test --configuration Debug --no-build `
150+ --framework ${{ matrix.framework }} `
151+ --logger:trx --results-directory ./SignNow.Net.Test/TestResults `
101152 /p:CollectCoverage=true
102153
103154 - name : Save Code Coverage Results
104155 uses : actions/upload-artifact@v4
105156 with :
106157 name : CoverageReports-${{ runner.os }}-${{ matrix.framework }}.zip
107- path : SignNow.Net.Test/bin/Debug/**/coverage*
158+ path : ${{ env.COVERAGE_PATH }}/**/coverage*
159+
160+ - name : SonarQube end
161+ if : steps.sonar.outputs.has-project-key == 'true'
162+ continue-on-error : true
163+ run : dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_SECRET }}"
108164
109165 - name : Test Release Notes parser
110166 if : (runner.os == 'macOS' || runner.os == 'Linux')
111167 shell : bash
112168 run : |
113169 .github/release-notes.sh CHANGELOG.md
114170
171+ - name : Check entire Solution Compilation and Packaging
172+ run : |
173+ # Build entire solution normally to ensure all projects are compiled
174+ dotnet build SignNow.Net.sln --configuration Debug --no-restore ${{ env.DOTNET_BUILD_ARGS }}
175+ dotnet pack --configuration Release --output ./SignNow.Net/bin/Publish SignNow.Net
176+
115177 - name : Upload Code Coverage Report (Codecov.io)
178+ if : env.CODECOV_TOKEN != ''
116179 continue-on-error : true
180+ env :
181+ CODECOV_TOKEN : ${{ secrets.CODECOV_TOKEN }}
117182 uses : codecov/codecov-action@v5
118183 with :
119184 name : ${{ runner.os }}-codecov-${{ matrix.framework }}
120- flags : ${{ runner.os }},${{ env.TARGET_FRAMEWORK }}
185+ flags : ${{ runner.os }},${{ matrix.target }}
121186 token : ${{ secrets.CODECOV_TOKEN }}
122187 files : ${{ env.COVERAGE_PATH }}/${{ matrix.framework }}/coverage.${{ matrix.framework }}.opencover.xml
123188 fail_ci_if_error : false
0 commit comments