diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cf5375e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,49 @@ +name: CI + +on: + push: + branches: + - main + - dev + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 10.0.x + + - name: Build + run: dotnet build src/Max.BotClient/Max.BotClient.csproj -c Release + + - name: Test + run: dotnet test tests/Max.BotClient.Tests/Max.BotClient.Tests.csproj -c Release --no-build + + publish: + runs-on: ubuntu-latest + needs: build-and-test + if: github.ref == 'refs/heads/main' + environment: main + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 10.0.x + + - name: Pack + run: dotnet pack src/Max.BotClient/Max.BotClient.csproj -c Release -o ./artifacts + + - name: Push to NuGet + run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate \ No newline at end of file diff --git a/src/Max.BotClient/Max.BotClient.DependencyInjection.cs b/src/Max.BotClient/Max.BotClient.DependencyInjection.cs new file mode 100644 index 0000000..e0350d9 --- /dev/null +++ b/src/Max.BotClient/Max.BotClient.DependencyInjection.cs @@ -0,0 +1,44 @@ +#if NET10_0_OR_GREATER +using System; +using System.Net.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace Max.BotClient +{ + public static class BotClientServiceCollectionExtensions + { + /// + /// Регистрирует и в DI-контейнере. + /// + /// Коллекция сервисов. + /// Токен бота. + /// Дополнительная настройка параметров (RetryCount, RetryDelaySeconds и др.). + public static IServiceCollection AddMaxBotClient( + this IServiceCollection services, + string token, + Action? configure = null) + { + ArgumentNullException.ThrowIfNull(services); + + var options = new BotClientOptions(token); + configure?.Invoke(options); + + services.TryAddSingleton(options); + + services.AddHttpClient("MaxBotClient"); + + services.TryAddSingleton(sp => + { + var factory = sp.GetRequiredService(); + var httpClient = factory.CreateClient("MaxBotClient"); + return new BotClient(options, httpClient); + }); + + services.TryAddSingleton(sp => (BotClient)sp.GetRequiredService()); + + return services; + } + } +} +#endif \ No newline at end of file diff --git a/src/Max.BotClient/Max.BotClient.csproj b/src/Max.BotClient/Max.BotClient.csproj index b505e1b..d0ae1ab 100644 --- a/src/Max.BotClient/Max.BotClient.csproj +++ b/src/Max.BotClient/Max.BotClient.csproj @@ -1,15 +1,17 @@  - netstandard2.0 + netstandard2.0;net10.0 latest enable - 1.0.0 + 1.0.1 + Max.BotClient Deskri SDK for MAX Bot API (.NET Standard 2.0) MIT + https://github.com/Deskri/Max.BotClient https://github.com/Deskri/Max.BotClient max;bot;api;sdk README.md @@ -23,4 +25,9 @@ + + + + + diff --git a/tests/Max.BotClient.Tests/Max.BotClient.Tests.csproj b/tests/Max.BotClient.Tests/Max.BotClient.Tests.csproj index 3d1659c..a15db4d 100644 --- a/tests/Max.BotClient.Tests/Max.BotClient.Tests.csproj +++ b/tests/Max.BotClient.Tests/Max.BotClient.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net10.0 false enable latest