Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/GitVersionCore.Tests/BuildServers/EnvRunTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.IO;
using GitVersion;
using GitVersionCore.Tests;
using NUnit.Framework;
using Shouldly;

[TestFixture]
public class EnvRunTests : TestBase
{
private const string EnvVarName = "ENVRUN_DATABASE";
private string mFilePath;

[SetUp]
public void SetEnvironmentVariableForTest()
{
// set environment variable and create an empty envrun file to indicate that EnvRun is running...
mFilePath = Path.Combine(Path.GetTempPath(), "envrun.db");
Environment.SetEnvironmentVariable(EnvVarName, mFilePath, EnvironmentVariableTarget.Process);
File.OpenWrite(mFilePath).Dispose();
}

[TearDown]
public void ClearEnvironmentVariableForTest()
{
Environment.SetEnvironmentVariable(EnvVarName, null, EnvironmentVariableTarget.Process);
File.Delete(mFilePath);
}

[Test]
public void CanApplyToCurrentContext()
{
EnvRun envrun = new EnvRun();
bool applys = envrun.CanApplyToCurrentContext();
applys.ShouldBeTrue();
}

[Test]
public void CanApplyToCurrentContext_EnvironmentVariableNotSet()
{
Environment.SetEnvironmentVariable(EnvVarName, null, EnvironmentVariableTarget.Process);
EnvRun envrun = new EnvRun();
bool applys = envrun.CanApplyToCurrentContext();
applys.ShouldBeFalse();
}

[TestCase("1.2.3")]
[TestCase("1.2.3-rc4")]
public void GenerateSetVersionMessage(string fullSemVer)
{
EnvRun envrun = new EnvRun();
var vars = new TestableVersionVariables(fullSemVer: fullSemVer);
var version = envrun.GenerateSetVersionMessage(vars);
version.ShouldBe(fullSemVer);
}

[TestCase("Version", "1.2.3", "@@envrun[set name='GitVersion_Version' value='1.2.3']")]
[TestCase("Version", "1.2.3-rc4", "@@envrun[set name='GitVersion_Version' value='1.2.3-rc4']")]
public void GenerateSetParameterMessage(string name, string value, string expected)
{
EnvRun envrun = new EnvRun();
var output = envrun.GenerateSetParameterMessage(name, value);
output.ShouldHaveSingleItem();
output[0].ShouldBe(expected);
}

}
1 change: 1 addition & 0 deletions src/GitVersionCore/BuildServers/BuildServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static class BuildServerList
new GitLabCi(),
new VsoAgent(),
new TravisCI(),
new EnvRun(),
};

public static IEnumerable<IBuildServer> GetApplicableBuildServers()
Expand Down
44 changes: 44 additions & 0 deletions src/GitVersionCore/BuildServers/EnvRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace GitVersion
{
using System;
using System.IO;

public class EnvRun : BuildServerBase
{
public override bool CanApplyToCurrentContext()
{
string envRunDatabasePath = Environment.GetEnvironmentVariable("ENVRUN_DATABASE");
if (!string.IsNullOrEmpty(envRunDatabasePath))
{
if (!File.Exists(envRunDatabasePath))
{
Logger.WriteError(string.Format("The database file of EnvRun.exe was not found at {0}.", envRunDatabasePath));
return false;
}

return true;
}

return false;
}

public override string GenerateSetVersionMessage(VersionVariables variables)
{
return variables.FullSemVer;
}

public override string[] GenerateSetParameterMessage(string name, string value)
{
return new[]
{
string.Format("@@envrun[set name='GitVersion_{0}' value='{1}']", name, value)
};
}

public override bool PreventFetch()
{
return true;
}

}
}