Introduce ThreadSafeSingleton, improve default type matching logic,…
#275
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: Build & Test | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| - 'feature/**' | |
| - 'release/**' | |
| - 'hotfix/**' | |
| env: | |
| configuration: Release | |
| artifacts-dir: artifacts | |
| nugets-dir: artifacts/nupkgs | |
| pdb-dir: artifacts/pdb | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: 10.0.x | |
| - name: Install GitVersion | |
| run: dotnet tool install --global GitVersion.Tool --version 6.0.* | |
| - name: Execute GitVersion | |
| id: gitversion | |
| shell: pwsh | |
| run: | | |
| # Run GitVersion and parse the JSON output | |
| $gitVersion = dotnet-gitversion | ConvertFrom-Json | |
| # Write necessary variables directly to the GitHub Environment file | |
| "AssemblySemVer=$($gitVersion.AssemblySemVer)" >> $env:GITHUB_ENV | |
| "AssemblySemFileVer=$($gitVersion.AssemblySemFileVer)" >> $env:GITHUB_ENV | |
| "InformationalVersion=$($gitVersion.InformationalVersion)" >> $env:GITHUB_ENV | |
| "SemVer=$($gitVersion.SemVer)" >> $env:GITHUB_ENV | |
| - name: Build | |
| run: > | |
| dotnet build | |
| -c ${{ env.configuration }} | |
| -p:AssemblyVersion=${{ env.AssemblySemVer }} | |
| -p:FileVersion=${{ env.AssemblySemFileVer }} | |
| -p:InformationalVersion=${{ env.InformationalVersion }} | |
| # Run tests and generate an OpenCover report | |
| - name: Test | |
| run: dotnet test --no-build --settings .runsettings --collect:"XPlat Code Coverage" | |
| - name: Pack | |
| run: dotnet pack --no-build -o:${{ env.nugets-dir }} -p:PackageVersion=${{ env.AssemblySemVer }} | |
| - name: Store Version JSON | |
| shell: pwsh | |
| run: | | |
| New-Item -Path "${{ env.artifacts-dir }}" -ItemType Directory -Force | Out-Null | |
| $json = @{ | |
| "assembly-version" = "${{ env.AssemblySemVer }}" | |
| "assembly-file-version" = "${{ env.AssemblySemFileVer }}" | |
| "nuget-version" = "${{ env.AssemblySemVer }}" | |
| } | ConvertTo-Json | |
| Set-Content -Path "${{ env.artifacts-dir }}/version.json" -Value $json -Encoding UTF8 | |
| - name: Store PDB | |
| shell: pwsh | |
| run: | | |
| New-Item -Path "${{ env.pdb-dir }}" -ItemType Directory -Force | Out-Null | |
| Copy-Item -Path "./.out/bin/netstandard2.0/*.pdb" -Destination "${{ env.pdb-dir }}" -Force -ErrorAction SilentlyContinue | |
| - name: Upload Artifacts | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: Artifacts | |
| path: ${{ env.artifacts-dir }}/ | |
| retention-days: 3 | |
| - name: Create & Upload Test Coverage Badge | |
| shell: pwsh | |
| run: | | |
| # 1. Dynamically find the report file, as it is located in a folder with a GUID | |
| $xmlPath = Get-ChildItem -Path . -Filter "coverage.cobertura.xml" -Recurse | Select-Object -First 1 -ExpandProperty FullName | |
| if (-not $xmlPath) { | |
| Write-Error "Coverage file not found!" | |
| exit 1 | |
| } | |
| Write-Host "Found coverage file at: $xmlPath" | |
| # 2. Parse the Cobertura XML | |
| [xml]$xml = Get-Content $xmlPath | |
| # In Cobertura, line-rate is a decimal (from 0.0 to 1.0), so we multiply by 100 | |
| $lineRate = $xml.coverage.'line-rate' | |
| $percentage = [math]::Round([decimal]$lineRate * 100, 2) | |
| Write-Host "Code coverage percentage: $percentage%" | |
| # 3. Determine the badge color | |
| $color = "red" | |
| if ($percentage -ge 80) { $color = "brightgreen" } | |
| elseif ($percentage -ge 60) { $color = "yellow" } | |
| # 4. Create JSON payload for Shields.io | |
| $badgeContent = @{ | |
| schemaVersion = 1 | |
| label = "Unit Test Coverage" | |
| message = "$percentage%" | |
| color = $color | |
| } | ConvertTo-Json -Compress | |
| Write-Host "Badge data: $badgeContent" | |
| # 5. Prepare the data for the GitHub Gist API | |
| $gistData = @{ | |
| description = "Updated coverage badge" | |
| files = @{ | |
| "bits-test-coverage.json" = @{ | |
| content = $badgeContent | |
| } | |
| } | |
| } | ConvertTo-Json -Depth 5 | |
| # 6. Send the PATCH request | |
| Invoke-RestMethod -Uri "https://api.github.com/gists/21c1ecd6072def6cf2300fe365aa46b9" ` | |
| -Method Patch ` | |
| -Headers @{ | |
| Authorization = "token ${{ secrets.GIST_KEY }}" | |
| Accept = "application/vnd.github.v3+json" | |
| } ` | |
| -Body $gistData |