Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,23 @@ name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches:
- '*'
tags:
- '*.*.*'

jobs:
build:

runs-on: ubuntu-latest

env:
Configuration: Release

steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Build
run: dotnet build
- name: Test
run: dotnet test --no-build
- name: Publish
run: dotnet nuget push ./src/assurance/bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.NUGET_API_KEY}}
if: github.event_name != 'pull_request'
environment:
name: NuGet.org
url: https://www.nuget.org/packages/Assurance
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build
32 changes: 32 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish

on:
release:
types: [ published ]

jobs:
publish:
if: startsWith(github.repository, 'chris-peterson')

runs-on: ubuntu-latest

env:
Configuration: Release
PackageReleaseNotes: ${{ github.event.release.body }}
PackageReleaseTag: ${{ github.event.release.tag_name }}

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Build
run: dotnet build
- name: Publish to nuget.org
run: dotnet nuget push **/*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

environment:
name: nuget.org
url: https://nuget.org/packages/Assurance
10 changes: 4 additions & 6 deletions src/assurance/Assurance.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.1.3</Version>
<Version>1.2.0</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Title>Assurance</Title>
<Authors>Chris Peterson</Authors>
<Description>A library to boost confidence when making code changes</Description>
<Copyright>2021-2023</Copyright>
<Copyright>2021-2025</Copyright>
<AssemblyName>Assurance</AssemblyName>
<PackageId>Assurance</PackageId>
<PackageProjectUrl>https://github.com/chris-peterson/assurance</PackageProjectUrl>
<PackageTags>validator</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>
Include release notes in package
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spiffy.Monitoring" Version="6.0.*" />
<PackageReference Include="Spiffy.Monitoring" Version="6.4.*" />
</ItemGroup>

<ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions src/assurance/LoggingContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Spiffy.Monitoring;

namespace Assurance;

internal class LoggingContext(EventContext _eventContext, string _loggingPrefix, bool _isMyEventContext)
{
public EventContext EventContext => _eventContext;
string GetLoggingKey(string key)
{
return $"{_loggingPrefix}{key}";
}

public void Log(string field, object value)
{
_eventContext[GetLoggingKey(field)] = value;
}

public void AppendToValue(string field, string value)
{
_eventContext.AppendToValue(GetLoggingKey(field), value, ",");
}

#pragma warning disable CS0465 // Introducing a 'Finalize' method can interfere with destructor invocation
public void Finalize()
#pragma warning restore CS0465 // Introducing a 'Finalize' method can interfere with destructor invocation
{
if (_isMyEventContext)
{
_eventContext.Dispose();
}
WasFinalized = true;
}

public bool WasFinalized { get; set; }

public void Warn(string value)
{
_eventContext.SetToWarning(value);
}
}
82 changes: 41 additions & 41 deletions src/assurance/RunResult.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
using Spiffy.Monitoring;

namespace Assurance
namespace Assurance;

public class RunResult<T>
{
public class RunResult<T>
readonly LoggingContext _loggingContext;
internal RunResult(T existing, T replacement, LoggingContext loggingContext)
{
readonly EventContext _eventContext;
bool _loggedProperly = false;
public RunResult(T existing, T replacement, EventContext eventContext)
{
Existing = existing;
Replacement = replacement;
_eventContext = eventContext;
}
Existing = existing;
Replacement = replacement;
_loggingContext = loggingContext;
}

public T Existing { get; }
public T Replacement { get; }
public bool SameResult
public T Existing { get; }
public T Replacement { get; }
public bool SameResult
{
get
{
get
{
if (Existing == null)
return Replacement == null;
return Existing.Equals(Replacement);
}
if (Existing == null)
return Replacement == null;
return Existing.Equals(Replacement);
}
}

public T UseExisting()
{
LogUse("existing");
return Existing;
}
public T UseReplacement()
{
LogUse("replacement");
return Replacement;
}
public T UseExisting()
{
LogUse("existing");
return Existing;
}

void LogUse(string use)
{
_eventContext["Use"] = use;
_eventContext.Dispose();
_loggedProperly = true;
}
public T UseReplacement()
{
LogUse("replacement");
return Replacement;
}

~RunResult()
public EventContext EventContext => _loggingContext.EventContext;

void LogUse(string use)
{
_loggingContext.Log("Use", use);
_loggingContext.Finalize();
}

~RunResult()
{
if (!_loggingContext.WasFinalized)
{
if (!_loggedProperly)
{
_eventContext.SetToWarning("Call UseExisting or UseReplacement in order to avoid this warning");
LogUse("Unknown");
}
_loggingContext.Warn("Call UseExisting or UseReplacement in order to avoid this warning");
LogUse("unknown");
}
}
}
Loading