Repository navigation
chore(support/v2): release 2.3.0 #959
This file contains hidden or 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: Sonarcloud | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| - support/v1 | |
| - support/v2 | |
| paths-ignore: ['.vscode/**'] | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| paths-ignore: ['.vscode/**'] | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| jobs: | |
| checksecret: | |
| name: check if SONAR_TOKEN is set in github secrets | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_SONAR_TOKEN_set: ${{ steps.checksecret_job.outputs.is_SONAR_TOKEN_set }} | |
| steps: | |
| - name: Check whether unity activation requests should be done | |
| id: checksecret_job | |
| run: | | |
| echo "is_SONAR_TOKEN_set=${{ env.SONAR_TOKEN != '' }}" >> $GITHUB_OUTPUT | |
| build: | |
| needs: [checksecret] | |
| if: needs.checksecret.outputs.is_SONAR_TOKEN_set == 'true' | |
| name: Build | |
| runs-on: windows-latest | |
| steps: | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'adopt' | |
| java-version: 17 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: | | |
| 8.0.x | |
| 10.0.x | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Install SonarCloud scanner | |
| run: dotnet tool install dotnet-sonarscanner --create-manifest-if-needed | |
| - name: Install PowerShell test dependency | |
| shell: pwsh | |
| run: Install-Module Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force | |
| - name: Test Hidi NuGet helpers with measured coverage | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| Import-Module Pester -RequiredVersion 5.7.1 -ErrorAction Stop | |
| $helperPaths = @('scripts/check-nuget-package-published.ps1', 'scripts/verify-hidi-package-assembly.ps1') | |
| $helpers = @($helperPaths | ForEach-Object { (Resolve-Path $_).Path }) | |
| $outputRoot = Join-Path $PWD 'artifacts\hidi\powershell-coverage' | |
| New-Item -ItemType Directory -Force -Path $outputRoot | Out-Null | |
| $configuration = New-PesterConfiguration | |
| $configuration.Run.Path = @('test\Microsoft.OpenApi.Hidi.Tests\check-nuget-package-published.Tests.ps1', 'test\Microsoft.OpenApi.Hidi.Tests\verify-hidi-package-assembly.Tests.ps1') | |
| $configuration.Run.PassThru = $true | |
| $configuration.CodeCoverage.Enabled = $true | |
| $configuration.CodeCoverage.Path = $helpers | |
| $configuration.CodeCoverage.OutputFormat = 'JaCoCo' | |
| $configuration.CodeCoverage.OutputPath = Join-Path $outputRoot 'pester-coverage.xml' | |
| $configuration.CodeCoverage.CoveragePercentTarget = 80 | |
| $result = Invoke-Pester -Configuration $configuration | |
| if ($result.FailedCount -gt 0 -or $result.PassedCount -lt 45) { | |
| throw "Hidi NuGet helper tests failed or did not execute all 45 cases." | |
| } | |
| $report = [xml](Get-Content $configuration.CodeCoverage.OutputPath.Value -Raw) | |
| $sourceFiles = @($report.SelectNodes('//sourcefile')) | |
| if ($sourceFiles.Count -ne $helpers.Count) { | |
| throw 'Expected measured coverage of both Hidi NuGet helpers.' | |
| } | |
| $coverage = [xml]'<coverage version="1"/>' | |
| foreach ($helperPath in $helperPaths) { | |
| $helper = (Resolve-Path $helperPath).Path | |
| $source = @($sourceFiles | Where-Object { $_.name -eq [IO.Path]::GetFileName($helper) }) | |
| if ($source.Count -ne 1) { throw "Missing or ambiguous measured coverage for $helperPath." } | |
| $lines = @($source[0].SelectNodes('line')) | |
| $sourceLineCount = @(Get-Content $helper).Count | |
| $lineNumbers = @($lines | ForEach-Object { [int]$_.nr }) | |
| if ($lines.Count -eq 0 -or @($lineNumbers | Select-Object -Unique).Count -ne $lines.Count -or | |
| @($lines | Where-Object { | |
| [int]$_.nr -le 0 -or [int]$_.nr -gt $sourceLineCount -or | |
| -not $_.HasAttribute('ci') -or -not $_.HasAttribute('mi') -or | |
| [int]$_.ci -lt 0 -or [int]$_.mi -lt 0 -or ([int]$_.ci + [int]$_.mi) -le 0 | |
| }).Count -gt 0) { | |
| throw "Missing or invalid measured helper coverage lines for $helperPath." | |
| } | |
| $covered = @($lines | Where-Object { [int]$_.ci -gt 0 }).Count | |
| if ($covered / $lines.Count -lt 0.8) { | |
| throw "Insufficient measured Hidi helper coverage for ${helperPath}: $covered/$($lines.Count) lines." | |
| } | |
| $file = $coverage.CreateElement('file') | |
| $file.SetAttribute('path', $helperPath) | |
| [void]$coverage.DocumentElement.AppendChild($file) | |
| foreach ($line in $lines) { | |
| $entry = $coverage.CreateElement('lineToCover') | |
| $entry.SetAttribute('lineNumber', $line.nr) | |
| $entry.SetAttribute('covered', ([int]$line.ci -gt 0).ToString().ToLowerInvariant()) | |
| [void]$file.AppendChild($entry) | |
| } | |
| Write-Host "Measured Hidi NuGet helper coverage for ${helperPath}: $covered/$($lines.Count) lines." | |
| } | |
| $coverage.Save((Join-Path $outputRoot 'sonar-coverage.xml')) | |
| Write-Host "Sonar generic report generated from measured coverage." | |
| - name: Build and analyze | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
| shell: pwsh | |
| run: | | |
| dotnet tool run dotnet-sonarscanner begin /k:"microsoft_OpenAPI.NET.OData" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="artifacts/test-results/*opencover*.xml" /d:sonar.coverageReportPaths="artifacts/hidi/powershell-coverage/sonar-coverage.xml" | |
| if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } | |
| dotnet workload restore | |
| if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } | |
| dotnet build | |
| if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } | |
| dotnet test --solution Microsoft.OpenApi.OData.sln --no-build --results-directory artifacts\test-results -- --minimum-expected-tests 1 --report-trx --report-gh --coverlet --coverlet-output-format opencover --coverlet-include "[Microsoft.OpenApi.OData.Reader]*" --coverlet-include "[Microsoft.OpenApi.Hidi]*" | |
| if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } | |
| $reports = @(Get-ChildItem artifacts\test-results -Filter '*opencover*.xml') | |
| if ($reports.Count -ne 2) { throw "Expected an OpenCover report from each test project." } | |
| dotnet tool run dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" | |
| if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } | |
| - name: Upload test and coverage results | |
| if: always() | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: sonar-test-results | |
| path: artifacts/test-results | |
| if-no-files-found: error |