-
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.
[idp-1511] Support updating spectral without ejecting (#59)
* Working stades * Refactor * Fixing bugs, remaining cleanup * Cleanup * Missing document * Cleanup in system test * Add debugging logs * Put back incremental build * Try pinpoint problem source * Try addig a nuget.config * Cleanup * Revert blind fix-try * Fix targets * Cleanup * CR fixes * Add unit test for RulesetManager * Fix sealed --------- Co-authored-by: Mathieu Gamache <[email protected]>
- Loading branch information
1 parent
f90150d
commit 8cd45bb
Showing
28 changed files
with
594 additions
and
176 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
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 @@ | ||
extends: [https://raw.githubusercontent.com/gsoft-inc/wl-api-guidelines/0.1.0/.spectral.yaml] |
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
This file was deleted.
Oops, something went wrong.
13 changes: 8 additions & 5 deletions
13
...OpenApi.MSBuild/SpectralDiffCalculator.cs → ...penApi.MSBuild/Spectral/DiffCalculator.cs
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
66 changes: 66 additions & 0 deletions
66
src/Workleap.OpenApi.MSBuild/Spectral/SpectralInstaller.cs
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,66 @@ | ||
namespace Workleap.OpenApi.MSBuild.Spectral; | ||
|
||
internal class SpectralInstaller | ||
{ | ||
private const string SpectralVersion = "6.11.0"; | ||
private const string SpectralDownloadUrlFormat = "https://github.com/stoplightio/spectral/releases/download/v{0}/{1}"; | ||
|
||
private readonly ILoggerWrapper _loggerWrapper; | ||
private readonly IHttpClientWrapper _httpClientWrapper; | ||
private readonly string _spectralDirectory; | ||
|
||
public SpectralInstaller( | ||
ILoggerWrapper loggerWrapper, | ||
string openApiToolsDirectoryPath, | ||
IHttpClientWrapper httpClientWrapper) | ||
{ | ||
this._loggerWrapper = loggerWrapper; | ||
this._httpClientWrapper = httpClientWrapper; | ||
this._spectralDirectory = Path.Combine(openApiToolsDirectoryPath, "spectral", SpectralVersion); | ||
} | ||
|
||
/// <summary> | ||
/// Install spectral tool | ||
/// </summary> | ||
/// <returns>Return executable path</returns> | ||
public async Task<string> InstallSpectralAsync(CancellationToken cancellationToken) | ||
{ | ||
this._loggerWrapper.LogMessage("Starting Spectral installation."); | ||
|
||
Directory.CreateDirectory(this._spectralDirectory); | ||
|
||
var executablePath = GetSpectralFileName(); | ||
var url = string.Format(SpectralDownloadUrlFormat, SpectralVersion, executablePath); | ||
var destination = Path.Combine(this._spectralDirectory, executablePath); | ||
|
||
await this._httpClientWrapper.DownloadFileToDestinationAsync(url, destination, cancellationToken); | ||
|
||
this._loggerWrapper.LogMessage("Spectral installation completed."); | ||
|
||
return executablePath; | ||
} | ||
|
||
private static string GetSpectralFileName() | ||
{ | ||
var osType = RuntimeInformationHelper.GetOperatingSystem(); | ||
var architecture = RuntimeInformationHelper.GetArchitecture(); | ||
|
||
if (osType == "linux") | ||
{ | ||
var distro = File.Exists("/etc/os-release") ? File.ReadAllText("/etc/os-release") : string.Empty; | ||
if (distro.Contains("Alpine Linux")) | ||
{ | ||
osType = "alpine"; | ||
} | ||
} | ||
|
||
var fileName = $"spectral-{osType}-{architecture}"; | ||
|
||
if (osType == "windows") | ||
{ | ||
fileName = "spectral.exe"; | ||
} | ||
|
||
return fileName; | ||
} | ||
} |
Oops, something went wrong.