Skip to content

Commit 686835d

Browse files
committed
ci: update pipelines and include tests
1 parent 6df10d4 commit 686835d

File tree

5 files changed

+144
-16
lines changed

5 files changed

+144
-16
lines changed

.github/workflows/build.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build
1+
name: Build And Test
22

33
on:
44
push:
@@ -9,19 +9,24 @@ on:
99
- main
1010

1111
jobs:
12-
build:
13-
name: Build
12+
build-and-test:
1413
runs-on: ubuntu-latest
1514
steps:
16-
- uses: actions/checkout@v5
15+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
1716

18-
- name: Setup .NET 9
19-
uses: actions/setup-dotnet@v5
17+
- name: Setup dotnet
18+
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
2019
with:
21-
dotnet-version: 9.0.*
20+
dotnet-version: |
21+
8.0.x
22+
9.0.x
23+
10.0.x
2224
23-
- name: Restore dotnet
25+
- name: Install dependencies
2426
run: dotnet restore
2527

26-
- name: Build dotnet
28+
- name: Build
2729
run: dotnet build --no-restore
30+
31+
- name: Test with the dotnet CLI
32+
run: dotnet test --no-restore

.github/workflows/publish.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ jobs:
99
build:
1010
name: Build and release
1111
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write # enable GitHub OIDC token issuance for trusted publishing
14+
contents: read
1215
steps:
13-
- uses: actions/checkout@v5
16+
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
1417

15-
- name: Setup .NET 9
16-
uses: actions/setup-dotnet@v5
18+
- name: Setup .NET 10
19+
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0
1720
with:
18-
dotnet-version: 9.0.*
21+
dotnet-version: 10.0.*
1922

2023
- name: Restore dotnet
2124
run: dotnet restore
@@ -25,7 +28,7 @@ jobs:
2528

2629
- name: Docker meta
2730
id: meta
28-
uses: docker/metadata-action@v5
31+
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
2932
with:
3033
flavor: |
3134
latest=false

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
release-please:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/create-github-app-token@v2
16+
- uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
1717
id: app-token
1818
with:
1919
app-id: ${{ vars.RELEASE_BOT_APP_ID }}
2020
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
21-
- uses: googleapis/release-please-action@v4
21+
- uses: googleapis/release-please-action@16a9c90856f42705d54a6fda1823352bdc62cf38 # v4.4.0
2222
with:
2323
token: ${{ steps.app-token.outputs.token }}
2424
config-file: ".github/release-please-config.json"

Intility.Logging.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkerSample", "samples\Wor
2424
EndProject
2525
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalApiSample", "samples\MinimalApiSample\MinimalApiSample.csproj", "{B647AC70-7210-462A-A43C-6EB4AFCB7ED4}"
2626
EndProject
27+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intility.Logging.Tests", "tests\Intility.Logging.Tests\Intility.Logging.Tests.csproj", "{97695851-9359-45F1-AEC8-0876E7061D54}"
30+
EndProject
2731
Global
2832
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2933
Debug|Any CPU = Debug|Any CPU
@@ -118,6 +122,18 @@ Global
118122
{B647AC70-7210-462A-A43C-6EB4AFCB7ED4}.Release|x64.Build.0 = Release|Any CPU
119123
{B647AC70-7210-462A-A43C-6EB4AFCB7ED4}.Release|x86.ActiveCfg = Release|Any CPU
120124
{B647AC70-7210-462A-A43C-6EB4AFCB7ED4}.Release|x86.Build.0 = Release|Any CPU
125+
{97695851-9359-45F1-AEC8-0876E7061D54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
126+
{97695851-9359-45F1-AEC8-0876E7061D54}.Debug|Any CPU.Build.0 = Debug|Any CPU
127+
{97695851-9359-45F1-AEC8-0876E7061D54}.Debug|x64.ActiveCfg = Debug|Any CPU
128+
{97695851-9359-45F1-AEC8-0876E7061D54}.Debug|x64.Build.0 = Debug|Any CPU
129+
{97695851-9359-45F1-AEC8-0876E7061D54}.Debug|x86.ActiveCfg = Debug|Any CPU
130+
{97695851-9359-45F1-AEC8-0876E7061D54}.Debug|x86.Build.0 = Debug|Any CPU
131+
{97695851-9359-45F1-AEC8-0876E7061D54}.Release|Any CPU.ActiveCfg = Release|Any CPU
132+
{97695851-9359-45F1-AEC8-0876E7061D54}.Release|Any CPU.Build.0 = Release|Any CPU
133+
{97695851-9359-45F1-AEC8-0876E7061D54}.Release|x64.ActiveCfg = Release|Any CPU
134+
{97695851-9359-45F1-AEC8-0876E7061D54}.Release|x64.Build.0 = Release|Any CPU
135+
{97695851-9359-45F1-AEC8-0876E7061D54}.Release|x86.ActiveCfg = Release|Any CPU
136+
{97695851-9359-45F1-AEC8-0876E7061D54}.Release|x86.Build.0 = Release|Any CPU
121137
EndGlobalSection
122138
GlobalSection(SolutionProperties) = preSolution
123139
HideSolutionNode = FALSE
@@ -130,6 +146,7 @@ Global
130146
{2C7C52E9-835F-4051-9A5E-7D985545A795} = {A5767C5D-9A48-4485-8D5E-686F34B2B766}
131147
{25312E6A-4BA3-4FDF-AA7C-CF2A10CDA2AA} = {A5767C5D-9A48-4485-8D5E-686F34B2B766}
132148
{B647AC70-7210-462A-A43C-6EB4AFCB7ED4} = {A5767C5D-9A48-4485-8D5E-686F34B2B766}
149+
{97695851-9359-45F1-AEC8-0876E7061D54} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
133150
EndGlobalSection
134151
GlobalSection(ExtensibilityGlobals) = postSolution
135152
SolutionGuid = {4B2214E5-8A73-47CE-9C97-4910BC331A86}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Hosting;
3+
using Microsoft.Extensions.Logging;
4+
using Serilog;
5+
using Serilog.Events;
6+
7+
namespace Intility.Logging.Tests;
8+
9+
public class LoggingExtensionsTests
10+
{
11+
[Fact]
12+
public void CanCreateLoggerInstance()
13+
{
14+
// Arrange
15+
var loggerConfig = new LoggerConfiguration()
16+
.MinimumLevel.Debug()
17+
.WriteTo.Console();
18+
19+
Log.Logger = loggerConfig.CreateLogger();
20+
21+
// Act
22+
var logger = Log.Logger;
23+
24+
// Assert
25+
Assert.NotNull(logger);
26+
logger.Information("Test log message");
27+
}
28+
29+
[Fact]
30+
public void CanConfigureLoggingWithHostBuilder()
31+
{
32+
// Arrange & Act
33+
var host = Host.CreateDefaultBuilder()
34+
.ConfigureLogging((context, logging) =>
35+
{
36+
logging.ClearProviders();
37+
logging.AddConsole();
38+
})
39+
.Build();
40+
41+
var logger = host.Services.GetRequiredService<ILogger<LoggingExtensionsTests>>();
42+
43+
// Assert
44+
Assert.NotNull(logger);
45+
logger.LogInformation("Test log from host builder");
46+
}
47+
48+
[Fact]
49+
public void LoggerCanWriteDifferentLevels()
50+
{
51+
// Arrange
52+
var loggerConfig = new LoggerConfiguration()
53+
.MinimumLevel.Verbose()
54+
.WriteTo.Console();
55+
56+
var logger = loggerConfig.CreateLogger();
57+
58+
// Act & Assert
59+
Assert.NotNull(logger);
60+
61+
logger.Verbose("Verbose message");
62+
logger.Debug("Debug message");
63+
logger.Information("Information message");
64+
logger.Warning("Warning message");
65+
logger.Error("Error message");
66+
}
67+
68+
[Fact]
69+
public void LoggerCanWriteStructuredData()
70+
{
71+
// Arrange
72+
var loggerConfig = new LoggerConfiguration()
73+
.MinimumLevel.Information()
74+
.WriteTo.Console();
75+
76+
var logger = loggerConfig.CreateLogger();
77+
78+
// Act & Assert
79+
Assert.NotNull(logger);
80+
81+
logger.Information("User {UserId} logged in from {IpAddress}",
82+
12345,
83+
"192.168.1.1");
84+
}
85+
86+
[Fact]
87+
public void LoggerMinimumLevelIsRespected()
88+
{
89+
// Arrange
90+
var loggerConfig = new LoggerConfiguration()
91+
.MinimumLevel.Warning()
92+
.WriteTo.Console();
93+
94+
var logger = loggerConfig.CreateLogger();
95+
96+
// Act & Assert
97+
Assert.NotNull(logger);
98+
Assert.True(logger.IsEnabled(LogEventLevel.Warning));
99+
Assert.True(logger.IsEnabled(LogEventLevel.Error));
100+
Assert.False(logger.IsEnabled(LogEventLevel.Debug));
101+
Assert.False(logger.IsEnabled(LogEventLevel.Verbose));
102+
}
103+
}

0 commit comments

Comments
 (0)