2019-04-18 23:05:15 +03:00
|
|
|
#
|
2019-04-18 23:17:32 +03:00
|
|
|
# Installs and runs Coveralls.exe to upload coverage files to https://coveralls.io/.
|
2019-04-18 23:05:15 +03:00
|
|
|
# Arguments example: -coverallsToken $(Coveralls.Token) -pathToCoverageFiles $(Build.SourcesDirectory)\CodeCoverage
|
|
|
|
#
|
2018-09-28 02:17:28 +03:00
|
|
|
Param(
|
2019-12-11 03:49:36 +03:00
|
|
|
[string]$coverallsToken = '', # This arg will display in the Azure pipeline log. To hide it, pass it as environment var CoverallsToken instead.
|
2019-05-10 04:41:50 +03:00
|
|
|
[string]$pathToCoverageFiles,
|
|
|
|
[string]$serviceName = 'Azure DevOps'
|
2018-09-28 02:17:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
Write-Host Install tools
|
2019-04-12 23:15:40 +03:00
|
|
|
$basePath = (get-item $pathToCoverageFiles ).parent.FullName
|
2022-07-05 21:09:07 +03:00
|
|
|
|
|
|
|
$coverageAnalyzer = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"
|
|
|
|
if (-not (Test-Path $coverageAnalyzer)) {
|
|
|
|
$coverageAnalyzer = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"
|
|
|
|
}
|
|
|
|
|
2022-08-25 00:44:27 +03:00
|
|
|
dotnet tool install coveralls.net --version 4.0.1 --tool-path tools --add-source https://api.nuget.org/v3/index.json
|
2018-09-28 02:17:28 +03:00
|
|
|
$coverageUploader = ".\tools\csmacnz.Coveralls.exe"
|
|
|
|
|
|
|
|
Write-Host "Analyze coverage [$coverageAnalyzer] with args:"
|
2019-04-12 23:15:40 +03:00
|
|
|
$coverageFiles = Get-ChildItem -Path "$pathToCoverageFiles" -Include "*.coverage" -Recurse | Select -Exp FullName
|
2018-09-28 02:17:28 +03:00
|
|
|
$analyzeArgs = @(
|
|
|
|
"analyze",
|
2019-04-12 23:15:40 +03:00
|
|
|
"/output:""$pathToCoverageFiles\coverage.coveragexml"""
|
2018-09-28 02:17:28 +03:00
|
|
|
);
|
|
|
|
$analyzeArgs += $coverageFiles
|
|
|
|
Foreach ($i in $analyzeArgs) { Write-Host " $i" }
|
|
|
|
."$coverageAnalyzer" @analyzeArgs
|
|
|
|
|
2019-12-11 03:49:36 +03:00
|
|
|
# Get $coverallsToken from environment var
|
|
|
|
if ($coverallsToken -eq '') {
|
|
|
|
$coverallsToken = $Env:CoverallsToken;
|
|
|
|
}
|
|
|
|
|
2018-09-28 02:17:28 +03:00
|
|
|
Write-Host "Upload coverage [$coverageUploader] with args"
|
|
|
|
if (Test-Path env:System_PullRequest_SourceBranch) {
|
2019-12-11 03:49:36 +03:00
|
|
|
$branchName = $env:System_PullRequest_SourceBranch -replace "refs/heads/", ""
|
|
|
|
}
|
2018-09-28 02:17:28 +03:00
|
|
|
$uploadArgs = @(
|
|
|
|
"--dynamiccodecoverage",
|
2019-04-12 23:15:40 +03:00
|
|
|
"-i ""$pathToCoverageFiles\coverage.coveragexml""",
|
|
|
|
"-o ""$pathToCoverageFiles\coverage.json"""
|
2018-09-28 02:17:28 +03:00
|
|
|
"--useRelativePaths",
|
2019-04-12 23:15:40 +03:00
|
|
|
"--basePath ""$basePath""",
|
2018-09-28 02:17:28 +03:00
|
|
|
"--repoToken ""$coverallsToken""",
|
|
|
|
"--jobId ""$env:Build_BuildId""",
|
|
|
|
"--commitId ""$env:Build_SourceVersion""",
|
|
|
|
"--commitAuthor ""$env:Build_RequestedFor""",
|
2019-06-29 01:51:06 +03:00
|
|
|
"--commitEmail ""$env:Build_RequestedForEmail """,
|
2019-05-10 04:41:50 +03:00
|
|
|
"--commitMessage ""$env:Build_SourceVersionMessage""",
|
|
|
|
"--serviceName ""$serviceName"""
|
2018-09-28 02:17:28 +03:00
|
|
|
);
|
2019-12-11 03:49:36 +03:00
|
|
|
if (Test-Path env:System_PullRequest_SourceBranch) {
|
2018-09-28 02:17:28 +03:00
|
|
|
$uploadArgs += "--commitBranch ""$($env:System_PullRequest_SourceBranch -replace ""refs/heads/"", """")"""
|
|
|
|
}
|
2019-12-11 03:49:36 +03:00
|
|
|
else {
|
2018-09-28 02:17:28 +03:00
|
|
|
$uploadArgs += "--commitBranch ""$($env:Build_SourceBranch -replace ""refs/heads/"", """")"""
|
|
|
|
}
|
2019-12-11 03:49:36 +03:00
|
|
|
if (Test-Path env:System_PullRequest_PullRequestNumber) {
|
2018-09-28 02:17:28 +03:00
|
|
|
$uploadArgs += "--pullRequest ""$env:System_PullRequest_PullRequestNumber"""
|
|
|
|
}
|
2019-12-11 03:49:36 +03:00
|
|
|
Foreach ($i in $uploadArgs) {
|
|
|
|
if (-not $i.StartsWith("--repoToken")) {
|
|
|
|
Write-Host " $i";
|
|
|
|
} else {
|
|
|
|
Write-Host " --repoToken ******";
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 02:17:28 +03:00
|
|
|
Start-Process $coverageUploader -ArgumentList $uploadArgs -NoNewWindow
|