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

Improve CI to make sure minimal checks are done before merge #26

Merged
merged 7 commits into from
Jun 29, 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
35 changes: 35 additions & 0 deletions .github/scripts/pack.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/local/bin/pwsh
param (
[ValidateScript({ ($_ -eq "") -or !(Test-Path $_ -PathType Leaf) })]
[string]$OutputPath = "",
[ValidateScript({ $_ -ge 0 })]
[int]$PullRequestNumber = 0,
[ValidateScript({ ($_ -eq "") -or (Test-Path $_) })]
[string]$KeyPath = ""
)

$namespaces = @{
ns = "http://schemas.microsoft.com/developer/msbuild/2003"
}
$propsPath = "Directory.Build.props"
$fileVersionPath = "/ns:Project/ns:PropertyGroup/ns:FileVersion"
$result = Select-Xml -Path $propsPath -Namespace $namespaces -XPath $fileVersionPath
if ($null -eq $result) {
Write-Host "File version not found"
exit 1
}

$fileVersion = $result.Node.InnerText
$KeyPath = $KeyPath ? $(Resolve-Path -Path $KeyPath) : ""
$OutputPath = $OutputPath ? [System.IO.Path]::GetFullPath($OutputPath) : ""
$keyPathExits = Test-Path -Path $KeyPath

$options = @(
$OutputPath ? "-o '$OutputPath'" : ""
"-p:FileVersion='$fileVersion'"
$PullRequestNumber ? "--version-suffix pr.$PullRequestNumber" : ""
$keyPathExits ? "-p:TreatWarningsAsErrors=true" : ""
$keyPathExits ? "-p:AssemblyOriginatorKeyFile='$KeyPath'" : ""
) | Where-Object { $_ }

Invoke-Expression -Command "dotnet pack $($options -join " ")"
41 changes: 17 additions & 24 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
name: Build and Test

on:
pull_request:
pull_request:

env:
TEST_RESULTS_PATH: ${{ github.workspace }}/test-results.trx

permissions:
contents: read
actions: read
checks: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Setup .NET
uses: actions/[email protected]
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
dotnet-version: 8.0.100
- name: Dotnet Build
run: dotnet build --configuration Release
- name: Dotnet Test
run: |
dotnet test --configuration Release --no-restore --no-build --logger "trx;LogFileName=${{ env.TEST_RESULTS_PATH }}"
- name: Upload test results
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-results
path: ${{ env.TEST_RESULTS_PATH }}
- name: Upload test results
uses: dorny/[email protected]
if: success() || failure()
- run: echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk
- run: |
dotnet build \
--configuration Release \
-p:TreatWarningsAsErrors=true \
-p:TreatWarningsAsErrors=true \
-p:AssemblyOriginatorKeyFile=$(pwd)/private.snk
- run: |
dotnet test \
--configuration Release \
--no-restore \
--no-build \
--logger "trx;LogFileName=${{ env.TEST_RESULTS_PATH }}"
- uses: dorny/test-reporter@v1
with:
name: XUnit Tests
path: ${{ env.TEST_RESULTS_PATH }}
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/check-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Check Changelog

on:
pull_request:

jobs:
check-changelog:
runs-on: ubuntu-latest
steps:
- uses: tarides/changelog-check-action@v2
with:
changelog: CHANGES.md
49 changes: 49 additions & 0 deletions .github/workflows/pack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Pack

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

jobs:
pack:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
dotnet-version: 8.0.100
- run: echo "${{ secrets.SNK_FILE }}" | base64 --decode > private.snk
- if: ${{ github.event_name == 'pull_request' }}
run: |
.github/scripts/pack.ps1 `
-OutputPath "pack" `
-PullRequestNumber ${{ github.event.pull_request.number }} `
-KeyPath "$pwd/private.snk"
shell: pwsh
- if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |
$commitMessage = "$(git log -1 --pretty=%B)"
$pattern = "(?<=Merge pull request #)(\d+)"
if (!($commitMessage -match $pattern)) {
Write-Error "Commit message does not contain a pull request number."
}

Remove-Item -Force -Recurse pack -ErrorAction SilentlyContinue

.github/scripts/pack.ps1 `
-OutputPath "pack" `
-PullRequestNumber $matches[1] `
-KeyPath "$pwd/private.snk"

