Skip to content

Commit

Permalink
#358: Test hooking up coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Badgerati committed Aug 28, 2019
1 parent dda3518 commit dba3fa3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -28,4 +28,7 @@ jobs:

- name: Run Pester Tests
shell: pwsh
env:
PODE_COVERALLS_TOKEN: ${{ secrets.PODE_COVERALLS_TOKEN }}
PODE_RUN_CODE_COVERAGE: ${{ matrix.os == 'windows-latest' }}
run: Invoke-Build Test
33 changes: 27 additions & 6 deletions pode.build.ps1
Expand Up @@ -32,6 +32,16 @@ function Test-PodeBuildIsAppVeyor
return (![string]::IsNullOrWhiteSpace($env:APPVEYOR_JOB_ID))
}

function Test-PodeBuildIsGitHub
{
return (![string]::IsNullOrWhiteSpace($env:GITHUB_REF))
}

function Test-PodeBuildCanCodeCoverage
{
return ((Test-PodeBuildIsAppVeyor) -or (@('1', 'true') -icontains $env:PODE_RUN_CODE_COVERAGE))
}

function Test-PodeBuildCommand($cmd)
{
$path = $null
Expand All @@ -46,6 +56,17 @@ function Test-PodeBuildCommand($cmd)
return (![string]::IsNullOrWhiteSpace($path))
}

function Get-PodeBuildBranch
{
if (Test-PodeBuildIsAppVeyor) {
return $env:APPVEYOR_REPO_BRANCH
}

if (Test-PodeBuildIsGitHub) {
return $env:GITHUB_REF
}
}

function Invoke-PodeBuildInstall($name, $version)
{
if (Test-PodeBuildIsWindows) {
Expand Down Expand Up @@ -123,7 +144,7 @@ task TestDeps {
}

# install coveralls
if (Test-PodeBuildIsAppVeyor)
if (Test-PodeBuildCanCodeCoverage)
{
if (((Get-Module -ListAvailable coveralls) | Where-Object { $_.Version -ieq $Versions.Coveralls }) -eq $null) {
Write-Host 'Installing Coveralls'
Expand Down Expand Up @@ -183,8 +204,8 @@ task Test TestDeps, {

$Script:TestResultFile = "$($pwd)/TestResults.xml"

# if appveyor, run code coverage
if (Test-PodeBuildIsAppVeyor) {
# if appveyor or github, run code coverage
if (Test-PodeBuildCanCodeCoverage) {
$srcFiles = (Get-ChildItem "$($pwd)/src/*.ps1" -Recurse -Force).FullName
$Script:TestStatus = Invoke-Pester './tests/unit' -OutputFormat NUnitXml -OutputFile $TestResultFile -CodeCoverage $srcFiles -PassThru
}
Expand All @@ -207,10 +228,10 @@ task PushAppVeyorTests -If (Test-PodeBuildIsAppVeyor) {
Push-AppveyorArtifact $TestResultFile
}

# Synopsis: If AppyVeyor, push code coverage stats
task PushCodeCoverage -If (Test-PodeBuildIsAppVeyor) {
# Synopsis: If AppyVeyor or GitHub, push code coverage stats
task PushCodeCoverage -If (Test-PodeBuildCanCodeCoverage) {
try {
$coverage = Format-Coverage -PesterResults $Script:TestStatus -CoverallsApiToken $env:PODE_COVERALLS_TOKEN -RootFolder $pwd -BranchName $ENV:APPVEYOR_REPO_BRANCH
$coverage = Format-Coverage -PesterResults $Script:TestStatus -CoverallsApiToken $env:PODE_COVERALLS_TOKEN -RootFolder $pwd -BranchName (Get-PodeBuildBranch)
Publish-Coverage -Coverage $coverage
}
catch {
Expand Down

0 comments on commit dba3fa3

Please sign in to comment.