Skip to content

Commit 0718a1b

Browse files
authored
Merge pull request #175 from nblumhardt/net90-actions
Switch to GitHub Actions build, add .NET 9 target
2 parents c0285b2 + 9b82ffb commit 0718a1b

File tree

12 files changed

+148
-75
lines changed

12 files changed

+148
-75
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# If this file is renamed, the incrementing run attempt number will be reset.
2+
3+
name: CI
4+
5+
on:
6+
push:
7+
branches: [ "dev", "main" ]
8+
pull_request:
9+
branches: [ "dev", "main" ]
10+
11+
env:
12+
CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
13+
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
14+
15+
jobs:
16+
build:
17+
18+
# The build must run on Windows so that .NET Framework targets can be built and tested.
19+
runs-on: windows-latest
20+
21+
permissions:
22+
contents: write
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Setup
27+
uses: actions/setup-dotnet@v4
28+
with:
29+
dotnet-version: 9.0.x
30+
- name: Compute build number
31+
shell: bash
32+
run: |
33+
echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+2300))" >> $GITHUB_ENV
34+
- name: Build and Publish
35+
env:
36+
DOTNET_CLI_TELEMETRY_OPTOUT: true
37+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
38+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
shell: pwsh
40+
run: |
41+
./Build.ps1

Build.ps1

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,79 @@
1+
Write-Output "build: Tool versions follow"
2+
3+
dotnet --version
4+
dotnet --list-sdks
5+
16
Write-Output "build: Build started"
27

38
Push-Location $PSScriptRoot
9+
try {
10+
if(Test-Path .\artifacts) {
11+
Write-Output "build: Cleaning ./artifacts"
12+
Remove-Item ./artifacts -Force -Recurse
13+
}
414

5-
if(Test-Path .\artifacts) {
6-
Write-Output "build: Cleaning ./artifacts"
7-
Remove-Item ./artifacts -Force -Recurse
8-
}
15+
& dotnet restore --no-cache
916

10-
& dotnet restore --no-cache
17+
$dbp = [Xml] (Get-Content .\Directory.Version.props)
18+
$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix
1119

12-
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
13-
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
14-
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
20+
Write-Output "build: Package version prefix is $versionPrefix"
1521

16-
Write-Output "build: Package version suffix is $suffix"
22+
$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
23+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER];
24+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"]
25+
$commitHash = $(git rev-parse --short HEAD)
26+
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
1727

