diff --git a/.github/scripts/generate-test-summary.ps1 b/.github/scripts/generate-test-summary.ps1 new file mode 100644 index 0000000..6dc07cd --- /dev/null +++ b/.github/scripts/generate-test-summary.ps1 @@ -0,0 +1,55 @@ +# A simple script that prints a summary of the tests + +param ( + [string]$WorkspacePath = $env:GITHUB_WORKSPACE, + [string]$SummaryPath = $env:GITHUB_STEP_SUMMARY +) + +# If the script is running locally (outside of GitHub Actions), print to the console +if ([string]::IsNullOrEmpty($SummaryPath)) { + $SummaryPath = ".\local-summary-test.md" + Write-Host "Uruchomienie lokalne. Wynik zostanie zapisany do $SummaryPath" +} + +# Retrieving data from a TRX file (test results) +$trxFile = Get-ChildItem -Path "$WorkspacePath/TestResults" -Filter *.trx -Recurse | Select-Object -First 1 +$total = 0; $passed = 0; $failed = 0 + +if ($trxFile) { + [xml]$trx = Get-Content $trxFile.FullName + $counters = $trx.GetElementsByTagName("Counters")[0] + if ($counters) { + $total = $counters.GetAttribute("total") + $passed = $counters.GetAttribute("passed") + $failed = $counters.GetAttribute("failed") + } +} + +# Retrieving data from a Cobertura file (code coverage) +$covFile = Get-ChildItem -Path "$WorkspacePath/TestResults" -Filter coverage.cobertura.xml -Recurse | Select-Object -First 1 +$coverageText = "Brak danych" + +if ($covFile) { + [xml]$cov = Get-Content $covFile.FullName + $lineRateStr = $cov.DocumentElement.GetAttribute("line-rate") + if (![string]::IsNullOrWhiteSpace($lineRateStr)) { + $lineRate = [double]::Parse($lineRateStr, [System.Globalization.CultureInfo]::InvariantCulture) + $percent = [math]::Round($lineRate * 100, 2) + $coverageText = "$percent %" + } +} + + +$markdown = @" +## 📊 Podsumowanie testów + +| Metryka | Wynik | +|---|---| +| **Pokrycie kodu** | **$coverageText** | +| **Wszystkie testy** | $total | +| Zaliczone ✅ | $passed | +| Nieudane ❌ | $failed | +"@ + +# Write to the file specified by the GitHub environment variable +$markdown | Out-File -FilePath $SummaryPath -Append -Encoding utf8 diff --git a/.github/workflows/release-pipeline.yml b/.github/workflows/release-pipeline.yml index 5aad07c..022a9a0 100644 --- a/.github/workflows/release-pipeline.yml +++ b/.github/workflows/release-pipeline.yml @@ -4,7 +4,7 @@ on: # Uruchom automatycznie przy wrzuceniu kodu na gałąź main # Trigger automatically on push to the main branch push: - branches: [ "master" ] + branches: [ "master" , "dev"] paths-ignore: #- "**.md" - "**/Dockerfile" @@ -83,6 +83,12 @@ jobs: ${{ github.workspace }}/TestResults/*.trx ${{ github.workspace }}/TestResults/*.xml retention-days: 14 + + # Natywne generowanie podsumowania za pomocą skryptu + # Generating a summary natively using an script + - name: Generate github tests summary + if: always() + run: pwsh ./.github/scripts/generate-test-summary.ps1 # ---------------------------------------------------------------- # ETAP 2: Publikacja i weryfikacja (AOT & JIT)