Skip to content

Commit 8141e45

Browse files
authored
Update CI/CD pipeline template and build script (#356)
* Update CI/CD pipeline template and build script * Update SDK to 5.0 and install 3.1 runtime * Update ubuntu image to 20.04, 16.04 is being deprecated 6 days from now * Add dotnet 2.1 runtime * Update target frameworks, use common.props on .csproj, fix APIApprover
1 parent 1c883b2 commit 8141e45

File tree

26 files changed

+192
-131
lines changed

26 files changed

+192
-131
lines changed

Hocon.sln

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Global
130130
{1437D06E-EA95-4599-A6D0-80C1EC774A5A} = {C3695FA9-B189-4881-864A-8377EE987B74}
131131
{7A497666-0799-4165-88A4-1DB37DB65A8D} = {C3695FA9-B189-4881-864A-8377EE987B74}
132132
{181D6251-3B11-4F2D-92E5-631C99D9F791} = {C3695FA9-B189-4881-864A-8377EE987B74}
133+
{6D1D4813-7AB6-4268-A9DF-627A60E08FB1} = {C3695FA9-B189-4881-864A-8377EE987B74}
133134
EndGlobalSection
134135
GlobalSection(ExtensibilityGlobals) = postSolution
135136
SolutionGuid = {557DB117-9178-4935-B327-3017C53186FE}

build-system/azure-pipeline.template.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ jobs:
1515
pool:
1616
vmImage: ${{ parameters.vmImage }}
1717
steps:
18+
- task: UseDotNet@2
19+
displayName: 'Use .NET 5 SDK 5.0'
20+
inputs:
21+
version: 5.0.x
22+
- task: UseDotNet@2
23+
displayName: 'Use .NET Core Runtime 3.1'
24+
inputs:
25+
packageType: runtime
26+
version: 3.1.x
27+
- task: UseDotNet@2
28+
displayName: 'Use .NET Core Runtime 2.1'
29+
inputs:
30+
packageType: runtime
31+
version: 2.1.x
1832
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
1933
clean: false # whether to fetch clean each time
2034
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules

build-system/pr-validation.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
parameters:
4646
name: 'linux_tests'
4747
displayName: 'Linux Tests'
48-
vmImage: 'ubuntu-16.04'
48+
vmImage: 'ubuntu-20.04'
4949
scriptFileName: build.sh
5050
scriptArgs: runtests
5151
outputDirectory: 'TestResults'
@@ -54,7 +54,7 @@ jobs:
5454
parameters:
5555
name: 'linux_perf_tests'
5656
displayName: 'Linux Performance Tests'
57-
vmImage: 'ubuntu-16.04'
57+
vmImage: 'ubuntu-20.04'
5858
scriptFileName: build.sh
5959
scriptArgs: nbench
6060
outputDirectory: 'PerfResults'

build.ps1

-43
Original file line numberDiff line numberDiff line change
@@ -46,49 +46,6 @@ if (!(Test-Path $ToolPath)) {
4646
New-Item -Path $ToolPath -Type directory | out-null
4747
}
4848

49-
###########################################################################
50-
# INSTALL .NET CORE CLI
51-
###########################################################################
52-
53-
Function Remove-PathVariable([string]$VariableToRemove)
54-
{
55-
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
56-
if ($path -ne $null)
57-
{
58-
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
59-
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
60-
}
61-
62-
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
63-
if ($path -ne $null)
64-
{
65-
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
66-
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
67-
}
68-
}
69-
70-
# Get .NET Core CLI path if installed.
71-
$FoundDotNetCliVersion = $null;
72-
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
73-
$FoundDotNetCliVersion = dotnet --version;
74-
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
75-
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
76-
}
77-
78-
if($FoundDotNetCliVersion -ne $DotNetVersion) {
79-
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
80-
if (!(Test-Path $InstallPath)) {
81-
mkdir -Force $InstallPath | Out-Null;
82-
}
83-
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
84-
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath -Architecture x64;
85-
86-
Remove-PathVariable "$InstallPath"
87-
$env:PATH = "$InstallPath;$env:PATH"
88-
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
89-
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
90-
}
91-
9249
###########################################################################
9350
# INSTALL NUGET
9451
###########################################################################

