-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Environment Info away from EnvironmentWrapper
- Loading branch information
1 parent
eb3e257
commit 364e466
Showing
9 changed files
with
167 additions
and
136 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,97 @@ | ||
using Reqnroll.CommonModels; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace Reqnroll.EnvironmentAccess | ||
{ | ||
public class EnvironmentInfoProvider : IEnvironmentInfoProvider | ||
{ | ||
private readonly IEnvironmentWrapper environmentWrapper; | ||
|
||
public EnvironmentInfoProvider(IEnvironmentWrapper environmentWrapper) | ||
{ | ||
this.environmentWrapper = environmentWrapper; | ||
} | ||
|
||
public string GetOSPlatform() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
return "Windows"; | ||
} | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
return "Linux"; | ||
} | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
return "OSX"; | ||
} | ||
|
||
throw new InvalidOperationException("Platform cannot be identified"); | ||
} | ||
|
||
private readonly Dictionary<string, string> buildServerTypes | ||
= new Dictionary<string, string> { | ||
{ "TF_BUILD","Azure Pipelines"}, | ||
{ "TEAMCITY_VERSION","TeamCity"}, | ||
{ "JENKINS_HOME","Jenkins"}, | ||
{ "GITHUB_ACTIONS","GitHub Actions"}, | ||
{ "GITLAB_CI","GitLab CI/CD"}, | ||
{ "CODEBUILD_BUILD_ID","AWS CodeBuild"}, | ||
{ "TRAVIS","Travis CI"}, | ||
{ "APPVEYOR","AppVeyor"}, | ||
{ "BITBUCKET_BUILD_NUMBER", "Bitbucket Pipelines" }, | ||
{ "bamboo_agentId", "Atlassian Bamboo" }, | ||
{ "CIRCLECI", "CircleCI" }, | ||
{ "GO_PIPELINE_NAME", "GoCD" }, | ||
{ "BUDDY", "Buddy" }, | ||
{ "NEVERCODE", "Nevercode" }, | ||
{ "SEMAPHORE", "SEMAPHORE" }, | ||
{ "BROWSERSTACK_USERNAME", "BrowserStack" }, | ||
{ "CF_BUILD_ID", "Codefresh" }, | ||
{ "TentacleVersion", "Octopus Deploy" }, | ||
|
||
{ "CI_NAME", "CodeShip" } | ||
}; | ||
|
||
public string GetBuildServerName() | ||
{ | ||
foreach (var buildServerType in buildServerTypes) | ||
{ | ||
var envVariable = environmentWrapper.GetEnvironmentVariable(buildServerType.Key); | ||
if (envVariable is ISuccess<string>) | ||
return buildServerType.Value; | ||
} | ||
return null; | ||
} | ||
|
||
public bool IsRunningInDockerContainer() | ||
{ | ||
return environmentWrapper.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") is ISuccess<string>; | ||
} | ||
|
||
public string GetReqnrollVersion() | ||
{ | ||
return VersionInfo.AssemblyInformationalVersion; | ||
} | ||
public string GetNetCoreVersion() | ||
{ | ||
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; | ||
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); | ||
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); | ||
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) | ||
{ | ||
return assemblyPath[netCoreAppIndex + 1]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} | ||
} |
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,11 @@ | ||
namespace Reqnroll.EnvironmentAccess | ||
{ | ||
public interface IEnvironmentInfoProvider | ||
{ | ||
string GetOSPlatform(); | ||
string GetBuildServerName(); | ||
bool IsRunningInDockerContainer(); | ||
string GetReqnrollVersion(); | ||
string GetNetCoreVersion(); | ||
} | ||
} |
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
Oops, something went wrong.