From 714edc266ba04b3c3401cc84611181a808f610c5 Mon Sep 17 00:00:00 2001 From: RobIII Date: Thu, 7 Mar 2024 16:35:39 +0100 Subject: [PATCH] Upgrade, cleanup, add workflow actions --- .github/FUNDING.yml | 2 + .github/workflows/publishnuget.yml | 40 ++++++++++++++++++++ .github/workflows/test.yml | 29 ++++++++++++++ NEnvoy/EnvoyClient.cs | 7 +--- NEnvoy/Exceptions/EnvoyException.cs | 4 +- NEnvoy/Exceptions/LoginFailedException.cs | 7 +--- NEnvoy/NEnvoy.csproj | 9 ++--- TestApp/TestApp.csproj | 46 ++++++++++++----------- 8 files changed, 105 insertions(+), 39 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/publishnuget.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..a25ebe0 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [RobThree] +custom: ["https://paypal.me/robiii"] diff --git a/.github/workflows/publishnuget.yml b/.github/workflows/publishnuget.yml new file mode 100644 index 0000000..a98b410 --- /dev/null +++ b/.github/workflows/publishnuget.yml @@ -0,0 +1,40 @@ +name: Publish Nuget Package + +on: + release: + types: + - created + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + dotnet-version: [ '8.0.x' ] + + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET ${{ matrix.dotnet-version }} + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2 + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build -c Release --no-restore /p:Version="${{ github.event.release.tag_name }}" + + - name: Run tests + run: dotnet test -c Release --no-restore --no-build + + - name: Create packages + run: dotnet pack ${{ github.event.repository.name }} -c Release --no-restore --no-build -p:Version="${{ github.event.release.tag_name }}" + + - name: Publish + run: dotnet nuget push **\*.nupkg -s 'https://api.nuget.org/v3/index.json' -k ${{secrets.NUGET_API_KEY}} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b174c21 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Test + +on: + push + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + dotnet-version: [ '8.0.x' ] + + steps: + - uses: actions/checkout@v4 + + - name: Setup .NET ${{ matrix.dotnet-version }} + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2 + + - name: Restore dependencies + run: dotnet restore + + - name: Run tests + run: dotnet test --no-restore \ No newline at end of file diff --git a/NEnvoy/EnvoyClient.cs b/NEnvoy/EnvoyClient.cs index eea9946..25d1b15 100644 --- a/NEnvoy/EnvoyClient.cs +++ b/NEnvoy/EnvoyClient.cs @@ -140,12 +140,9 @@ private static HttpClient GetUnsafeClient(Uri baseAddress, EnvoySession? session return client; } - private class EnvoyHttpClientHandler : HttpClientHandler + private class EnvoyHttpClientHandler(EnvoySession? session) : HttpClientHandler { - private readonly EnvoySession? _session; - - public EnvoyHttpClientHandler(EnvoySession? session) - => _session = session; + private readonly EnvoySession? _session = session; protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { diff --git a/NEnvoy/Exceptions/EnvoyException.cs b/NEnvoy/Exceptions/EnvoyException.cs index ae4fd8d..97ea5c9 100644 --- a/NEnvoy/Exceptions/EnvoyException.cs +++ b/NEnvoy/Exceptions/EnvoyException.cs @@ -1,6 +1,4 @@ namespace NEnvoy.Exceptions; -public class EnvoyException : Exception +public class EnvoyException(string message, Exception? innerException = null) : Exception(message, innerException) { - public EnvoyException(string message, Exception? innerException = null) - : base(message, innerException) { } } diff --git a/NEnvoy/Exceptions/LoginFailedException.cs b/NEnvoy/Exceptions/LoginFailedException.cs index 787ca8a..c887337 100644 --- a/NEnvoy/Exceptions/LoginFailedException.cs +++ b/NEnvoy/Exceptions/LoginFailedException.cs @@ -1,9 +1,6 @@ namespace NEnvoy.Exceptions; -public class LoginFailedException : EnvoyException +public class LoginFailedException(string? responseMessage) : EnvoyException("Login failed") { - public string? ResponseMessage { get; init; } - - public LoginFailedException(string? responseMessage) - : base("Login failed") => ResponseMessage = responseMessage; + public string? ResponseMessage { get; init; } = responseMessage; } \ No newline at end of file diff --git a/NEnvoy/NEnvoy.csproj b/NEnvoy/NEnvoy.csproj index 9b2d97c..7d71686 100644 --- a/NEnvoy/NEnvoy.csproj +++ b/NEnvoy/NEnvoy.csproj @@ -1,7 +1,7 @@  - net7 + net8.0 enable enable latest @@ -18,8 +18,7 @@ git api-client;envoy;enphase-api;enphase;envoy-api MIT - Copyright © 2023 Devcorner.nl - 0.3.1-alpha + Copyright © 2023 - 2024 Devcorner.nl True @@ -31,11 +30,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/TestApp/TestApp.csproj b/TestApp/TestApp.csproj index 53676f3..6be8a07 100644 --- a/TestApp/TestApp.csproj +++ b/TestApp/TestApp.csproj @@ -1,27 +1,31 @@ - + - - Exe - net7.0 - enable - enable - bb70e725-2135-46e1-916c-401c35941915 - + + Exe + net8.0 + enable + enable + enable + latest + latest + true + bb70e725-2135-46e1-916c-401c35941915 + - - - - - + + + + + - - - + + + - - - PreserveNewest - - + + + PreserveNewest + +