From dba3fa39414a6de529ea290619f0ae43a08f2eaa Mon Sep 17 00:00:00 2001 From: Matthew Kelly Date: Wed, 28 Aug 2019 22:01:25 +0100 Subject: [PATCH] #358: Test hooking up coverage --- .github/workflows/ci.yml | 3 +++ pode.build.ps1 | 33 +++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e0b0369d..ef27ac283 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file diff --git a/pode.build.ps1 b/pode.build.ps1 index 4694516aa..1669b093d 100644 --- a/pode.build.ps1 +++ b/pode.build.ps1 @@ -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 @@ -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) { @@ -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' @@ -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 } @@ -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 {