From e970fa8c32c1022910b8288a36f96d3c0fb86e84 Mon Sep 17 00:00:00 2001 From: s2quake Date: Sat, 29 Jun 2024 15:51:36 +0900 Subject: [PATCH 1/7] chore: Fix typos. --- .../Extensions/ISerializerExtensions.cs | 18 +++++++++--------- src/JSSoft.Communication/Grpc/AdaptorServer.cs | 2 +- src/JSSoft.Communication/Grpc/Peer.cs | 2 +- .../Grpc/PeerCollection.cs | 4 ++-- .../MethodDescriptorCollection.cs | 16 ++++++++-------- .../ClientTestBase.cs | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/JSSoft.Communication/Extensions/ISerializerExtensions.cs b/src/JSSoft.Communication/Extensions/ISerializerExtensions.cs index fe9fb91..7aa2838 100644 --- a/src/JSSoft.Communication/Extensions/ISerializerExtensions.cs +++ b/src/JSSoft.Communication/Extensions/ISerializerExtensions.cs @@ -23,13 +23,13 @@ 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); } @@ -37,20 +37,20 @@ public static string[] SerializeMany(this ISerializer @this, Type[] types, objec } 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; diff --git a/src/JSSoft.Communication/Grpc/AdaptorServer.cs b/src/JSSoft.Communication/Grpc/AdaptorServer.cs index 2895b3e..67a3143 100644 --- a/src/JSSoft.Communication/Grpc/AdaptorServer.cs +++ b/src/JSSoft.Communication/Grpc/AdaptorServer.cs @@ -139,7 +139,7 @@ public async Task 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) { diff --git a/src/JSSoft.Communication/Grpc/Peer.cs b/src/JSSoft.Communication/Grpc/Peer.cs index 320cb49..f7fa341 100644 --- a/src/JSSoft.Communication/Grpc/Peer.cs +++ b/src/JSSoft.Communication/Grpc/Peer.cs @@ -47,7 +47,7 @@ public void EndPolling() } } - public void Disconect(int closeCode) + public void Disconnect(int closeCode) { lock (_lockObject) { diff --git a/src/JSSoft.Communication/Grpc/PeerCollection.cs b/src/JSSoft.Communication/Grpc/PeerCollection.cs index 32a8be8..d144fc1 100644 --- a/src/JSSoft.Communication/Grpc/PeerCollection.cs +++ b/src/JSSoft.Communication/Grpc/PeerCollection.cs @@ -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; } @@ -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) diff --git a/src/JSSoft.Communication/MethodDescriptorCollection.cs b/src/JSSoft.Communication/MethodDescriptorCollection.cs index bd98b86..2ba7bd1 100644 --- a/src/JSSoft.Communication/MethodDescriptorCollection.cs +++ b/src/JSSoft.Communication/MethodDescriptorCollection.cs @@ -12,7 +12,7 @@ namespace JSSoft.Communication; public sealed class MethodDescriptorCollection : IEnumerable { - private readonly Dictionary _discriptorByName; + private readonly Dictionary _descriptorByName; internal MethodDescriptorCollection(Type type) { @@ -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 GetEnumerator() - => _discriptorByName.Values.GetEnumerator(); + => _descriptorByName.Values.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() - => _discriptorByName.Values.GetEnumerator(); + => _descriptorByName.Values.GetEnumerator(); } diff --git a/test/JSSoft.Communication.Tests/ClientTestBase.cs b/test/JSSoft.Communication.Tests/ClientTestBase.cs index 27cdd37..91fd5d3 100644 --- a/test/JSSoft.Communication.Tests/ClientTestBase.cs +++ b/test/JSSoft.Communication.Tests/ClientTestBase.cs @@ -57,9 +57,9 @@ public async Task DisposeAsync() } } -public abstract class ClientTestBase : IAsyncLifetime +public abstract class ClientTestBase : IAsyncLifetime where TService : class - where TServerSevice : ServerService + where TServerService : ServerService { private readonly ClientService _clientService = new(); private readonly ServerContext _serverContext; @@ -70,7 +70,7 @@ public abstract class ClientTestBase : IAsyncLifetime private Guid _clientToken; private Guid _serverToken; - protected ClientTestBase(ITestOutputHelper logger, TServerSevice serverService) + protected ClientTestBase(ITestOutputHelper logger, TServerService serverService) { Logger = logger; ServerService = serverService; @@ -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() { From 7d355a193bb6e0c0801fa2646f102bd03f3a3b1c Mon Sep 17 00:00:00 2001 From: s2quake Date: Sat, 29 Jun 2024 15:52:15 +0900 Subject: [PATCH 2/7] ci: Improve the build action to run without artifacts. --- .github/workflows/build-and-test.yml | 41 ++++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 94341fa..ce55e6c 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -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/checkout@v4.1.7 - - name: Setup .NET - uses: actions/setup-dotnet@v4.0.0 + - uses: actions/checkout@v4.1.7 + - uses: actions/setup-dotnet@v4.0.0 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/test-reporter@v1.9.1 - 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 }} From 0c7c1dea0accb1d103126c414cdafcb41c960229 Mon Sep 17 00:00:00 2001 From: s2quake Date: Sat, 29 Jun 2024 15:52:38 +0900 Subject: [PATCH 3/7] ci: Add typos action. --- .github/workflows/typos.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/workflows/typos.yml diff --git a/.github/workflows/typos.yml b/.github/workflows/typos.yml new file mode 100644 index 0000000..41ef03b --- /dev/null +++ b/.github/workflows/typos.yml @@ -0,0 +1,11 @@ +name: Check Typos + +on: + pull_request: + +jobs: + typos: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: crate-ci/typos@v1.22.9 From 584190269ae7f9fcbe3fbf51097b5a002c4ea2f4 Mon Sep 17 00:00:00 2001 From: s2quake Date: Sat, 29 Jun 2024 15:52:57 +0900 Subject: [PATCH 4/7] ci: Add changelog check action. --- .github/workflows/check-changelog.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/check-changelog.yml diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml new file mode 100644 index 0000000..bd01836 --- /dev/null +++ b/.github/workflows/check-changelog.yml @@ -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 From 523e0cb0fe2741d9a1a5e1ea94868555d62e051e Mon Sep 17 00:00:00 2001 From: s2quake Date: Sat, 29 Jun 2024 15:53:18 +0900 Subject: [PATCH 5/7] chore: Change version properties for packing. --- Directory.Build.props | 3 ++- Directory.Build.targets | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index e0f7e40..0550a44 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -57,7 +57,8 @@ SOFTWARE. --> Copyright (c) 2024 Jeesu Choi grpc-based communication library for crema project s2quake - $(FileVersion) + $(FileVersion) + $(FileVersion)-$(VersionSuffix) https://github.com/s2quake/communication LICENSE.md README.md diff --git a/Directory.Build.targets b/Directory.Build.targets index 229c68f..513c4e2 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -29,11 +29,6 @@ SOFTWARE. --> $(PublishDir) $(DesiredPublishDirTemp) - - - $(FileVersion)-$(TargetFramework) - - $([System.IO.Path]::Combine($(DesiredPublishDir),$(PublishName))) From 147f9a666ecbb14d5e2446831599da5c4edb5cb2 Mon Sep 17 00:00:00 2001 From: s2quake Date: Sat, 29 Jun 2024 15:53:35 +0900 Subject: [PATCH 6/7] ci: Add pack action. --- .github/scripts/pack.ps1 | 35 +++++++++++++++++++++++++++ .github/workflows/pack.yml | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100755 .github/scripts/pack.ps1 create mode 100644 .github/workflows/pack.yml diff --git a/.github/scripts/pack.ps1 b/.github/scripts/pack.ps1 new file mode 100755 index 0000000..5a131d9 --- /dev/null +++ b/.github/scripts/pack.ps1 @@ -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 " ")" diff --git a/.github/workflows/pack.yml b/.github/workflows/pack.yml new file mode 100644 index 0000000..6cbf3bf --- /dev/null +++ b/.github/workflows/pack.yml @@ -0,0 +1,49 @@ +name: Pack + +on: + pull_request: + push: + branches: + - main + tags: + - "*" + +jobs: + pack: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.7 + - uses: actions/setup-dotnet@v4.0.0 + 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 From f1d4601c8c91a9918eb3b2fde343e8e94ca419ed Mon Sep 17 00:00:00 2001 From: s2quake Date: Sat, 29 Jun 2024 15:53:50 +0900 Subject: [PATCH 7/7] chore: Changelog --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f8dd54b..93a08e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 -------------