build.sh

-18
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ if [ ! -d "$TOOLS_DIR" ]; then
4343
mkdir "$TOOLS_DIR"
4444
fi
4545

46-
###########################################################################
47-
# INSTALL .NET CORE CLI
48-
###########################################################################
49-
50-
echo "Installing .NET CLI..."
51-
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
52-
mkdir "$SCRIPT_DIR/.dotnet"
53-
fi
54-
curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" $DOTNET_INSTALLER_URL
55-
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --channel $DOTNET_CHANNEL --install-dir .dotnet --no-path
56-
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION2 --channel $DOTNET_CHANNEL --install-dir .dotnet --no-path
57-
export PATH="$SCRIPT_DIR/.dotnet":$PATH
58-
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
59-
export DOTNET_CLI_TELEMETRY_OPTOUT=1
60-
chmod -R 0755 ".dotnet"
61-
"$SCRIPT_DIR/.dotnet/dotnet" --info
62-
63-
6446
###########################################################################
6547
# INSTALL NUGET
6648
###########################################################################

src/Hocon.API.Tests/Hocon.API.Tests.csproj

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="..\common.props" />
23

34
<PropertyGroup>
4-
<TargetFramework>net461</TargetFramework>
5-
5+
<TargetFramework>$(NetFrameworkTestVersion)</TargetFramework>
66
<IsPackable>false</IsPackable>
7-
8-
<RootNamespace>Hocon.API.Tests</RootNamespace>
9-
10-
<AssemblyName>Hocon.API.Tests</AssemblyName>
117
</PropertyGroup>
128

139
<ItemGroup>
@@ -33,10 +29,11 @@
3329
</ItemGroup>
3430

3531
<ItemGroup>
32+
<PackageReference Include="DiffPlex" Version="1.7.0" />
3633
<PackageReference Include="ApiApprover" Version="9.3.0" />
37-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
38-
<PackageReference Include="xunit" Version="2.4.1" />
39-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
34+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
35+
<PackageReference Include="xunit" Version="$(XunitVersion)" />
36+
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
4037
<PrivateAssets>all</PrivateAssets>
4138
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4239
</PackageReference>

src/Hocon.API.Tests/HoconAPISpec.cs

+132-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@
1010
using Xunit;
1111
using static PublicApiGenerator.ApiGenerator;
1212
using System;
13+
using System.IO;
1314
using System.Linq;
1415
using System.Runtime.CompilerServices;
16+
using System.Text;
17+
using ApprovalTests.Core;
18+
using ApprovalTests.Reporters;
19+
using ApprovalTests.Reporters.Mac;
20+
using ApprovalUtilities.Utilities;
21+
using DiffPlex;
22+
using DiffPlex.DiffBuilder;
23+
using DiffPlex.DiffBuilder.Model;
24+
using Xunit.Sdk;
25+
using P4MergeReporter = ApprovalTests.Reporters.P4MergeReporter;
26+
using P4MacMergeReporter = ApprovalTests.Reporters.Mac.P4MergeReporter;
1527

