Skip to content

move build agents to a separate lib out of core #3386

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 1 commit into from
Feb 19, 2023
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ src/Docker/**/content
config.wyam.dll
config.wyam.hash
config.wyam.packages.xml
/tests/integration/core/build
/tests/integration/full/build
/tests/integration/build
docs/output

# NPM
Expand Down
2 changes: 1 addition & 1 deletion build/artifacts/Tasks/ArtifactsMsBuildCoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override void Run(BuildContext context)
_ => targetFramework
};

var cmd = $"{rootPrefix}/scripts/test-msbuild-task.sh --version {version} --nugetPath {rootPrefix}/nuget --repoPath {rootPrefix}/repo/tests/integration/core --targetframework {targetFramework}";
var cmd = $"{rootPrefix}/scripts/test-msbuild-task.sh --version {version} --nugetPath {rootPrefix}/nuget --repoPath {rootPrefix}/repo/tests/integration --targetframework {targetFramework}";

context.DockerTestArtifact(dockerImage, cmd);
}
Expand Down
11 changes: 5 additions & 6 deletions build/artifacts/Tasks/ArtifactsMsBuildFullTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ public override void Run(BuildContext context)

var nugetSource = context.MakeAbsolute(Paths.Nuget).FullPath;

context.Information("\nTesting msbuild task with dotnet build (for .net core)\n");
context.Information("\nTesting msbuild task with dotnet build\n");
var frameworks = new[] { Constants.NetVersion60, Constants.NetVersion70 };
foreach (var framework in frameworks)
{
var dotnetMsBuildSettings = new DotNetMSBuildSettings();
dotnetMsBuildSettings.WithProperty("TargetFrameworks", framework);
dotnetMsBuildSettings.WithProperty("TargetFramework", framework);
dotnetMsBuildSettings.SetTargetFramework(framework);
dotnetMsBuildSettings.WithProperty("GitVersionMsBuildVersion", version);
var projPath = context.MakeAbsolute(Paths.Integration.Combine("core"));
var projPath = context.MakeAbsolute(Paths.Integration);

context.DotNetBuild(projPath.FullPath, new DotNetBuildSettings
{
Expand All @@ -40,8 +39,8 @@ public override void Run(BuildContext context)
Sources = new[] { nugetSource }
});

var netcoreExe = Paths.Integration.Combine("core").Combine("build").Combine(framework).CombineWithFilePath("app.dll");
context.ValidateOutput("dotnet", netcoreExe.FullPath, context.Version.GitVersion.FullSemVer);
var exe = Paths.Integration.Combine("build").Combine(framework).CombineWithFilePath("app.dll");
context.ValidateOutput("dotnet", exe.FullPath, context.Version.GitVersion.FullSemVer);
}
}
}
1 change: 1 addition & 0 deletions build/build/Tasks/Package/PackageNuget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static void PackageWithCli(BuildContext context)

// GitVersion.MsBuild, global tool & core
context.DotNetPack("./src/GitVersion.Core", settings);
context.DotNetPack("./src/GitVersion.BuildAgents", settings);

