|
| 1 | +param( |
| 2 | + [Parameter(Mandatory = $true)] |
| 3 | + [string]$Database, |
| 4 | + [Parameter(Mandatory = $true)] |
| 5 | + [string]$SqlInstance, |
| 6 | + [string]$Package = "GOEddie.SQLCover", |
| 7 | + [Parameter(Mandatory = $true)] |
| 8 | + [string]$OutputFile |
| 9 | +) |
| 10 | + |
| 11 | +if ($Env:RUNNER_OS -ne "Windows") { |
| 12 | + Write-Error "This action only supported on Windows runners." -ErrorAction "Stop" |
| 13 | +} |
| 14 | + |
| 15 | +# Install SQLCover |
| 16 | +Write-Output "Installing SQLCover." |
| 17 | +$null = Install-Package $Package -Force -Scope "CurrentUser" |
| 18 | +$NugetPath = (Get-Package $Package).Source | Convert-Path |
| 19 | +$SQLCoverRoot = Split-Path $NugetPath |
| 20 | +$SQLCoverDllPath = Join-Path $SQLCoverRoot "lib\SQLCover.dll" |
| 21 | +Add-Type -Path $SQLCoverDllPath |
| 22 | + |
| 23 | +$connString = "server=$SqlInstance;Trusted_Connection=yes" |
| 24 | +$sqlCover = New-Object SQLCover.CodeCoverage($connString, $Database) |
| 25 | +$null = $sqlCover.Start() |
| 26 | + |
| 27 | +# Run tests |
| 28 | +Invoke-Pester -Path ".\tests\*" |
| 29 | + |
| 30 | +# Stop |
| 31 | +Write-Output "Stopping SQL Cover." |
| 32 | +$coverageResults = $sqlCover.Stop() |
| 33 | + |
| 34 | +# Save results |
| 35 | +[xml]$coberturaXml = $coverageResults.Cobertura() |
| 36 | +$OutputFullPath = Join-Path -Path "." -ChildPath $OutputFile |
| 37 | +Write-Output "Saving Cobertura report to $OutputFullPath" |
| 38 | + |
| 39 | +# Fix missing filename with best-effort value |
| 40 | +# https://github.com/GoEddie/SQLCover/issues/79 |
| 41 | +foreach ($class in $coberturaXml.coverage.packages.package.classes.class) { |
| 42 | + $class.filename = $class.Name |
| 43 | +} |
| 44 | +$coberturaXml.Save($OutputFullPath) |
| 45 | + |
| 46 | +# HTML artifact |
| 47 | +$HtmlFullPath = Join-Path -Path "." -ChildPath "coverage.html" |
| 48 | +Write-Output "Saving HTML report to $HtmlFullPath" |
| 49 | +Set-Content -Path $HtmlFullPath -Value $coverageResults.Html2() -Force |
0 commit comments