Skip to content

Commit

Permalink
🚀 Add Code Coverage Reports (#259)
Browse files Browse the repository at this point in the history
* 🚀 Add code coverage generation to build

* 🚀 Update build steps to publish code coverage

🚧 Adjust yaml step

🚧 get all script files for coverage

🚀 Exclude koans files from code coverage

🚀 Add report generation to code cov

🚀 Add variable for source folders

* 🚀 Tidy up yaml

* 📝 Add coverage badge to readme
  • Loading branch information
vexx32 committed Sep 25, 2019
1 parent db83193 commit 11d0143
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
21 changes: 15 additions & 6 deletions Build/Psake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Properties {
$Timestamp = Get-Date -Format "yyyyMMdd-hhmmss"
$PSVersion = $PSVersionTable.PSVersion
$TestFile = "PS${PSVersion}_${TimeStamp}_PSKoans.TestResults.xml"
$CodeCoverageFile = "PS${PSVersion}_${TimeStamp}_PSKoans.CodeCoverage.xml"
$ModuleFolders = @(
Get-ChildItem -Path "$ProjectRoot/PSKoans" -Directory -Recurse |
Where-Object { 'Koans' -notin $_.Parent.Name, $_.Parent.Parent.Name }
).FullName -join ';'
$Lines = '-' * 70

$Continue = @{
Expand Down Expand Up @@ -48,16 +53,20 @@ STATUS: Testing with PowerShell $PSVersion
$env:PSModulePath = '{0}{1}{2}' -f $ProjectRoot, ([System.IO.Path]::PathSeparator), $env:PSModulePath
Import-Module 'PSKoans'

# Tell Azure where the test results file will be
# Tell Azure where the test results & code coverage files will be
Write-Host "##vso[task.setvariable variable=TestResults]$TestFile"
Write-Host "##vso[task.setvariable variable=CodeCoverageFile]$CodeCoverageFile"
Write-Host "##vso[task.setvariable variable=SourceFolders]$ProjectRoot/PSKoans;$ModuleFolders"

# Gather test results. Store them in a variable and file
$PesterParams = @{
Path = "$ProjectRoot/Tests"
PassThru = $true
OutputFormat = 'NUnitXml'
OutputFile = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$TestFile"
Show = "Header", "Failed", "Summary"
Path = "$ProjectRoot/Tests"
PassThru = $true
OutputFormat = 'NUnitXml'
OutputFile = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$TestFile"
Show = "Header", "Failed", "Summary"
CodeCoverage = (Get-ChildItem -Recurse -Path "$ProjectRoot/PSKoans" -Filter '*.ps*1' -Exclude '*.Koans.ps1').FullName
CodeCoverageOutputFile = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/$CodeCoverageFile"
}
$TestResults = Invoke-Pester @PesterParams

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# PowerShell Koans

| [![PSKoans Logo](./logo-128px.png)](./logo.svg) |
| :---------------------------------------------: |
| [![Build Status][build-badge]][build-link] |
| [![PSKoans Logo](./logo-128px.png)](./logo.svg) |
| :---------------------------------------------------------------------------------------------: |
| [![Build Status][build-badge]][build-link]<br/>[![Coverage Status][coverage-badge]][build-link] |

## About the Author

Expand Down Expand Up @@ -178,7 +178,8 @@ Good luck!

## Contributing

If you would like to contribute to PSKoans, please check out the [Contributing](https://github.com/vexx32/PSKoans/blob/master/CONTRIBUTING.md) document.
If you would like to contribute to PSKoans, please check out the [Contributing](https://github.com/vexx32/PSKoans/blob/master/CONTRIBUTING.md) document.

[build-badge]: https://dev.azure.com/SallowCode/PSKoans/_apis/build/status/PSKoans%20CI
[build-link]: https://dev.azure.com/SallowCode/PSKoans/_build/latest?definitionId=1
[coverage-badge]: https://img.shields.io/azure-devops/coverage/SallowCode/PSKoans/1
11 changes: 11 additions & 0 deletions templates/build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ steps:
- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: succeededOrFailed()

inputs:
testResultsFormat: NUnit
testResultsFiles: '$(TestResults)'
searchFolder: '$(Build.ArtifactStagingDirectory)'
mergeTestResults: true

- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
condition: succeededOrFailed()

inputs:
codeCoverageTool: JaCoCo
summaryFileLocation: '$(Build.ArtifactStagingDirectory)/$(CodeCoverageFile)'
#reportDirectory: '$(Build.ArtifactStagingDirectory)'
pathToSources: '$(SourceFolders)'

0 comments on commit 11d0143

Please sign in to comment.