run_artifacts.ps1 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. if (Test-Path -Path "/home/vsts/work/artifacts/Code Coverage Report_*/summary*/coverage.xml") {
  2. [xml]$MasterXML = Get-Content "/home/vsts/work/artifacts/Code Coverage Report_*/summary*/coverage.xml"
  3. } else {
  4. Write-Host "No code coverage from previous build. Exiting pipeline." -ForegroundColor Red
  5. exit 1
  6. }
  7. [xml]$BranchXML = Get-Content .\coverage.xml
  8. $masterlinerate = [math]::Abs([math]::Round([decimal]$MasterXML.coverage.'line-rate' * 100, 2))
  9. $branchlinerate = [math]::Abs([math]::Round([decimal]$BranchXML.coverage.'line-rate' * 100, 2))
  10. Write-Output "Old line coverage rate: $masterlinerate%"
  11. Write-Output "New line coverage rate: $branchlinerate%"
  12. if ($masterlinerate -eq 0) {
  13. $change = "Infinite"
  14. } else {
  15. $change = [math]::Abs([math]::Round((($branchlinerate - $masterlinerate) / $masterlinerate) * 100, 2))
  16. }
  17. if ($branchlinerate -gt $masterlinerate) {
  18. Write-Host "Code coverage has increased by $change%. Build passed." -ForegroundColor Green
  19. exit 0
  20. } elseif ($branchlinerate -eq $masterlinerate) {
  21. Write-Host "Code coverage has not changed. Build passed." -ForegroundColor Green
  22. exit 0
  23. } else {
  24. Write-Host "Code coverage as decreased by $change%. Code coverage must be greater than or equal to the previous build to pass." -ForegroundColor Red
  25. exit 2
  26. }