From b1af502ba67235432a4273e0b5d4b22a166105fe Mon Sep 17 00:00:00 2001 From: HavenDV Date: Wed, 11 Sep 2024 04:58:36 +0400 Subject: [PATCH] ci: Use cli init command in cli tests. --- .github/workflows/main.yml | 37 ++++++------------- .../AutoSDK.CLI/Commands/InitializeCommand.cs | 23 +++++++++--- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a324d5026..86325f5a29 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,33 +52,20 @@ jobs: - name: Generate code run: dotnet run --project src/libs/AutoSDK.CLI - generate specs/${{ matrix.spec }} - --namespace Oag - --targetFramework net8.0 + init + TestSolution + TestApi + https://raw.githubusercontent.com/api/openapi.json + TestCompany --output TestProject + --add-tests false - - name: Create .csproj file - run: | - cat < TestProject/TestProject.csproj - - - - net8.0 - preview - enable - enable - true - - - - true - latest - All - true - - - - EOF + - name: Generate code + run: dotnet run --project src/libs/AutoSDK.CLI + generate specs/${{ matrix.spec }} + --namespace TestSolution + --targetFramework net8.0 + --output TestProject/src/libs/TestSolution/Generated - name: Build run: dotnet build TestProject diff --git a/src/libs/AutoSDK.CLI/Commands/InitializeCommand.cs b/src/libs/AutoSDK.CLI/Commands/InitializeCommand.cs index df982da903..22a8af7505 100644 --- a/src/libs/AutoSDK.CLI/Commands/InitializeCommand.cs +++ b/src/libs/AutoSDK.CLI/Commands/InitializeCommand.cs @@ -31,12 +31,17 @@ public class InitializeCommand : Command aliases: ["--add-mkdocs", "-m"], getDefaultValue: () => true, description: "Adds MkDocs to the solution"); + var addTests = new Option( + aliases: ["--add-tests", "-t"], + getDefaultValue: () => true, + description: "Adds integration tests to the solution"); AddArgument(solutionName); AddArgument(apiName); AddArgument(openApiSpec); AddArgument(company); AddOption(output); AddOption(addMkDocs); + AddOption(addTests); this.SetHandler( HandleAsync, @@ -45,7 +50,8 @@ public class InitializeCommand : Command openApiSpec, company, output, - addMkDocs); + addMkDocs, + addTests); } private static async Task HandleAsync( @@ -54,7 +60,8 @@ private static async Task HandleAsync( string openApiSpec, string company, string outputPath, - bool addMkDocs) + bool addMkDocs, + bool addTests) { Console.WriteLine("Initializing..."); @@ -90,9 +97,6 @@ private static async Task HandleAsync( H.Resources.src_libs__SolutionName___SolutionName__csproj, H.Resources.src_libs__SolutionName__generate_sh, H.Resources.src_libs_Directory_Build_props, - H.Resources.src_tests_IntegrationTests__SolutionName__IntegrationTests_csproj, - H.Resources.src_tests_IntegrationTests_Tests_cs, - H.Resources.src_tests_IntegrationTests_Tests_Test_cs, }; if (addMkDocs) { @@ -106,6 +110,15 @@ private static async Task HandleAsync( H.Resources.src_helpers_GenerateDocs_Program_cs, }); } + if (addTests) + { + resources.AddRange(new [] + { + H.Resources.src_tests_IntegrationTests__SolutionName__IntegrationTests_csproj, + H.Resources.src_tests_IntegrationTests_Tests_cs, + H.Resources.src_tests_IntegrationTests_Tests_Test_cs, + }); + } foreach (var resource in resources) {