Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Tonga 0.10.0, Add smarts #13

Merged
merged 7 commits into from
Dec 4, 2024
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
136 changes: 136 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: CI/CD Workflow

on:
push:
branches:
- main
tags:
- '*'
pull_request:

env:
PROJECTS_TO_BUILD: |
src/WHyLL/WHyLL.csproj
src/WHyLL.AspNet/WHyLL.AspNet.csproj
src/WHyLL.Http/WHyLL.Http.csproj
tests/Test.WHyLL/Test.WHyLL.csproj
tests/Test.WHyLL.AspNet/Test.WHyLL.AspNet.csproj
tests/Test.WHyLL.Http/Test.WHyLL.Http.csproj

jobs:
build-and-test:
name: Build and Test
runs-on: windows-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.x'

- name: Restore Dependencies
run: |
for project in $PROJECTS_TO_BUILD; do
echo "Restoring dependencies for $project"
dotnet restore "$project"
done
shell: bash

- name: Build Projects
run: |
for project in $PROJECTS_TO_BUILD; do
echo "Building $project"
dotnet build "$project" --no-restore --configuration Release
done
shell: bash

- name: Run Tests
run: |
for project in $PROJECTS_TO_BUILD; do
if [[ $project == *"TEST"* ]]; then
echo "Running tests for $project"
dotnet test "$project" --no-build --verbosity normal --configuration Release
fi
done
shell: bash

- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get Current Tag
shell: bash
run: |
CURRENT_TAG=$(git describe --tags --abbrev=0)
echo "CURRENT_TAG=$CURRENT_TAG" >> $GITHUB_ENV

- name: Debug Current Tag
shell: bash
run: |
echo "Current Tag: $CURRENT_TAG"

- name: Restore Dependencies
run: |
for project in $PROJECTS_TO_BUILD; do
echo "Restoring dependencies for $project"
dotnet restore "$project"
done
shell: bash

- name: Pack NuGet Package
run: |
for project in $PROJECTS_TO_BUILD; do
if [[ $project != *"TEST"* ]]; then
echo "Packing $(basename "$project" .csproj) from $project with version $CURRENT_TAG"
dotnet pack "$project" --configuration Release --output "./artifacts" -p:PackageVersion=$CURRENT_TAG
fi
done
shell: bash
env:
CURRENT_TAG: ${{ env.CURRENT_TAG }}

- name: Log Files Before Upload
shell: pwsh
run: |
echo "Files ready for upload:"
Get-ChildItem -Path .\artifacts\ -File

- name: Upload NuGet Package
uses: actions/upload-artifact@v3
with:
name: nuget-package
path: ./artifacts/*.nupkg

publish:
name: Publish to NuGet
runs-on: windows-latest
needs: build-and-test
if: startsWith(github.ref, 'refs/tags/')

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Download NuGet Package
uses: actions/download-artifact@v3
with:
name: nuget-package
path: ./

- name: Log Downloaded Artifacts
shell: pwsh
run: |
echo "Downloaded artifacts:"
Get-ChildItem -Path .\ -File

- name: Publish to NuGet
shell: bash
run: |
for nupkg in ./*.nupkg; do
echo "Publishing $nupkg"
dotnet nuget push "$nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
done
2 changes: 1 addition & 1 deletion Build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="3.2.0" />
<PackageReference Include="Cake.Frosting" Version="5.0.0" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions WHyLL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
appveyor.yml = appveyor.yml
build.sh = build.sh
.github\workflows\ci-cd.yml = .github\workflows\ci-cd.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WHyLL", "src\WHyLL\WHyLL.csproj", "{EAEA2EE1-691C-43B9-B171-8430D5ED6813}"
Expand Down
2 changes: 1 addition & 1 deletion src/WHyLL.AspNet/WHyLL.AspNet.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/WHyLL.Http/WHyLL.Http.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/WHyLL.Http/Warp/HttpWire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ bool allowBodyReplay
this.allowBodyReplay = allowBodyReplay;
}

public IWarp<IMessage> Refine(string requestLine)
public IWarp<IMessage> Refine(string newFirstLine)
{
return new HttpWire(
new AsText(requestLine), this.headers, this.body, this.convert, this.allowBodyReplay
new AsText(newFirstLine), this.headers, this.body, this.convert, this.allowBodyReplay
);
}

public IWarp<IMessage> Refine(IEnumerable<IPair<string, string>> parts) =>
this.Refine(parts.ToArray());
public IWarp<IMessage> Refine(IEnumerable<IPair<string, string>> newParts) =>
this.Refine(newParts.ToArray());

public IWarp<IMessage> Refine(params IPair<string, string>[] parts)
{
Expand Down
24 changes: 11 additions & 13 deletions src/WHyLL.Http/Warp/StatusCode.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using System.Text.RegularExpressions;
using WHyLL.Warp;

namespace WHyLL.Http.Warp
{
/// <summary>
/// Renders the statuscode of a http response.
/// </summary>
public sealed class StatusCode() : WarpEnvelope<int>(new FirstLineAs<int>((line) =>
{
if (!Regex.IsMatch(line, "^HTTP\\/\\d\\.\\d\\s\\d{3}\\s.*$"))
throw new ArgumentException($"'{line}' is not a valid http response.");
return Convert.ToInt32(line.Split(" ")[1]);
})
);
}
namespace WHyLL.Http.Warp;

/// <summary>
/// Renders the statuscode of a http response.
/// </summary>
public sealed class StatusCode() : WarpEnvelope<int>(new FirstLineAs<int>(line =>
{
if (!Regex.IsMatch(line, "^HTTP\\/\\d\\.\\d\\s\\d{3}\\s.*$"))
throw new ArgumentException($"'{line}' is not a valid http response.");
return Convert.ToInt32(line.Split(" ")[1]);
})
);
6 changes: 3 additions & 3 deletions src/WHyLL.Http/Warp/WithoutHttp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public sealed class WithoutHttp(string firstLine, IEnumerable<IPair<string, stri
public WithoutHttp() : this(string.Empty, None._<IPair<string, string>>(), new MemoryStream())
{ }

public IWarp<IMessage> Refine(string firstLine) =>
new WithoutHttp(firstLine, parts, body);
public IWarp<IMessage> Refine(string newFirstLine) =>
new WithoutHttp(newFirstLine, parts, body);

public IWarp<IMessage> Refine(IEnumerable<IPair<string, string>> header) =>
public IWarp<IMessage> Refine(IEnumerable<IPair<string, string>> newParts) =>
this.Refine(parts.ToArray());

public IWarp<IMessage> Refine(params IPair<string, string>[] header) =>
Expand Down
3 changes: 0 additions & 3 deletions src/WHyLL/ByteMessage/AsByteMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ public sealed class AsByteMessage(byte[] head, IEnumerable<IPair<string,byte[]>>
{
public IByteMessage With(byte[] newHead) => new AsByteMessage(head, attributes, body);

public IByteMessage With(params IPair<string, byte[]>[] newAttributes) =>
new AsByteMessage(head, Joined._(attributes, newAttributes), body);

public IByteMessage With(IEnumerable<IPair<string, byte[]>> newAttributes) =>
new AsByteMessage(head, Joined._(attributes, newAttributes), body);

Expand Down
File renamed without changes.
7 changes: 1 addition & 6 deletions src/WHyLL/IByteMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ public interface IByteMessage
/// or status-line (response message).
/// </summary>
IByteMessage With(byte[] head);

/// <summary>
/// Refine the headers.
/// </summary>
IByteMessage With(params IPair<string, byte[]>[] attributes);


/// <summary>
/// Refine the headers.
/// </summary>
Expand Down
7 changes: 1 addition & 6 deletions src/WHyLL/IMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ public interface IMessage
/// request-line (request message)
/// or status-line (response message).
/// </summary>
IMessage With(string firstLine);

/// <summary>
/// Refine the headers.
/// </summary>
IMessage With(params IPair<string, string>[] newParts);
IMessage With(string newFirstLine);

/// <summary>
/// Refine the headers.
Expand Down
10 changes: 0 additions & 10 deletions src/WHyLL/IOptional.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/WHyLL/IWarp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IWarp<T>
/// <summary>
/// Refines the start of the Warp.
/// </summary>
IWarp<T> Refine(string start);
IWarp<T> Refine(string newFirstLine);

/// <summary>
/// Adds a header to the Warp.
Expand All @@ -18,7 +18,7 @@ public interface IWarp<T>
/// <summary>
/// Adds a header to the Warp.
/// </summary>
IWarp<T> Refine(IEnumerable<IPair<string, string>> headers);
IWarp<T> Refine(IEnumerable<IPair<string, string>> newParts);

/// <summary>
/// Adds a body to the Warp.
Expand Down
7 changes: 2 additions & 5 deletions src/WHyLL/Message/AsMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ public async Task<T> To<T>(IWarp<T> warp) =>
.Refine(body)
.Render();

public IMessage With(string firstLine) =>
new AsMessage(firstLine, parts, body);
public IMessage With(string newFirstLine) =>
new AsMessage(newFirstLine, parts, body);

public IMessage With(IEnumerable<IPair<string, string>> newParts) =>
this.With(newParts.ToArray());

public IMessage With(params IPair<string, string>[] newParts) =>
new AsMessage(firstLine, Joined._(parts, newParts), body);

public IMessage WithBody(Stream newBody) =>
Expand Down
4 changes: 0 additions & 4 deletions src/WHyLL/Message/AsyncMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Tonga;
using WHyLL.Warp;
using WHyLL.Warp;

namespace WHyLL.Message
{
Expand All @@ -16,9 +15,6 @@ public IMessage With(string firstLine) =>
asyncMessage().Result.With(firstLine);

public IMessage With(IEnumerable<IPair<string, string>> newParts) =>
this.With(newParts.ToArray());

public IMessage With(params IPair<string, string>[] newParts) =>
asyncMessage().Result.With(newParts);

public IMessage WithBody(Stream newBody) =>
Expand Down
3 changes: 0 additions & 3 deletions src/WHyLL/Message/Lambda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public IMessage With(string firstLine) =>
message.Value.With(firstLine);

public IMessage With(IEnumerable<IPair<string, string>> newParts) =>
this.With(newParts.ToArray());

public IMessage With(params IPair<string, string>[] newParts) =>
this.message.Value.With(newParts);

public IMessage WithBody(Stream newBody) =>
Expand Down
3 changes: 0 additions & 3 deletions src/WHyLL/Message/MessageEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public IMessage With(string firstLine) =>
origin.With(firstLine);

public IMessage With(IEnumerable<IPair<string, string>> newParts) =>
this.With(newParts.ToArray());

public IMessage With(params IPair<string, string>[] newParts) =>
origin.With(newParts);

public IMessage WithBody(Stream newBody) =>
Expand Down
3 changes: 0 additions & 3 deletions src/WHyLL/Message/MessageOfInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public IMessage With(string firstLine) =>
public IMessage With(IEnumerable<IPair<string, string>> newParts) =>
this.message.Value.With(newParts.ToArray());

public IMessage With(params IPair<string, string>[] newParts) =>
this.message.Value.With(newParts);

public IMessage WithBody(Stream body) =>
this.message.Value.WithBody(body);
}
Expand Down
7 changes: 7 additions & 0 deletions src/WHyLL/Message/MessageSmarts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Tonga;
using Tonga.Enumerable;

namespace WHyLL.Message;

Expand All @@ -9,4 +10,10 @@ public static class MessageSmarts
/// </summary>
public static IMessage With(this IMessage msg, IText firstLine) =>
msg.With(firstLine.AsString());

/// <summary>
/// Message with new headers.
/// </summary>
public static IMessage With(this IMessage msg, params IPair<string, string>[] newParts) =>
msg.With(new AsEnumerable<IPair<string,string>>(newParts));
}
Loading
Loading