-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add oasfiff download * Moved file check to HttpClientWrapper * Moved RuntimeInformation to a helper class for reusability --------- Co-authored-by: Rushikesh Vyas <[email protected]>
- Loading branch information
Showing
6 changed files
with
103 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Workleap.OpenApi.MSBuild; | ||
|
||
internal interface IOasdiffManager | ||
{ | ||
Task InstallOasdiffAsync(CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace Workleap.OpenApi.MSBuild; | ||
|
||
internal sealed class OasdiffManager : IOasdiffManager | ||
{ | ||
private const string OasdiffVersion = "1.9.2"; | ||
|
||
private readonly IHttpClientWrapper _httpClientWrapper; | ||
private readonly IProcessWrapper _processWrapper; | ||
private readonly string _toolDirectory; | ||
|
||
public OasdiffManager(IProcessWrapper processWrapper, string openApiToolsDirectoryPath, IHttpClientWrapper httpClientWrapper) | ||
{ | ||
this._httpClientWrapper = httpClientWrapper; | ||
this._processWrapper = processWrapper; | ||
this._toolDirectory = Path.Combine(openApiToolsDirectoryPath, "oasdiff", OasdiffVersion); | ||
} | ||
|
||
public async Task InstallOasdiffAsync(CancellationToken cancellationToken) | ||
{ | ||
Directory.CreateDirectory(this._toolDirectory); | ||
|
||
var oasdiffFileName = GetOasdiffFileName(); | ||
var url = $"https://github.com/Tufin/oasdiff/releases/download/v{OasdiffVersion}/{oasdiffFileName}"; | ||
|
||
await this._httpClientWrapper.DownloadFileToDestinationAsync(url, Path.Combine(this._toolDirectory, oasdiffFileName), cancellationToken); | ||
await this.DecompressDownloadedFileAsync(oasdiffFileName, cancellationToken); | ||
} | ||
|
||
private async Task DecompressDownloadedFileAsync(string oasdiffFileName, CancellationToken cancellationToken) | ||
{ | ||
var pathToCompressedFile = Path.Combine(this._toolDirectory, oasdiffFileName); | ||
await this._processWrapper.RunProcessAsync("tar", new[] { "-xzf", $"{pathToCompressedFile}", "-C", $"{this._toolDirectory}" }, cancellationToken); | ||
} | ||
|
||
private static string GetOasdiffFileName() | ||
{ | ||
var osType = RuntimeInformationHelper.GetOperatingSystem(); | ||
var architecture = RuntimeInformationHelper.GetArchitecture("amd"); | ||
|
||
var fileName = $"oasdiff_{OasdiffVersion}_{osType}_{architecture}.tar.gz"; | ||
|
||
if (osType == "macos") | ||
{ | ||
fileName = $"oasdiff_{OasdiffVersion}_darwin_all.tar.gz"; | ||
} | ||
|
||
return fileName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Workleap.OpenApi.MSBuild; | ||
|
||
internal static class RuntimeInformationHelper | ||
{ | ||
internal static string GetOperatingSystem() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
return "linux"; | ||
} | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
return "macos"; | ||
} | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return "windows"; | ||
} | ||
|
||
throw new OpenApiTaskFailedException("Unknown operating system encountered"); | ||
} | ||
|
||
internal static string GetArchitecture(string? prefix = default) | ||
=> RuntimeInformation.OSArchitecture switch | ||
{ | ||
Architecture.X64 => string.IsNullOrEmpty(prefix) ? "x64" : $"{prefix}64", | ||
Architecture.Arm64 => "arm64", | ||
_ => throw new OpenApiTaskFailedException("Unknown processor architecture encountered"), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters