Skip to content

Commit

Permalink
ci: Use cli init command in cli tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Sep 11, 2024
1 parent def9d53 commit b1af502
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
37 changes: 12 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > TestProject/TestProject.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Label="Analyzers">
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>All</AnalysisMode>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
</Project>
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
Expand Down
23 changes: 18 additions & 5 deletions src/libs/AutoSDK.CLI/Commands/InitializeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ public class InitializeCommand : Command
aliases: ["--add-mkdocs", "-m"],
getDefaultValue: () => true,
description: "Adds MkDocs to the solution");
var addTests = new Option<bool>(
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,
Expand All @@ -45,7 +50,8 @@ public class InitializeCommand : Command
openApiSpec,
company,
output,
addMkDocs);
addMkDocs,
addTests);
}

private static async Task HandleAsync(
Expand All @@ -54,7 +60,8 @@ private static async Task HandleAsync(
string openApiSpec,
string company,
string outputPath,
bool addMkDocs)
bool addMkDocs,
bool addTests)
{
Console.WriteLine("Initializing...");

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit b1af502

Please sign in to comment.