Skip to content

Commit a1e7770

Browse files
committed
[#201] #EXTEND 'assemblyName: DotNet.Testcontainers; function SonarCloud'
{Add Windows test results to SonarCloud.}
1 parent aff55c4 commit a1e7770

File tree

10 files changed

+95
-55
lines changed

10 files changed

+95
-55
lines changed

azure-pipelines.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ pr:
1919

2020
jobs:
2121
# Run Windows build and tests.
22-
- template: template/build.yml
22+
- template: azure/build.yml
2323
parameters:
2424
name: BuildAndTestsOnWindows
2525
displayName: Windows
2626
vmImage: windows-2019
2727
dotNetCoreVersion3: $(dotNetCoreVersion3)
2828
cakeVersion: $(cakeVersion)
29-
testFilter: FullyQualifiedName~DotNet.Testcontainers.Tests.Unit.Windows
29+
testFilter: FullyQualifiedName~DotNet.Testcontainers.Tests.Unit.Containers.Windows
3030

31-
# Run Linux build and tests.
32-
- template: template/build.yml
31+
# Run Unix build and tests.
32+
- template: azure/build.yml
3333
parameters:
3434
name: BuildAndTestsOnUnix
35-
displayName: Linux
35+
displayName: Unix
3636
vmImage: ubuntu-18.04
3737
dotNetCoreVersion3: $(dotNetCoreVersion3)
3838
cakeVersion: $(cakeVersion)
@@ -41,7 +41,7 @@ jobs:
4141
# Run static code analysis and publish artifact.
4242
# Until now, we do not cover Windows only tests.
4343
- ${{ if in(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/heads/develop') }}:
44-
- template: template/publish.yml
44+
- template: azure/publish.yml
4545
parameters:
4646
name: Release
4747
displayName: Release

template/build.yml renamed to azure/build.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ jobs:
1515
inputs:
1616
version: ${{ parameters.dotNetCoreVersion3 }}
1717

18-
- powershell: docker ps -a -q | % { docker rm $_ --force }
19-
displayName: Remove All Orphaned Containers
20-
2118
- powershell: dotnet tool install --tool-path ./tools --version ${{ parameters.cakeVersion }} Cake.Tool
2219
displayName: Setup prerequisites
2320

@@ -27,8 +24,20 @@ jobs:
2724
- powershell: ./tools/dotnet-cake --target=Build
2825
displayName: Build
2926

30-
- powershell: ./tools/dotnet-cake --target=Tests --test-filter="${{ parameters.testFilter }}"
27+
- powershell: ./tools/dotnet-cake --target=Tests --test-filter='${{ parameters.testFilter }}'
3128
displayName: Tests
3229

3330
- powershell: Get-ChildItem -Path . -Include *.log -Recurse | % { Get-Content -Path $_.FullName }
3431
displayName: Logs
32+
33+
- powershell: Get-ChildItem -Path 'test-coverage' -Filter *.xml | Rename-Item -NewName { $_.Name -Replace 'coverage.netcoreapp3.1', '${{ parameters.displayName }}'.ToLower() }
34+
displayName: Rename Test And Coverage Results
35+
36+
- powershell: "@('test-results', 'test-coverage') | % { Copy-Item -Path $_ -Destination '$(Build.ArtifactStagingDirectory)' -Recurse }"
37+
displayName: Copy Test And Coverage Results To Staging Directory
38+
39+
- task: PublishPipelineArtifact@1
40+
displayName: Publish Test And Coverage Results
41+
inputs:
42+
targetPath: $(Build.ArtifactStagingDirectory)
43+
artifactName: ${{ parameters.displayName }}.TestAndCoverageResults

azure/publish.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
jobs:
2+
- job: ${{ parameters.name }}
3+
displayName: CI build for ${{ parameters.displayName }}
4+
5+
pool:
6+
vmImage: ${{ parameters.vmImage }}
7+
8+
dependsOn:
9+
- BuildAndTestsOnWindows
10+
- BuildAndTestsOnUnix
11+
12+
steps:
13+
- checkout: self
14+
clean: true
15+
lfs: true
16+
17+
- task: DownloadPipelineArtifact@2
18+
inputs:
19+
source: current
20+
artifact: Unix.TestAndCoverageResults
21+
path: $(Build.SourcesDirectory)
22+
23+
- task: DownloadPipelineArtifact@2
24+
inputs:
25+
source: current
26+
artifact: Windows.TestAndCoverageResults
27+
path: $(Build.SourcesDirectory)
28+
29+
- task: UseDotNet@2
30+
displayName: Use .NET Core SDK ${{ parameters.dotNetCoreVersion3 }}
31+
inputs:
32+
version: ${{ parameters.dotNetCoreVersion3 }}
33+
34+
- task: UseDotNet@2
35+
displayName: Use .NET Core SDK ${{ parameters.dotNetCoreVersion2 }}
36+
inputs:
37+
version: ${{ parameters.dotNetCoreVersion2 }}
38+
39+
- powershell: Get-ChildItem -Path 'test-coverage' -Filter *.xml | % { (Get-Content $_) -Replace '[A-Za-z0-9:\\\/]+src', '$(Build.SourcesDirectory)/src' | Set-Content $_ }
40+
displayName: Fix Absolute Code Coverage Paths
41+
42+
- powershell: dotnet tool install --tool-path ./tools --version ${{ parameters.cakeVersion }} Cake.Tool
43+
displayName: Setup prerequisites
44+
45+
- powershell: ./tools/dotnet-cake --target=Restore-NuGet-Packages
46+
displayName: Prepare
47+
48+
- powershell: |
49+
$env:SONARCLOUD_TOKEN = "$(sonarcloud.token)"
50+
./tools/dotnet-cake --target=Sonar-Begin
51+
displayName: Sonar Begin
52+
53+
- powershell: ./tools/dotnet-cake --target=Build
54+
displayName: Build
55+
56+
- powershell: |
57+
$env:SONARCLOUD_TOKEN = "$(sonarcloud.token)"
58+
./tools/dotnet-cake --target=Sonar-End
59+
displayName: Sonar End
60+
61+
- powershell: |
62+
$env:FEED_APIKEY = "$(feed.apikey)"
63+
./tools/dotnet-cake --target=Publish
64+
displayName: Publish

build.cake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ Task("Publish-NuGet-Packages")
144144
{
145145
foreach(var package in GetFiles($"{param.Paths.Directories.NugetRoot}/*.(nupkg|snupkgs)"))
146146
{
147-
NuGetPush(package, new NuGetPushSettings
147+
DotNetCoreNuGetPush(package.FullPath, new DotNetCoreNuGetPushSettings
148148
{
149-
ToolPath = "./tools/nuget.exe",
150149
Source = param.NuGetCredentials.Source,
151150
ApiKey = param.NuGetCredentials.ApiKey
152151
});

src/DotNet.Testcontainers.Tests/Unit/Containers/Unix/MessageBroker/RabbitMqTestcontainerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace DotNet.Testcontainers.Tests.Unit.Containers.Linux.MessageBroker
1+
namespace DotNet.Testcontainers.Tests.Unit.Containers.Unix.MessageBroker
22
{
33
using System;
44
using System.Threading.Tasks;

src/DotNet.Testcontainers.Tests/Unit/Containers/Unix/TestcontainersContainerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace DotNet.Testcontainers.Tests.Unit.Containers.Linux
1+
namespace DotNet.Testcontainers.Tests.Unit.Containers.Unix
22
{
33
using System;
44
using System.IO;

src/DotNet.Testcontainers.Tests/Unit/Containers/Windows/TestcontainersContainerTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace DotNet.Testcontainers.Tests.Unit.Containers.Windows
55
using DotNet.Testcontainers.Containers;
66
using DotNet.Testcontainers.Containers.Builders;
77
using DotNet.Testcontainers.Containers.Modules;
8+
using DotNet.Testcontainers.Containers.WaitStrategies;
89
using Xunit;
910

1011
public static class TestcontainersContainerTest
@@ -18,11 +19,12 @@ public async Task IsWindowsEngineEnabled()
1819
}
1920

2021
[IgnoreOnLinuxEngine]
21-
public async Task Disposable()
22+
public async Task SafeDisposable()
2223
{
2324
// Given
2425
var testcontainersBuilder = new TestcontainersBuilder<TestcontainersContainer>()
25-
.WithImage("mcr.microsoft.com/windows/nanoserver:1809");
26+
.WithImage("mcr.microsoft.com/windows/nanoserver:1809")
27+
.WithWaitStrategy(Wait.ForWindowsContainer());
2628

2729
// When
2830
// Then

src/DotNet.Testcontainers/Containers/OutputConsumers/Common/DoNotConsumeStdoutOrStderr.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ internal sealed class DoNotConsumeStdoutOrStderr : IOutputConsumer
1313

1414
public void Dispose()
1515
{
16+
this.Stdout.Dispose();
17+
this.Stderr.Dispose();
1618
}
1719
}
1820
}

src/Shared.msbuild

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Company>Andre Hofmeister</Company>
99
<Description>A lightweight library to run tests with throwaway instances of Docker containers.</Description>
1010
<Summary>.NET Testcontainers makes it easy to run tests with Docker containers. Create reliable and fast environments within seconds and throw them away if not needed anymore.</Summary>
11+
<PackageIcon>DotNet.Testcontainers.png</PackageIcon>
1112
<PackageIconUrl>https://github.com/HofmeisterAn/dotnet-testcontainers/raw/develop/docs/DotNet.Testcontainers.png</PackageIconUrl>
1213
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1314
<PackageProjectUrl>https://github.com/HofmeisterAn/dotnet-testcontainers</PackageProjectUrl>
@@ -32,6 +33,7 @@
3233
<!-- Global solution information -->
3334
<ItemGroup>
3435
<Compile Include="$(MSBuildThisFileDirectory)SolutionInfo.cs" />
35-
<None Include="../../LICENSE" Pack="true" PackagePath=""/>
36+
<None Include="$(MSBuildThisFileDirectory)../LICENSE" Pack="true" PackagePath="" />
37+
<None Include="$(MSBuildThisFileDirectory)../docs/DotNet.Testcontainers.png" Pack="true" PackagePath="" />
3638
</ItemGroup>
3739
</Project>

template/publish.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)