RamblingCookieMonster / BuildHelpers

Helper functions for PowerShell CI/CD scenarios
MIT License
215 stars 47 forks source link

Added Set-CodeCoverageBadge function #62

Closed markwragg closed 6 years ago

markwragg commented 6 years ago

Per this blog post:

This PR is to introduce a Set-CodeCoverageBadge function which can be used to update a code coverage badge on your readme.md with the current code coverage percentage result and an associated colour. Example usage in your build pipeline:

$CodeFiles = (Get-ChildItem $ENV:BHModulePath -Recurse -Include "*.psm1","*.ps1").FullName
$TestResults = Invoke-Pester -Path $ProjectRoot\Tests -CodeCoverage $CodeFiles -PassThru

$CoveragePercent = [math]::floor(100 - (($TestResults.CodeCoverage.NumberOfCommandsMissed / $TestResults.CodeCoverage.NumberOfCommandsAnalyzed) * 100))

Set-CodeCoverageBadge -CodeCoverage $CoveragePercent  

I've also added a basic Pester test for this new function.

RamblingCookieMonster commented 6 years ago

Awesome idea! Will try to flip through this at lunch today or tomorrow : D

lipkau commented 6 years ago

I would suggest using CodeCov.io for the badge. Mark Kraus and I am working on this: https://github.com/markekraus/CodeCovIo

However, this introduces 2 dependencies: the module mentioned and the account on the service.

midacts commented 6 years ago

Line 63, is it possible to not hardcoded the Test Results string?

It might be possible to use this for multiple badges:

markwragg commented 6 years ago

I did consider that but it might be tricky to incorporate the variables in that string.

On 18 May 2018, 00:06 +0100, John McCarthy notifications@github.com, wrote:

Line 63, is it possible to not hardcoded the Test Results string? It might be possible to use this for multiple badges:

• Build • Code coverage • Docs • etc

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

midacts commented 6 years ago

Would something like this be acceptable? https://gist.github.com/Midacts/ef0eb1d30f9234c9dd2433a2129187a1

It makes it so:

markwragg commented 6 years ago

@Midacts great idea. I've done a refactor of your version of the function and have renamed it to Set-ShieldsIoBadge as its now a more generic function. I've change the parameter names to match how they are referenced on shields.io: subject, status and color (and i've made it so you can manually specify colour). Also I’ve added a -AsPercentage switch rather than assume people would want all numeric values treated as percentages. Let me know what you think.

RamblingCookieMonster commented 6 years ago

Awesome! Looks good from here - will try to merge this in tonight

Side note! there's no real governance model in place, but essentially if someone adds a file here, I sort of assume they have ownership over it and will tag them if folks open related issues/PRs (until they tell me not to : P)

markwragg commented 6 years ago

That's fine with me :).

On Fri, 18 May 2018 at 16:13, Warren Frame notifications@github.com wrote:

Awesome! Looks good from here - will try to merge this in tonight

Side note! there's no real governance model in place, but essentially if someone adds a file here, I sort of assume they have ownership over it and will tag them if folks open related issues/PRs (until they tell me not to : P)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RamblingCookieMonster/BuildHelpers/pull/62#issuecomment-390239032, or mute the thread https://github.com/notifications/unsubscribe-auth/AGZUFF0hMnDy-CtoQOnatSUyst2oqgD4ks5tzuUZgaJpZM4T93js .

midacts commented 6 years ago

Looks good to me. The aspercentage makes sense.

Thanks for adding this so I can start adding this to our builds.

RamblingCookieMonster commented 6 years ago

Awesome, thanks @markwragg @Midacts : ) merged!