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
55 changes: 55 additions & 0 deletions .github/workflows/codebreaker-lib-client-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Client stable lib

on:

# Allow manually trigger
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
env:
solutionfile-path: src/Codebreaker.GameApis.Client.sln
projectfile-path: src/client/common/Codebreaker.GameAPIs.Client/Codebreaker.GameAPIs.Client.csproj
artifact-name: codebreaker-client-stable

steps:
- name: Checkout to the branch
uses: actions/checkout@v4
with:
ref: main

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

- name: Build the library
run: dotnet build -c Release ${{ env.solutionfile-path }}

- name: Run the unit tests
run: dotnet test ${{ env.solutionfile-path }}

- name: Create a Package
run: dotnet pack -c Release ${{ env.projectfile-path }} -o packages

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifact-name }}
path: packages/*
retention-days: 30

publishdevops:
uses: CodebreakerApp/Codebreaker.Backend/.github/workflows/publishnuget-azuredevops.yml@main
needs: build
with:
artifact-name: codebreaker-client-stable
secrets: inherit

publishnuget:
uses: CodebreakerApp/Codebreaker.Backend/.github/workflows/publishnuget-nugetserver.yml@main
needs: publishdevops
with:
artifact-name: codebreaker-client-stable
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
9 changes: 4 additions & 5 deletions src/clients/common/Codebreaker.GameAPIs.Client/GamesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class GamesClient(HttpClient httpClient, ILogger<GamesClient> logger) : I
internal const string Version = "1.0.0";
internal static ActivitySource ActivitySource { get; } = new ActivitySource(ActivitySourceName, Version);

private readonly HttpClient _httpClient = httpClient;
private readonly static JsonSerializerOptions s_jsonOptions = new()
{
PropertyNameCaseInsensitive = true
Expand All @@ -31,7 +30,7 @@ public class GamesClient(HttpClient httpClient, ILogger<GamesClient> logger) : I
try
{
CreateGameRequest createGameRequest = new(gameType, playerName);
var response = await _httpClient.PostAsJsonAsync("/games", createGameRequest, s_jsonOptions, cancellationToken);
var response = await httpClient.PostAsJsonAsync("/games", createGameRequest, s_jsonOptions, cancellationToken);
response.EnsureSuccessStatusCode();
var gameResponse = await response.Content.ReadFromJsonAsync<CreateGameResponse>(s_jsonOptions, cancellationToken) ?? throw new InvalidOperationException();

Expand Down Expand Up @@ -96,7 +95,7 @@ public async Task CancelGameAsync(Guid id, string playerName, GameType gameType,
{
GuessPegs = guessPegs
};
var response = await _httpClient.PatchAsJsonAsync($"/games/{id}", updateGameRequest, s_jsonOptions, cancellationToken);
var response = await httpClient.PatchAsJsonAsync($"/games/{id}", updateGameRequest, s_jsonOptions, cancellationToken);
response.EnsureSuccessStatusCode();
var moveResponse = await response.Content.ReadFromJsonAsync<UpdateGameResponse>(s_jsonOptions, cancellationToken)
?? throw new InvalidOperationException();
Expand Down Expand Up @@ -128,7 +127,7 @@ public async Task CancelGameAsync(Guid id, string playerName, GameType gameType,
GameInfo? game;
try
{
game = await _httpClient.GetFromJsonAsync<GameInfo>($"/games/{id}", s_jsonOptions, cancellationToken);
game = await httpClient.GetFromJsonAsync<GameInfo>($"/games/{id}", s_jsonOptions, cancellationToken);
logger.GameReceived(id, game?.EndTime != null, game?.LastMoveNumber ?? 0);
}
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
Expand Down Expand Up @@ -158,7 +157,7 @@ public async Task<IEnumerable<GameInfo>> GetGamesAsync(GamesQuery query, Cancell
try
{
string urlQuery = query.AsUrlQuery();
IEnumerable<GameInfo> games = (await _httpClient.GetFromJsonAsync<IEnumerable<GameInfo>>($"/games/{urlQuery}", s_jsonOptions, cancellationToken)) ?? Enumerable.Empty<GameInfo>();
IEnumerable<GameInfo> games = (await httpClient.GetFromJsonAsync<IEnumerable<GameInfo>>($"/games/{urlQuery}", s_jsonOptions, cancellationToken)) ?? Enumerable.Empty<GameInfo>();
logger.GamesReceived(urlQuery, games.Count());
return games;
}
Expand Down