Skip to content

Commit 42a0a99

Browse files
authored
add BuildServerDetector (#11)
1 parent 2098053 commit 42a0a99

5 files changed

Lines changed: 93 additions & 8 deletions

File tree

readme.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Support is available via [Tidelift](https://tidelift.com/subscription/pkg/nuget-
2828
* [Launching a tool](#launching-a-tool)
2929
* [Closing a tool](#closing-a-tool)
3030
* [File type detection](#file-type-detection)
31+
* [BuildServerDetector](#buildserverdetector)
3132
* [Security contact information](#security-contact-information)<!-- endtoc -->
3233
* [Tools](/docs/diff-tool.md) <!-- include: doc-index. path: /docs/mdsource/doc-index.include.md -->
3334
* [Tool Order](/docs/diff-tool.order.md)
@@ -92,12 +93,26 @@ Note that this method will respect the above [difference behavior](/docs/diff-to
9293

9394
## File type detection
9495

95-
DiffEngine use [EmptyFiles](https://github.com/SimonCropp/EmptyFiles) to determineif a given file or extension is a binary or text.
96+
DiffEngine use [EmptyFiles](https://github.com/SimonCropp/EmptyFiles) to determine if a given file or extension is a binary or text.
97+
98+
99+
## BuildServerDetector
100+
101+
`BuildServerDetector.Detected` returns true if the current code is running on a build/CI server.
102+
103+
Supports:
104+
105+
* [AppVeyor](https://www.appveyor.com/docs/environment-variables/)
106+
* [Travis](https://docs.travis-ci.com/user/environment-variables/#default-environment-variables)
107+
* [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables)
108+
* [GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables)
109+
* [AzureDevops](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#agent-variables)
110+
* [TeamCity](https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#PredefinedBuildParameters-ServerBuildProperties)
96111

97112

98113
## Security contact information
99114

100-
To report a security vulnerability, use the [Tidelift security contact](https://tidelift.com/security).Tidelift will coordinate the fix and disclosure.
115+
To report a security vulnerability, use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
101116

102117

103118
## Icon

readme.source.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,26 @@ Note that this method will respect the above [difference behavior](/docs/diff-to
4747

4848
## File type detection
4949

50-
DiffEngine use [EmptyFiles](https://github.com/SimonCropp/EmptyFiles) to determineif a given file or extension is a binary or text.
50+
DiffEngine use [EmptyFiles](https://github.com/SimonCropp/EmptyFiles) to determine if a given file or extension is a binary or text.
51+
52+
53+
## BuildServerDetector
54+
55+
`BuildServerDetector.Detected` returns true if the current code is running on a build/CI server.
56+
57+
Supports:
58+
59+
* [AppVeyor](https://www.appveyor.com/docs/environment-variables/)
60+
* [Travis](https://docs.travis-ci.com/user/environment-variables/#default-environment-variables)
61+
* [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables)
62+
* [GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables)
63+
* [AzureDevops](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#agent-variables)
64+
* [TeamCity](https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#PredefinedBuildParameters-ServerBuildProperties)
5165

5266

5367
## Security contact information
5468

55-
To report a security vulnerability, use the [Tidelift security contact](https://tidelift.com/security).Tidelift will coordinate the fix and disclosure.
69+
To report a security vulnerability, use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
5670

5771

5872
## Icon
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
3+
namespace DiffEngine
4+
{
5+
public static class BuildServerDetector
6+
{
7+
static BuildServerDetector()
8+
{
9+
// Appveyor
10+
// https://www.appveyor.com/docs/environment-variables/
11+
// Travis
12+
// https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
13+
if (string.Equals(Environment.GetEnvironmentVariable("CI"), "true", StringComparison.OrdinalIgnoreCase))
14+
{
15+
Detected = true;
16+
return;
17+
}
18+
19+
// Jenkins
20+
// https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables
21+
if (Environment.GetEnvironmentVariable("JENKINS_URL") != null)
22+
{
23+
Detected = true;
24+
return;
25+
}
26+
27+
// GitHub Action
28+
// https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables
29+
if (Environment.GetEnvironmentVariable("GITHUB_ACTION") != null)
30+
{
31+
Detected = true;
32+
return;
33+
}
34+
35+
// AzureDevops
36+
// https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#agent-variables
37+
// Variable name is 'Agent.Id' but must be referenced with an underscore
38+
// https://docs.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=powershell#using-default-variables
39+
if (Environment.GetEnvironmentVariable("Agent_Id") != null)
40+
{
41+
Detected = true;
42+
return;
43+
}
44+
45+
// TeamCity
46+
// https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#PredefinedBuildParameters-ServerBuildProperties
47+
if (Environment.GetEnvironmentVariable("teamcity") != null)
48+
{
49+
Detected = true;
50+
}
51+
}
52+
53+
public static bool Detected { get; set; }
54+
}
55+
}

src/DiffEngine/ProcessCleanup.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ static ProcessCleanup()
2121

2222
public static void Refresh()
2323
{
24-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
24+
if (BuildServerDetector.Detected ||
25+
!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
2526
{
26-
commands = FindAll().ToList();
27+
commands = new List<ProcessCommand>();
2728
}
2829
else
2930
{
30-
commands = new List<ProcessCommand>();
31+
commands = FindAll().ToList();
3132
}
3233
}
3334

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649</NoWarn>
5-
<Version>2.0.5</Version>
5+
<Version>2.1.0</Version>
66
<AssemblyVersion>1.0.0.0</AssemblyVersion>
77
<PackageTags>Json, Testing, Verify, Snapshot, Approvals</PackageTags>
88
<Description>Enables simple verification of complex models and documents.</Description>

0 commit comments

Comments
 (0)