PavanMudigonda / jacoco-reporter

GitHub Action to Publish JaCoCo Format Code Coverage XML and attach it to the Workflow Run as a Check Run. Also can enforce Coverage Quality Gate.
https://linkedin.com/in/PavanMudigonda
MIT License
63 stars 7 forks source link

Should consider checking when $coveredLines is 0 #19

Closed chenggangpro closed 2 years ago

chenggangpro commented 2 years ago

Hi guys,

I'm new here.It seems like a bug as I mentioned below . When $coveredLines is 0, there is no place to check "$coveredLines" . Then it will raise an error about Attempted to divide by zero. I think when $coveredLines is 0 , $coveragePercentage should be zero directly

https://github.com/PavanMudigonda/jacoco-reporter/blob/95a0b976e99043d65782a3a68f3fda0b51dbd5f6/action.ps1#L142

PavanMudigondaTR commented 2 years ago

@chenggangpro

Thanks for reporting. I have fixed it today and it should work for you if ($missedLines -eq 0) { $coveragePercentage = 100 } elseif ($coveredLines -eq 0) { $coveragePercentage = 0 } elseif ($coveredLines -eq 0 -and $missedLines -eq 0) { $coveragePercentage = 0 } else { $coveragePercentage = [math]::Round(100 - (($missedLines / $coveredLines) * 100)) }

PavanMudigonda commented 2 years ago

@chenggangpro

If the fix is working for you hit STAR ⭐ on top right of this repo