settings.ArgumentCustomization = arg => arg.Append("/p:PackAsTool=true");
context.DotNetPack("./src/GitVersion.App", settings);
Expand Down
2 changes: 1 addition & 1 deletion src/GitTools.Testing/Internal/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void IDisposable.Dispose()
{
try
{
SetErrorMode(this.oldMode);
_ = SetErrorMode(this.oldMode);
}
catch (Exception ex) when (ex is EntryPointNotFoundException or DllNotFoundException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void EmptyOnFetchDisabledBuildServerMeansNoFetchIsTrue()

private class MockBuildAgent : ICurrentBuildAgent
{
public bool IsDefault => false;
public bool CanApplyToCurrentContext() => throw new NotImplementedException();

public void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true) => throw new NotImplementedException();
Expand Down
4 changes: 3 additions & 1 deletion src/GitVersion.App.Tests/Helpers/ProgramFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ProgramFixture(string workingDirectory = "")

this.environment = new TestEnvironment();

Overrides.Add(services =>
WithOverrides(services =>
{
services.AddSingleton(log);
services.AddSingleton(consoleAdapter);
Expand All @@ -46,6 +46,8 @@ public void WithEnv(params KeyValuePair<string, string>[] envs)
}
}

public void WithOverrides(Action<IServiceCollection> action) => Overrides.Add(action);

public Task<ProgramFixtureResult> Run(string arg)
{
var args = arg.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
Expand Down
2 changes: 2 additions & 0 deletions src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Extensions;
using LibGit2Sharp;

namespace GitVersion.App.Tests;
Expand Down Expand Up @@ -166,6 +167,7 @@ private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pu
}

var programFixture = new ProgramFixture(fixture.RepositoryPath);
programFixture.WithOverrides(services => services.AddModule(new GitVersionBuildAgentsModule()));
programFixture.WithEnv(env.ToArray());

var result = await programFixture.Run();
Expand Down
13 changes: 7 additions & 6 deletions src/GitVersion.App/GitVersion.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting"/>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing"/>
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GitVersion.LibGit2Sharp\GitVersion.LibGit2Sharp.csproj"/>
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj"/>
<ProjectReference Include="..\GitVersion.BuildAgents\GitVersion.BuildAgents.csproj" />
<ProjectReference Include="..\GitVersion.LibGit2Sharp\GitVersion.LibGit2Sharp.csproj" />
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="../../docs/input/docs/usage/cli/arguments.md"/>
<EmbeddedResource Include="../../docs/input/docs/usage/cli/arguments.md" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GitVersion.App.Tests"/>
<InternalsVisibleTo Include="GitVersion.App.Tests" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions src/GitVersion.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.BuildAgents;
using GitVersion.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -23,6 +24,7 @@ private IHostBuilder CreateHostBuilder(string[] args) =>
{
services.AddModule(new GitVersionCoreModule());
services.AddModule(new GitVersionLibGit2SharpModule());
services.AddModule(new GitVersionBuildAgentsModule());
services.AddModule(new GitVersionAppModule());

services.AddSingleton(sp =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class AzurePipelinesTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class BitBucketPipelinesTests : TestBase
Expand All @@ -17,8 +16,8 @@ public class BitBucketPipelinesTests : TestBase
public void SetEnvironmentVariableForTest()
{
this.sp = ConfigureServices(services => services.AddSingleton<BitBucketPipelines>());
this.environment = sp.GetRequiredService<IEnvironment>();
this.buildServer = sp.GetRequiredService<BitBucketPipelines>();
this.environment = this.sp.GetRequiredService<IEnvironment>();
this.buildServer = this.sp.GetRequiredService<BitBucketPipelines>();

this.environment.SetEnvironmentVariable(BitBucketPipelines.EnvironmentVariableName, "MyWorkspace");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class BuildKiteTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Logging;
using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class BuildServerBaseTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public sealed class CodeBuildTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class ContinuaCiTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class DroneTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class EnvRunTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class GitHubActionsTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class GitLabCiTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class JenkinsTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class MyGetTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using GitVersion;
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersionCore.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class SpaceAutomationTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using GitVersion.BuildAgents;
using GitVersion.Core.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;

namespace GitVersion.Core.Tests.BuildAgents;
namespace GitVersion.BuildAgents.Tests;

[TestFixture]
public class TeamCityTests : TestBase
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\GitVersion.BuildAgents\GitVersion.BuildAgents.csproj" />
<ProjectReference Include="..\GitVersion.Core.Tests\GitVersion.Core.Tests.csproj" />
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public class BitBucketPipelines : BuildAgentBase

public void WithPropertyFile(string propertiesFileName) => this.file = propertiesFileName;

public override string[] GenerateSetParameterMessage(string name, string value) => new[]
{
$"GITVERSION_{name.ToUpperInvariant()}={value}"
};
public override string[] GenerateSetParameterMessage(string name, string value) => new[] { $"GITVERSION_{name.ToUpperInvariant()}={value}" };

public override void WriteIntegration(Action<string?> writer, VersionVariables variables, bool updateBuildNumber = true)
{
Expand Down Expand Up @@ -59,7 +56,7 @@ public override void WriteIntegration(Action<string?> writer, VersionVariables v
private string? EvaluateEnvironmentVariable(string variableName)
{
var branchName = Environment.GetEnvironmentVariable(variableName);
Log.Info("Evaluating environment variable {0} : {1}", variableName, branchName ?? "(null)");
this.Log.Info("Evaluating environment variable {0} : {1}", variableName, branchName ?? "(null)");
return branchName;
}
}
5 changes: 5 additions & 0 deletions src/GitVersion.BuildAgents/GitVersion.BuildAgents.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion.BuildAgents;

public class BuildServerModule : GitVersionModule
public class GitVersionBuildAgentsModule : GitVersionModule
{
public override void RegisterTypes(IServiceCollection services)
{
Expand All @@ -12,8 +12,5 @@ public override void RegisterTypes(IServiceCollection services)
{
services.AddSingleton(typeof(IBuildAgent), buildAgent);
}

services.AddSingleton<IBuildAgentResolver, BuildAgentResolver>();
services.AddSingleton(sp => sp.GetRequiredService<IBuildAgentResolver>().Resolve());
}
}
1 change: 1 addition & 0 deletions src/GitVersion.BuildAgents/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Loading