1628
namespace Hocon.API.Tests
1729
{
30+
#if(DEBUG)
31+
[UseReporter(typeof(DiffPlexReporter), typeof(CustomDiffReporter), typeof(AllFailingTestsClipboardReporter))]
32+
#else
33+
[UseReporter(typeof(DiffPlexReporter), typeof(CustomDiffReporter))]
34+
#endif
1835
public class HoconAPISpec
1936
{
2037
[Fact]
@@ -55,9 +72,123 @@ static string Filter(string text)
5572
{
5673
Environment.NewLine
5774
}, StringSplitOptions.RemoveEmptyEntries)
58-
.Where(l => !l.StartsWith("[assembly: ReleaseDateAttribute("))
75+
.Where(l => !l.StartsWith("[assembly: ReleaseDateAttribute(") && !l.StartsWith("[assembly: System.Reflection.AssemblyMetadataAttribute"))
5976
.Where(l => !string.IsNullOrWhiteSpace(l))
6077
);
6178
}
6279
}
80+
81+
82+
internal class ApiNotApprovedException : XunitException
83+
{
84+
public ApiNotApprovedException(string message) : base($"Failed API approval. Diff:\n{message}")
85+
{ }
86+
87+
public override string StackTrace { get; } = string.Empty;
88+
}
89+
90+
#region Suppress FrameworkAssertReporter hack
91+
// The built-in FrameworkAssertReporter that is being called inside the DiffReporter class
92+
// is buggy in a CI/CD environment because it is trying to be clever, could not distinguish
93+
// between XUnit and XUnit2, and will throw Null Reference Exception every time it ran.
94+
//
95+
// This is probably fixed in latest version of ApiApprover but we couldn't switch to that
96+
// version because the latest ApiGenerator returns a different API report format.
97+
//
98+
// FIX: This hack removes FrameworkAssertReporter from the possible reporter list and retains
99+
// all of the other reporters in DiffReporter
100+
101+
internal class CustomDiffReporter : FirstWorkingReporter
102+
{
103+
public CustomDiffReporter() : base(
104+
CustomWindowsDiffReporter.Instance,
105+
CustomMacDiffReporter.Instance)
106+
{ }
107+
}
108+
109+
internal class CustomMacDiffReporter : FirstWorkingReporter
110+
{
111+
public static readonly CustomMacDiffReporter Instance = new CustomMacDiffReporter();
112+
public CustomMacDiffReporter()
113+
: base(
114+
115+
BeyondCompareMacReporter.INSTANCE,
116+
DiffMergeReporter.INSTANCE,
117+
KaleidoscopeDiffReporter.INSTANCE,
118+
P4MacMergeReporter.INSTANCE,
119+
KDiff3Reporter.INSTANCE,
120+
TkDiffReporter.INSTANCE,
121+
QuietReporter.INSTANCE)
122+
{ }
123+
124+
public override bool IsWorkingInThisEnvironment(string forFile) => OsUtils.IsUnixOs() && base.IsWorkingInThisEnvironment(forFile);
125+
}
126+
127+
internal class CustomWindowsDiffReporter : FirstWorkingReporter
128+
{
129+
public static readonly CustomWindowsDiffReporter Instance = new CustomWindowsDiffReporter();
130+
public CustomWindowsDiffReporter()
131+
: base(
132+
CodeCompareReporter.INSTANCE,
133+
BeyondCompareReporter.INSTANCE,
134+
TortoiseDiffReporter.INSTANCE,
135+
AraxisMergeReporter.INSTANCE,
136+
P4MergeReporter.INSTANCE,
137+
WinMergeReporter.INSTANCE,
138+
KDiffReporter.INSTANCE,
139+
VisualStudioReporter.INSTANCE,
140+
QuietReporter.INSTANCE)
141+
{ }
142+
143+
public override bool IsWorkingInThisEnvironment(string forFile) => OsUtils.IsWindowsOs() && base.IsWorkingInThisEnvironment(forFile);
144+
}
145+
146+
#endregion
147+
148+
internal class DiffPlexReporter : IApprovalFailureReporter
149+
{
150+
public void Report(string approved, string received)
151+
{
152+
var approvedText = File.ReadAllText(approved);
153+
var receivedText = File.ReadAllText(received);
154+
155+
var diffBuilder = new SideBySideDiffBuilder(new Differ());
156+
var diff = diffBuilder.BuildDiffModel(approvedText, receivedText);
157+
158+
var sb = new StringBuilder()
159+
.AppendLine($"<<<<<<<<< {Path.GetFileName(approved)}")
160+
.AppendDiff(diff.OldText)
161+
.AppendLine("=========")
162+
.AppendDiff(diff.NewText)
163+
.Append($">>>>>>>>> {Path.GetFileName(received)}");
164+
165+
//_out.WriteLine(sb.ToString());
166+
throw new ApiNotApprovedException(sb.ToString());
167+
}
168+
}
169+
170+
internal static class Extensions
171+
{
172+
public static StringBuilder AppendDiff(this StringBuilder output, DiffPaneModel diff)
173+
{
174+
foreach (var line in diff.Lines)
175+
{
176+
switch (line.Type)
177+
{
178+
case ChangeType.Deleted:
179+
output.AppendLine($"[{line.Position:0000}] - {line.Text}");
180+
break;
181+
case ChangeType.Inserted:
182+
output.AppendLine($"[{line.Position:0000}] + {line.Text}");
183+
break;
184+
case ChangeType.Modified:
185+
output.AppendLine($"[{line.Position:0000}] ? {line.Text}");
186+
break;
187+
}
188+
}
189+
190+
return output;
191+
}
192+
193+
}
63194
}

