From 661d252c5e5f446873b9755ab08a8503c547500b Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Mon, 23 Dec 2019 00:00:00 +0800 Subject: [PATCH] Collect code coverage, Stage 1 --- .config/dotnet-tools.json | 18 ++++++++ Directory.Build.targets | 91 ++++++++++++++++++++++++++++++++++++++- azure-pipelines.yml | 15 +++++-- 3 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 .config/dotnet-tools.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 000000000..efea27171 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,18 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "coverlet.console": { + "version": "1.6.0", + "commands": [ + "coverlet" + ] + }, + "powershell": { + "version": "6.2.3", + "commands": [ + "pwsh" + ] + } + } +} \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets index 3b02169fa..4141bd922 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,4 +1,93 @@ + + + cobertura + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Log.LogMessage(MessageImportance.High, PipeName); + Log.LogMessage(MessageImportance.High, "1"); + using var coverlet = Process.Start( + @"$(DotNetTool)", + $@"tool run coverlet ""{TestAssembly}"" " + + @"--format $(CoverageFormat) " + + @"--target ""$(DotNetTool)"" " + + @"--targetargs ""tool run pwsh " + + $"$server = [System.IO.Pipes.NamedPipeServerStream]::new('{PipeName}');" + + "$server.WaitForConnection();" + + "$server.Disconnect();" + + "$server.WaitForConnection();" + + "$server.Disconnect();" + + @""""); + CoverletId = coverlet.Id; + Log.LogMessage(MessageImportance.High, "2"); + + using var client = new NamedPipeClientStream(PipeName); + Log.LogMessage(MessageImportance.High, "3"); + client.Connect(); + Log.LogMessage(MessageImportance.High, "4"); + + + + + + + + + + + + + + + + + Log.LogMessage(MessageImportance.High, PipeName); + Log.LogMessage(MessageImportance.High, "5"); + using var client = new NamedPipeClientStream(PipeName); + Log.LogMessage(MessageImportance.High, "6"); + client.Connect(); + + Log.LogMessage(MessageImportance.High, "7"); + using var coverlet = Process.GetProcessById(CoverletId); + coverlet.WaitForExit(); + Log.LogMessage(MessageImportance.High, "8"); + + + + + - \ No newline at end of file + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 033beedf8..1ef68e700 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -57,11 +57,15 @@ jobs: - task: PublishBuildArtifacts@1 displayName: Publish Packages inputs: - PathtoPublish: '$(Build.SourcesDirectory)/artifacts/packages/$(_BuildConfig)' - PublishLocation: Container - ArtifactName: Packages_$(Agent.Os)_$(Agent.JobName) + pathtoPublish: '$(Build.SourcesDirectory)/artifacts/packages/$(_BuildConfig)' + artifactName: Packages_$(Agent.Os)_$(Agent.JobName) continueOnError: true condition: always() + - task: PublishCodeCoverageResults@1 + displayName: Publish Code Coverage + inputs: + codeCoverageTool: cobertura + summaryFileLocation: '$(Build.SourcesDirectory)/src/*/coverage.cobertura.xml' - job: Linux pool: name: NetCorePublic-Pool @@ -79,3 +83,8 @@ jobs: name: Build displayName: Build condition: succeeded() + - task: PublishCodeCoverageResults@1 + displayName: Publish Code Coverage + inputs: + codeCoverageTool: cobertura + summaryFileLocation: '$(Build.SourcesDirectory)/src/*/coverage.cobertura.xml'