Skip to content

Initial support of Drone #1654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 20, 2019
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
50 changes: 50 additions & 0 deletions src/GitVersionCore.Tests/BuildServers/DroneTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace GitVersionCore.Tests.BuildServers
{
using System;
using GitVersion;
using NUnit.Framework;
using Shouldly;

[TestFixture]
public class DroneTests : TestBase
{
[SetUp]
public void SetUp()
{
Environment.SetEnvironmentVariable("DRONE", "true");
}

[TearDown]
public void TearDown()
{
Environment.SetEnvironmentVariable("DRONE", null);
}

[Test]
public void CanApplyToCurrentContext_ShouldBeTrue_WhenEnvironmentVariableIsSet()
{
// Arrange
var buildServer = new Drone();

// Act
var result = buildServer.CanApplyToCurrentContext();

// Assert
result.ShouldBeTrue();
}

[Test]
public void CanApplyToCurrentContext_ShouldBeFalse_WhenEnvironmentVariableIsNotSet()
{
// Arrange
Environment.SetEnvironmentVariable("DRONE", "");
var buildServer = new Drone();

// Act
var result = buildServer.CanApplyToCurrentContext();

// Assert
result.ShouldBeFalse();
}
}
}
3 changes: 2 additions & 1 deletion src/GitVersionCore/BuildServers/BuildServerList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GitVersion
namespace GitVersion
{
using System;
using System.Collections.Generic;
Expand All @@ -16,6 +16,7 @@ public static class BuildServerList
new VsoAgent(),
new TravisCI(),
new EnvRun(),
new Drone()
};

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

public class Drone : BuildServerBase
{
public override bool CanApplyToCurrentContext()
{
return Environment.GetEnvironmentVariable("DRONE")?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false;
}

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

public override string[] GenerateSetParameterMessage(string name, string value)
{
return new[]
{
$"GitVersion_{name}={value}"
};
}

public override string GetCurrentBranch(bool usingDynamicRepos)
{
return Environment.GetEnvironmentVariable("DRONE_BRANCH");
}
}
}