Get-ChildItem -Path pack -Filter "*.nupkg" | ForEach-Object {
dotnet nuget push `
$_ `
--skip-duplicate `
--api-key ${{ secrets.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json
}
shell: pwsh
11 changes: 11 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Check Typos

on:
pull_request:

jobs:
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: crate-ci/[email protected]
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Communication changes

To be released.

* Improve CI to make sure minimal checks are done before merge [[#26]]

[26]: https://github.com/s2quake/communication/pull/26


2.0.2
-------------
Expand Down
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ SOFTWARE. -->
<Copyright>Copyright (c) 2024 Jeesu Choi</Copyright>
<Description>grpc-based communication library for crema project</Description>
<Authors>s2quake</Authors>
<PackageVersion>$(FileVersion)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)'==''">$(FileVersion)</PackageVersion>
<PackageVersion Condition="'$(VersionSuffix)'!=''">$(FileVersion)-$(VersionSuffix)</PackageVersion>
<PackageProjectUrl>https://github.com/s2quake/communication</PackageProjectUrl>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
5 changes: 0 additions & 5 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ SOFTWARE. -->
<DesiredPublishDirTemp Condition="'$(PublishDir)' != '$(DesiredPublishDir)'">$(PublishDir)</DesiredPublishDirTemp>
<DesiredPublishDir>$(DesiredPublishDirTemp)</DesiredPublishDir>
</PropertyGroup>
<Target Name="BeforeBuild">
<PropertyGroup>
<Version>$(FileVersion)-$(TargetFramework)</Version>
</PropertyGroup>
</Target>
<Target Name="AfterBuild">
<PropertyGroup Condition="'$(PublishName)' != ''">
<PublishDir>$([System.IO.Path]::Combine($(DesiredPublishDir),$(PublishName)))</PublishDir>
Expand Down
18 changes: 9 additions & 9 deletions src/JSSoft.Communication/Extensions/ISerializerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ public static string[] SerializeMany(this ISerializer @this, Type[] types, objec
return items;
}

public static object?[] DeserializeMany(this ISerializer @this, Type[] types, string[] datas)
public static object?[] DeserializeMany(this ISerializer @this, Type[] types, string[] data)
{
var items = new object?[datas.Length];
for (var i = 0; i < datas.Length; i++)
var items = new object?[data.Length];
for (var i = 0; i < data.Length; i++)
{
var type = types[i];
var value = datas[i];
var value = data[i];
items[i] = @this.Deserialize(type, value);
}

return items;
}

public static object?[] DeserializeMany(
this ISerializer @this, Type[] types, string[] datas, CancellationToken? cancellationToken)
this ISerializer @this, Type[] types, string[] data, CancellationToken? cancellationToken)
{
var length = cancellationToken != null ? datas.Length + 1 : datas.Length;
var length = cancellationToken != null ? data.Length + 1 : data.Length;
var items = new object?[length];
for (var i = 0; i < datas.Length; i++)
for (var i = 0; i < data.Length; i++)
{
var type = types[i];
var value = datas[i];
var value = data[i];
items[i] = @this.Deserialize(type, value);
}

if (cancellationToken != null)
{
items[datas.Length] = cancellationToken;
items[data.Length] = cancellationToken;
}

return items;
Expand Down
2 changes: 1 addition & 1 deletion src/JSSoft.Communication/Grpc/AdaptorServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task<InvokeReply> InvokeAsync(InvokeRequest request, ServerCallCont
var instance = peer.Services[service];
var args = _serializer.DeserializeMany(
types: methodDescriptor.ParameterTypes,
datas: [.. request.Data],
data: [.. request.Data],
cancellationToken: cancellationToken);
if (methodDescriptor.IsOneWay == true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/JSSoft.Communication/Grpc/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void EndPolling()
}
}

public void Disconect(int closeCode)
public void Disconnect(int closeCode)
{
lock (_lockObject)
{
Expand Down
4 changes: 2 additions & 2 deletions src/JSSoft.Communication/Grpc/PeerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public bool Remove(IServiceContext serviceContext, string id, int closeCode)
{
peer.Descriptor = null;
_instanceContext.DestroyInstance(peer);
peer.Disconect(closeCode);
peer.Disconnect(closeCode);
serviceContext.Debug($"{id} Disconnected ({closeCode})");
return true;
}
Expand All @@ -53,7 +53,7 @@ public async Task DisconnectAsync(
using var cancellationTokenSource = new CancellationTokenSource(millisecondsDelay: 3000);
foreach (var item in items)
{
item.Disconect(closeCode: 0);
item.Disconnect(closeCode: 0);
}

while (Count > 0 && cancellationTokenSource.IsCancellationRequested != true)
Expand Down
16 changes: 8 additions & 8 deletions src/JSSoft.Communication/MethodDescriptorCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace JSSoft.Communication;

public sealed class MethodDescriptorCollection : IEnumerable<MethodDescriptor>
{
private readonly Dictionary<string, MethodDescriptor> _discriptorByName;
private readonly Dictionary<string, MethodDescriptor> _descriptorByName;

internal MethodDescriptorCollection(Type type)
{
Expand All @@ -25,23 +25,23 @@ internal MethodDescriptorCollection(Type type)
{
var methodInfos = type.GetMethods();
var methodDescriptors = methodInfos.Select(item => new MethodDescriptor(item));
_discriptorByName = methodDescriptors.ToDictionary(item => item.Name);
_descriptorByName = methodDescriptors.ToDictionary(item => item.Name);
}
else
{
_discriptorByName = [];
_descriptorByName = [];
}
}

public int Count => _discriptorByName.Count;
public int Count => _descriptorByName.Count;

public MethodDescriptor this[string name] => _discriptorByName[name];
public MethodDescriptor this[string name] => _descriptorByName[name];

public bool Contains(string name) => _discriptorByName.ContainsKey(name);
public bool Contains(string name) => _descriptorByName.ContainsKey(name);

public IEnumerator<MethodDescriptor> GetEnumerator()
=> _discriptorByName.Values.GetEnumerator();
=> _descriptorByName.Values.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator()
=> _discriptorByName.Values.GetEnumerator();
=> _descriptorByName.Values.GetEnumerator();
}
8 changes: 4 additions & 4 deletions test/JSSoft.Communication.Tests/ClientTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public async Task DisposeAsync()
}
}

public abstract class ClientTestBase<TService, TServerSevice> : IAsyncLifetime
public abstract class ClientTestBase<TService, TServerService> : IAsyncLifetime
where TService : class
where TServerSevice : ServerService<TService>
where TServerService : ServerService<TService>
{
private readonly ClientService<TService> _clientService = new();
private readonly ServerContext _serverContext;
Expand All @@ -70,7 +70,7 @@ public abstract class ClientTestBase<TService, TServerSevice> : IAsyncLifetime
private Guid _clientToken;
private Guid _serverToken;

protected ClientTestBase(ITestOutputHelper logger, TServerSevice serverService)
protected ClientTestBase(ITestOutputHelper logger, TServerService serverService)
{
Logger = logger;
ServerService = serverService;
Expand All @@ -82,7 +82,7 @@ protected ClientTestBase(ITestOutputHelper logger, TServerSevice serverService)

protected TService Client => _client!;

protected TServerSevice ServerService { get; }
protected TServerService ServerService { get; }

public async Task InitializeAsync()
{
Expand Down
Loading