Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDP-818 - Handling running swashbuckle cli with a sdk greater than net7.0 #28

Merged
merged 10 commits into from
Jan 23, 2024
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-dotnet@v4
with:
dotnet-version: "6.0.x"
dotnet-version: "8.0.x"

- run: ./Build.ps1
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-dotnet@v4
with:
dotnet-version: "6.0.x"
dotnet-version: "8.0.x"

- run: ./Build.ps1
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.418",
"version": "8.0.101",
"rollForward": "latestMinor",
"allowPrerelease": false
}
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<PackageProjectUrl>https://github.com/gsoft-inc/wl-openapi-msbuild</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Description>TODO.</Description>
<AnalysisLevel>6.0-all</AnalysisLevel>
<AnalysisLevel>8.0-all</AnalysisLevel>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
3 changes: 2 additions & 1 deletion src/WebApiDebugger/WebApiDebugger.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
Expand All @@ -13,6 +13,7 @@

<PropertyGroup>
<OpenApiDebuggingEnabled>true</OpenApiDebuggingEnabled>
<OpenApiDevelopmentMode>CodeFirst</OpenApiDevelopmentMode>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Workleap.OpenApi.MSBuild/IProcessWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace Workleap.OpenApi.MSBuild;

public interface IProcessWrapper
{
public Task<BufferedCommandResult> RunProcessAsync(string filename, string[] arguments, CancellationToken cancellationToken);
public Task<BufferedCommandResult> RunProcessAsync(string filename, string[] arguments, CancellationToken cancellationToken, Dictionary<string, string?>? envVars = null);
}
4 changes: 3 additions & 1 deletion src/Workleap.OpenApi.MSBuild/ProcessWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ namespace Workleap.OpenApi.MSBuild;
internal sealed class ProcessWrapper : IProcessWrapper
{
private readonly string _workingDirectory;
private readonly Dictionary<string, string?> _defaultEnvVars = new();

public ProcessWrapper(string workingDirectory)
{
this._workingDirectory = workingDirectory;
}

public async Task<BufferedCommandResult> RunProcessAsync(string filename, string[] arguments, CancellationToken cancellationToken)
public async Task<BufferedCommandResult> RunProcessAsync(string filename, string[] arguments, CancellationToken cancellationToken, Dictionary<string, string?>? envVars = null)
{
var result = await Cli.Wrap(filename)
.WithWorkingDirectory(this._workingDirectory)
.WithValidation(CommandResultValidation.None)
.WithArguments(arguments)
.WithEnvironmentVariables(envVars ?? this._defaultEnvVars)
.ExecuteBufferedAsync(cancellationToken);

return result;
Expand Down
10 changes: 7 additions & 3 deletions src/Workleap.OpenApi.MSBuild/SwaggerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ public async Task InstallSwaggerCliAsync(CancellationToken cancellationToken)
{
return;
}

var retryCount = 0;
while (retryCount < 2)
{
var result = await this._processWrapper.RunProcessAsync("dotnet", new[] { "tool", "update", "Swashbuckle.AspNetCore.Cli", "--ignore-failed-sources", "--tool-path", this._swaggerDirectory, "--configfile", Path.Combine(this._openApiToolsDirectoryPath, "nuget.config"), "--version", SwaggerVersion }, cancellationToken);
var result = await this._processWrapper.RunProcessAsync(
"dotnet",
new[] { "tool", "update", "Swashbuckle.AspNetCore.Cli", "--ignore-failed-sources", "--tool-path", this._swaggerDirectory, "--configfile", Path.Combine(this._openApiToolsDirectoryPath, "nuget.config"), "--version", SwaggerVersion },
cancellationToken);

if (result.ExitCode != 0 && retryCount != 1)
{
Expand All @@ -72,7 +75,8 @@ public async Task InstallSwaggerCliAsync(CancellationToken cancellationToken)

public async Task<string> GenerateOpenApiSpecAsync(string swaggerExePath, string outputOpenApiSpecPath, string documentName, CancellationToken cancellationToken)
{
var result = await this._processWrapper.RunProcessAsync(swaggerExePath, new[] { "tofile", "--output", outputOpenApiSpecPath, "--yaml", this._openApiWebApiAssemblyPath, documentName }, cancellationToken: cancellationToken);
var envVars = new Dictionary<string, string?>() { { "DOTNET_ROLL_FORWARD", "LatestMajor" } };
var result = await this._processWrapper.RunProcessAsync(swaggerExePath, new[] { "tofile", "--output", outputOpenApiSpecPath, "--yaml", this._openApiWebApiAssemblyPath, documentName }, cancellationToken: cancellationToken, envVars: envVars);
this._loggerWrapper.LogMessage(result.StandardOutput, MessageImportance.High);

if (result.ExitCode != 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
Expand All @@ -17,5 +16,4 @@
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
Expand Down