src/Hocon.API.Tests/HoconAPISpecConfig.cs

-12
This file was deleted.

src/Hocon.Benchmarks/Hocon.Benchmarks.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
<Import Project="..\common.props" />
3+
34
<PropertyGroup>
45
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<TargetFramework>$(NetCoreTestVersion)</TargetFramework>
67
<IsPackable>false</IsPackable>
78
</PropertyGroup>
89

src/Hocon.Configuration.Test/Hocon.Configuration.Tests.csproj

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<Import Project="..\common.props" />
33

44
<PropertyGroup>
5-
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
5+
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetCoreTestVersion)</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="FluentAssertions" Version="5.10.3" />
9+
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
11-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
11+
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftVersion)" />
1212
<PackageReference Include="xunit" Version="$(XunitVersion)" />
1313
<DotNetCliToolReference Include="dotnet-xunit" Version="$(XunitCliVersion)" />
1414
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
@@ -24,9 +24,13 @@
2424
<ProjectReference Include="..\Hocon.Configuration\Hocon.Configuration.csproj" />
2525
</ItemGroup>
2626

27-
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
27+
<ItemGroup Condition=" '$(TargetFramework)' == '$(NetFrameworkTestVersion)' ">
2828
<Reference Include="System.Configuration" />
2929
</ItemGroup>
30+
31+
<PropertyGroup Condition=" '$(TargetFramework)' == '$(NetCoreTestVersion)' ">
32+
<DefineConstants>NETCORE</DefineConstants>
33+
</PropertyGroup>
3034

3135
<ItemGroup>
3236
<None Update="app.conf">
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<Import Project="..\common.props" />
43

54
<PropertyGroup>
6-
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks>$(NetFrameworkVersion);$(NetStandardLibVersion)</TargetFrameworks>
76
<GenerateDocumentationFile>true</GenerateDocumentationFile>
87
<RootNamespace>Hocon</RootNamespace>
98
<PackageTags>$(HoconPackageTags)</PackageTags>
@@ -14,14 +13,12 @@
1413
<ProjectReference Include="..\Hocon\Hocon.csproj" />
1514
</ItemGroup>
1615

17-
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
16+
<ItemGroup Condition=" '$(TargetFramework)' == '$(NetFrameworkVersion)' ">
1817
<Reference Include="System.Configuration" />
1918
</ItemGroup>
2019

21-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
22-
<PackageReference Include="System.Configuration.ConfigurationManager">
23-
<Version>4.7.0</Version>
24-
</PackageReference>
20+
<ItemGroup Condition="'$(TargetFramework)' == '$(NetStandardLibVersion)'">
21+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0"/>
2522
</ItemGroup>
2623

2724
</Project>

0 commit comments

Comments
 (0)