-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25e40e0
commit ce8846c
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Release Probes | ||
|
||
on: | ||
repository_dispatch: | ||
push: | ||
tags: | ||
- "Probes-v[0-9]+.[0-9]+.[0-9]+" | ||
|
||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY}} | ||
|
||
jobs: | ||
|
||
Release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Verify commit | ||
run: | | ||
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* | ||
git branch --remote --contains | grep origin/main | ||
- name: Set version | ||
run: echo "VERSION=${GITHUB_REF/refs\/tags\/Probes-v/}" >> $GITHUB_ENV | ||
|
||
- name: Build | ||
run: | | ||
dotnet build src/BitzArt.Probes/BitzArt.Probes.csproj --configuration Release /p:Version=${VERSION} | ||
dotnet pack src/BitzArt.Probes/BitzArt.Probes.csproj --configuration Release /p:Version=${VERSION} --no-build --output . | ||
- name: Push | ||
run: dotnet nuget push BitzArt.Probes.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<PackageId>BitzArt.Probes</PackageId> | ||
<Authors>BitzArt</Authors> | ||
<Description>Default probes and healthchecks for web APIs</Description> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/BitzArt/Miscellaneous</RepositoryUrl> | ||
<PackageProjectUrl>https://github.com/BitzArt/Miscellaneous</PackageProjectUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
26 changes: 26 additions & 0 deletions
26
src/BitzArt.Probes/Extensions/AddServiceInfoOptionsExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using BitzArt.Probes; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace BitzArt; | ||
|
||
public static class AddServiceInfoOptionsExtension | ||
{ | ||
public static IHostApplicationBuilder AddServiceInfoOptions(this IHostApplicationBuilder builder) | ||
{ | ||
builder.Services.AddServiceInfoOptions(builder.Configuration); | ||
return builder; | ||
} | ||
|
||
public static IServiceCollection AddServiceInfoOptions(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
var options = configuration | ||
.GetRequiredSection(ServiceInfoOptions.SectionName) | ||
.Get<ServiceInfoOptions>()!; | ||
|
||
services.AddSingleton(options); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using BitzArt.Probes; | ||
using HealthChecks.UI.Client; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace BitzArt; | ||
|
||
public static class MapProbesExtension | ||
{ | ||
public static IEndpointRouteBuilder MapRoutes(this IEndpointRouteBuilder builder) | ||
{ | ||
builder.MapHealthChecks("_health", new HealthCheckOptions | ||
{ | ||
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse | ||
}); | ||
|
||
var infoOptions = builder.ServiceProvider.GetService<ServiceInfoOptions>(); | ||
|
||
if (infoOptions is null) | ||
{ | ||
builder.MapGet("/", () => "It's good to be alive."); | ||
} | ||
else | ||
{ | ||
var info = new ServiceInfoResponse(infoOptions); | ||
builder.MapGet("/", () => info); | ||
} | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BitzArt.Probes; | ||
|
||
internal class ServiceInfoResponse(ServiceInfoOptions options) | ||
{ | ||
[JsonPropertyName("serviceName")] | ||
public string? ServiceName { get; set; } = options.Name; | ||
|
||
[JsonPropertyName("version")] | ||
public string? Version { get; set; } = options.Version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace BitzArt.Probes; | ||
|
||
public class ServiceInfoOptions | ||
{ | ||
public const string SectionName = "ServiceInfo"; | ||
|
||
public string? Name { get; set; } | ||
public string? Version { get; set; } | ||
} |