Skip to content

Commit e9f75ac

Browse files
jpnurmiFlash0ver
andauthored
test(ci): .NET 5.0 with MSBuild 16 (#4569)
Co-authored-by: Stefan Pölz <38893694+Flash0ver@users.noreply.github.com>
1 parent fc55d48 commit e9f75ac

File tree

6 files changed

+154
-2
lines changed

6 files changed

+154
-2
lines changed

.github/actions/environment/action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ runs:
2424
shell: bash
2525
run: sudo chmod 666 /var/run/docker.sock
2626

27+
# Install old deprecated libssl1 for .NET 5.0 on Linux
28+
- name: Install libssl1 for NET 5.0 on Linux
29+
if: ${{ runner.os == 'Linux' }}
30+
shell: bash
31+
run: sudo ./scripts/install-libssl1.sh
32+
2733
- name: Install Linux ARM 32-bit dependencies
2834
if: ${{ matrix.rid == 'linux-arm' }}
2935
shell: bash
@@ -90,6 +96,13 @@ runs:
9096
global-json-file: global.json
9197
dotnet-version: 8.0.x
9298

99+
# .NET 5.0 does not support ARM64 on macOS
100+
- name: Install .NET 5.0 SDK
101+
if: ${{ runner.os != 'macOS' || runner.arch != 'ARM64' }}
102+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
103+
with:
104+
dotnet-version: 5.0.x
105+
93106
- name: Install .NET Workloads
94107
shell: bash
95108
run: |

.github/workflows/build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ jobs:
297297

298298
- name: Run MSBuild
299299
id: msbuild
300-
run: msbuild Sentry-CI-Build-Windows.slnf -t:Restore,Build -p:Configuration=Release --nologo -v:minimal -flp:logfile=msbuild.log -p:CopyLocalLockFileAssemblies=true -bl:msbuild.binlog
300+
run: msbuild Sentry-CI-Build-Windows.slnf -t:Restore,Build,Pack -p:Configuration=Release --nologo -v:minimal -flp:logfile=msbuild.log -p:CopyLocalLockFileAssemblies=true -bl:msbuild.binlog
301+
302+
- name: Test MSBuild
303+
uses: getsentry/github-workflows/sentry-cli/integration-test/@a5e409bd5bad4c295201cdcfe862b17c50b29ab7 # v2.14.1
304+
with:
305+
path: integration-test/msbuild.Tests.ps1
301306

302307
- name: Upload logs
303308
if: ${{ always() }}

integration-test/common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ BeforeAll {
154154
Push-Location $projectPath
155155
try
156156
{
157-
dotnet restore | ForEach-Object { Write-Host $_ }
157+
dotnet restore /p:CheckEolTargetFramework=false | ForEach-Object { Write-Host $_ }
158158
if ($LASTEXITCODE -ne 0)
159159
{
160160
throw "Failed to restore the test app project."

integration-test/msbuild.Tests.ps1

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# This file contains test cases for https://pester.dev/
2+
Set-StrictMode -Version Latest
3+
$ErrorActionPreference = 'Stop'
4+
. $PSScriptRoot/common.ps1
5+
6+
$IsARM64 = "Arm64".Equals([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString())
7+
8+
# NOTE: These .NET versions are used to build a test app that consumes the Sentry
9+
# .NET SDK, and are not tied to the .NET version used to build the SDK itself.
10+
Describe 'MSBuild app' {
11+
BeforeDiscovery {
12+
$frameworks = @()
13+
14+
# .NET 5.0 does not support ARM64 on macOS
15+
if (-not $IsMacOS -or -not $IsARM64)
16+
{
17+
$frameworks += @{
18+
framework = 'net5.0'
19+
sdk = '5.0.400'
20+
# NuGet 5 does not support packageSourceMapping
21+
config = "$PSScriptRoot\nuget5.config"
22+
}
23+
}
24+
25+
$frameworks += @(
26+
@{ framework = 'net8.0'; sdk = '8.0.400' },
27+
@{ framework = 'net9.0'; sdk = '9.0.300' }
28+
)
29+
}
30+
31+
Context '(<framework>)' -ForEach $frameworks {
32+
BeforeEach {
33+
Write-Host "::group::Create msbuild-app"
34+
dotnet new console --no-restore --output msbuild-app --framework $framework | ForEach-Object { Write-Host $_ }
35+
$LASTEXITCODE | Should -Be 0
36+
AddPackageReference msbuild-app Sentry
37+
Push-Location msbuild-app
38+
@'
39+
using System.Runtime.InteropServices;
40+
using Sentry;
41+
42+
SentrySdk.Init(options =>
43+
{
44+
options.Dsn = args[0];
45+
options.Debug = true;
46+
});
47+
48+
SentrySdk.CaptureMessage($"Hello from MSBuild app");
49+
'@ | Out-File Program.cs
50+
Write-Host "::endgroup::"
51+
52+
Write-Host "::group::Setup .NET SDK"
53+
if (Test-Path variable:sdk)
54+
{
55+
# Pin to a specific SDK version to use MSBuild from that version
56+
@"
57+
{
58+
"sdk": {
59+
"version": "$sdk",
60+
"rollForward": "latestFeature"
61+
}
62+
}
63+
"@ | Out-File global.json
64+
}
65+
Write-Host "Using .NET SDK: $(dotnet --version)"
66+
Write-Host "Using MSBuild version: $(dotnet msbuild -version)"
67+
Write-Host "::endgroup::"
68+
}
69+
70+
AfterEach {
71+
Pop-Location
72+
Remove-Item msbuild-app -Recurse -Force -ErrorAction SilentlyContinue
73+
}
74+
75+
It 'builds without warnings and is able to capture a message' {
76+
Write-Host "::group::Restore packages"
77+
if (!(Test-Path variable:config))
78+
{
79+
$config = "$PSScriptRoot/nuget.config"
80+
}
81+
dotnet restore msbuild-app.csproj --configfile $config -p:CheckEolTargetFramework=false | ForEach-Object { Write-Host $_ }
82+
$LASTEXITCODE | Should -Be 0
83+
Write-Host "::endgroup::"
84+
85+
# TODO: pass -p:TreatWarningsAsErrors=true after #4554 is fixed
86+
dotnet msbuild msbuild-app.csproj -t:Build -p:Configuration=Release -p:TreatWarningsAsErrors=false | ForEach-Object { Write-Host $_ }
87+
$LASTEXITCODE | Should -Be 0
88+
89+
Write-Host "::group::Run msbuild-app"
90+
$result = Invoke-SentryServer {
91+
param([string]$url)
92+
$dsn = $url.Replace('http://', 'http://key@') + '/0'
93+
dotnet msbuild msbuild-app.csproj -t:Run -p:Configuration=Release -p:RunArguments=$dsn | ForEach-Object { Write-Host $_ }
94+
$LASTEXITCODE | Should -Be 0
95+
}
96+
$result.HasErrors() | Should -BeFalse
97+
$result.Envelopes() | Should -AnyElementMatch "`"message`":`"Hello from MSBuild app`""
98+
Write-Host "::endgroup::"
99+
}
100+
}
101+
}

integration-test/nuget5.config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- nuget5.config is meant for testing with .NET 5.0 / NuGet 5. It is otherwise same as
3+
nuget.config but without <packageSourceMapping> which was added in .NET 6.0 / NuGet 6
4+
https://learn.microsoft.com/en-us/nuget/consume-packages/package-source-mapping -->
5+
<configuration>
6+
<packageSources>
7+
<clear />
8+
<add key="integration-test" value="./packages" />
9+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
10+
</packageSources>
11+
</configuration>

scripts/install-libssl1.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Install old deprecated libssl 1.x for .NET 5.0 on Linux to avoid:
5+
# Error: 'No usable version of libssl was found'
6+
7+
if apk --version >/dev/null 2>&1; then
8+
# Alpine Linux: openssl1.1-compat from the community repo
9+
apk add --repository=https://dl-cdn.alpinelinux.org/alpine/v3.18/community openssl1.1-compat
10+
elif dpkg --version >/dev/null 2>&1; then
11+
# Ubuntu: libssl1 from focal-security
12+
# https://github.com/actions/runner-images/blob/d43555be6577f2ac4e4f78bf683c520687891e1b/images/ubuntu/scripts/build/install-sqlpackage.sh#L11-L21
13+
if [ "$(dpkg --print-architecture)" = "arm64" ]; then
14+
echo "deb http://ports.ubuntu.com/ubuntu-ports focal-security main" | tee /etc/apt/sources.list.d/focal-security.list
15+
else
16+
echo "deb http://security.ubuntu.com/ubuntu focal-security main" | tee /etc/apt/sources.list.d/focal-security.list
17+
fi
18+
apt-get update
19+
apt-get install -y --no-install-recommends libssl1.1
20+
rm /etc/apt/sources.list.d/focal-security.list
21+
apt-get update
22+
fi

0 commit comments

Comments
 (0)