18-
foreach ($src in Get-ChildItem src/*) {
19-
Push-Location $src
28+
Write-Output "build: Package version suffix is $suffix"
29+
Write-Output "build: Build version suffix is $buildSuffix"
2030

21-
Write-Output "build: Packaging project in $src"
31+
& dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
32+
if($LASTEXITCODE -ne 0) { throw "Build failed" }
2233

23-
if ($suffix) {
24-
& dotnet pack -c Release --include-source -o ../../artifacts --version-suffix=$suffix
25-
} else {
26-
& dotnet pack -c Release --include-source -o ../../artifacts
34+
foreach ($src in Get-ChildItem src/*) {
35+
Push-Location $src
36+
37+
Write-Output "build: Packaging project in $src"
38+
39+
if ($suffix) {
40+
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix
41+
} else {
42+
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts
43+
}
44+
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
45+
46+
Pop-Location
2747
}
28-
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
2948

30-
Pop-Location
31-
}
49+
foreach ($test in Get-ChildItem test/*.Tests) {
50+
Push-Location $test
51+
52+
Write-Output "build: Testing project in $test"
53+
54+
& dotnet test -c Release --no-build --no-restore
55+
if($LASTEXITCODE -ne 0) { throw "Testing failed" }
56+
57+
Pop-Location
58+
}
59+
60+
if ($env:NUGET_API_KEY) {
61+
# GitHub Actions will only supply this to branch builds and not PRs. We publish
62+
# builds from any branch this action targets (i.e. main and dev).
3263

33-
foreach ($test in Get-ChildItem test/*.Tests) {
34-
Push-Location $test
64+
Write-Output "build: Publishing NuGet packages"
3565

36-
Write-Output "build: Testing project in $test"
66+
foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
67+
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
68+
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
69+
}
3770

38-
& dotnet test -c Release
39-
if($LASTEXITCODE -ne 0) { throw "Testing failed" }
71+
if (!($suffix)) {
72+
Write-Output "build: Creating release for version $versionPrefix"
4073

74+
iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
75+
}
76+
}
77+
} finally {
4178
Pop-Location
4279
}
43-
44-
Pop-Location

Directory.Build.props

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
<Project>
2+
<!-- Properties in this file are expected to be identical for all Serilog organization projects. If
3+
a property value is project-specific, please record it in the CSPROJ file instead. -->
4+
<Import Project="$(MSBuildThisFileDirectory)Directory.Version.props" />
25
<PropertyGroup>
36
<LangVersion>latest</LangVersion>
47
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
5-
<SignAssembly>true</SignAssembly>
8+
<!-- The condition is required to support BenchmarkDotNet -->
9+
<SignAssembly Condition="Exists('$(MSBuildThisFileDirectory)assets/Serilog.snk')">true</SignAssembly>
610
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)assets/Serilog.snk</AssemblyOriginatorKeyFile>
711
<CheckEolTargetFramework>false</CheckEolTargetFramework>
812
<Nullable>enable</Nullable>
913
<ImplicitUsings>enable</ImplicitUsings>
14+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
16+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
17+
<IncludeSymbols>true</IncludeSymbols>
18+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1019
</PropertyGroup>
1120
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
1221
<Reference Include="System" />
1322
<Reference Include="System.Core" />
1423
<Reference Include="Microsoft.CSharp" />
1524
</ItemGroup>
16-
</Project>
25+
</Project>

Directory.Version.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<VersionPrefix>4.2.0</VersionPrefix>
4+
</PropertyGroup>
5+
</Project>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Serilog.Sinks.OpenTelemetry [![Build status](https://ci.appveyor.com/api/projects/status/sqmrvw34pcuatwl5/branch/dev?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-opentelemetry/branch/dev) [![NuGet Version](https://img.shields.io/nuget/vpre/Serilog.Sinks.OpenTelemetry.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.OpenTelemetry/)
1+
# Serilog.Sinks.OpenTelemetry&nbsp;[![Build status](https://github.com/serilog/serilog-sinks-opentelemetry/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/serilog/serilog-sinks-opentelemetry/actions)&nbsp;[![NuGet Version](https://img.shields.io/nuget/vpre/Serilog.Sinks.OpenTelemetry.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.OpenTelemetry/)
22

33
This Serilog sink transforms Serilog events into OpenTelemetry
44
`LogRecord`s and sends them to an OTLP (gRPC or HTTP) endpoint.

appveyor.yml

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

example/Example/Example.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
87
</PropertyGroup>
98

109
<ItemGroup>

serilog-sinks-opentelemetry.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5
99
ProjectSection(SolutionItems) = preProject
1010
.gitattributes = .gitattributes
1111
.gitignore = .gitignore
12-
appveyor.yml = appveyor.yml
1312
Build.ps1 = Build.ps1
1413
LICENSE = LICENSE
1514
README.md = README.md
1615
assets\Serilog.snk = assets\Serilog.snk
1716
global.json = global.json
17+
Directory.Build.props = Directory.Build.props
18+
Directory.Version.props = Directory.Version.props
1819
EndProjectSection
1920
EndProject
2021
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}"
@@ -27,6 +28,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{CC7B
2728
EndProject
2829
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "example\Example\Example.csproj", "{C45B5103-C0CE-40CB-ACB8-4ED17B81AB7B}"
2930
EndProject
31+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{84C182D9-BA28-4E90-B505-1DB18EA1E6C8}"
32+
EndProject
33+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{5809900F-4557-4B45-B01A-E3B5C0EB74B1}"
34+
ProjectSection(SolutionItems) = preProject
35+
.github\workflows\ci.yml = .github\workflows\ci.yml
36+
EndProjectSection
37+
EndProject
3038
Global
3139
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3240
Debug|Any CPU = Debug|Any CPU
@@ -53,6 +61,7 @@ Global
5361
{866A028E-27DB-49A0-AC78-E5FEF247C099} = {037440DE-440B-4129-9F7A-09B42D00397E}
5462
{1D56534C-4009-42C2-A573-789CAE6B8AA9} = {7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}
5563
{C45B5103-C0CE-40CB-ACB8-4ED17B81AB7B} = {CC7B094D-FD20-4053-9749-F9098927CA5E}
64+
{5809900F-4557-4B45-B01A-E3B5C0EB74B1} = {84C182D9-BA28-4E90-B505-1DB18EA1E6C8}
5665
EndGlobalSection
5766
GlobalSection(ExtensibilityGlobals) = postSolution
5867
SolutionGuid = {43C32ED4-D39A-4E27-AE99-7BB8C883833C}

src/Serilog.Sinks.OpenTelemetry/Serilog.Sinks.OpenTelemetry.csproj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22
<PropertyGroup>
33
<Description>This Serilog sink transforms Serilog events into OpenTelemetry
44
logs and sends them to an OTLP (gRPC or HTTP) endpoint.</Description>
5-
<VersionPrefix>4.1.2</VersionPrefix>
65
<Authors>Serilog Contributors</Authors>
76
<!-- .NET Framework version targeting is frozen at these two TFMs. -->
87
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net471;net462</TargetFrameworks>
98
<!-- Policy is to trim TFM-specific builds to `netstandard2.0`, `net6.0`,
109
all active LTS versions, and optionally the latest RTM version, when releasing new
1110
major Serilog versions. -->
12-
<TargetFrameworks>$(TargetFrameworks);net8.0;net6.0;netstandard2.0</TargetFrameworks>
11+
<TargetFrameworks>$(TargetFrameworks);net9.0;net8.0;net6.0;netstandard2.0</TargetFrameworks>
1312
<PackageTags>serilog;sink;opentelemetry</PackageTags>
1413
<PackageIcon>serilog-sink-nuget.png</PackageIcon>
1514
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-opentelemetry</PackageProjectUrl>
1615
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
17-
<RepositoryUrl>https://github.com/serilog/serilog-sinks-opentelemetry</RepositoryUrl>
18-
<RepositoryType>git</RepositoryType>
19-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2016
<RootNamespace>Serilog</RootNamespace>
2117
<PackageReadmeFile>README.md</PackageReadmeFile>
22-
<LangVersion>12</LangVersion>
2318
<NoWarn>CS8981</NoWarn>
2419
</PropertyGroup>
2520

@@ -31,15 +26,19 @@
3126
<DefineConstants>$(DefineConstants);FEATURE_CWT_ADDORUPDATE;FEATURE_ACTIVITY;FEATURE_HALF;FEATURE_DATE_AND_TIME_ONLY;FEATURE_SYNC_HTTP_SEND;FEATURE_SOCKETS_HTTP_HANDLER</DefineConstants>
3227
</PropertyGroup>
3328

29+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
30+
<DefineConstants>$(DefineConstants);FEATURE_CWT_ADDORUPDATE;FEATURE_ACTIVITY;FEATURE_HALF;FEATURE_DATE_AND_TIME_ONLY;FEATURE_SYNC_HTTP_SEND;FEATURE_SOCKETS_HTTP_HANDLER</DefineConstants>
31+
</PropertyGroup>
32+
3433
<ItemGroup Condition=" '$(TargetFramework)' == 'net471' or '$(TargetFramework)' == 'net462' ">
3534
<Using Include="System.Net.Http" />
3635
</ItemGroup>
3736

3837
<ItemGroup>
3938
<None Include="../../assets/serilog-sink-nuget.png" Pack="true" Visible="false" PackagePath="/" />
4039
<None Include="../../README.md" Pack="true" Visible="false" PackagePath="/" />
41-
<PackageReference Include="Google.Protobuf" Version="3.26.1" />
42-
<PackageReference Include="Grpc.Net.Client" Version="2.62.0" />
43-
<PackageReference Include="Serilog" Version="4.0.0" />
40+
<PackageReference Include="Google.Protobuf" Version="3.30.1" />
41+
<PackageReference Include="Grpc.Net.Client" Version="2.70.0" />
42+
<PackageReference Include="Serilog" Version="4.2.0" />
4443
</ItemGroup>
4544
</Project>

test/Serilog.Sinks.OpenTelemetry.Tests/OtlpEventBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void SourceContextCanBePreservedAsAttribute()
251251
var (logRecord, scopeName) = OtlpEventBuilder.ToLogRecord(logEvent, null, OpenTelemetrySinkOptions.DefaultIncludedData | IncludedData.SourceContextAttribute);
252252

253253
Assert.Equal(contextType.FullName, scopeName);
254-
var ctx = Assert.Single(logRecord.Attributes.Where(a => a.Key == Core.Constants.SourceContextPropertyName));
254+
var ctx = Assert.Single(logRecord.Attributes, a => a.Key == Core.Constants.SourceContextPropertyName);
255255
Assert.Equal(contextType.FullName, ctx.Value.StringValue);
256256
}
257257
}

0 commit comments

Comments
 (0)