forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuildAgentBase.cs
More file actions
54 lines (41 loc) · 1.83 KB
/
Copy pathBuildAgentBase.cs
File metadata and controls
54 lines (41 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.IO.Abstractions;
using GitVersion.Extensions;
using GitVersion.OutputVariables;
namespace GitVersion.Agents;
internal abstract class BuildAgentBase(IEnvironment environment, ILogger logger, IFileSystem fileSystem) : ICurrentBuildAgent
{
protected readonly ILogger Logger = logger.NotNull();
protected readonly IEnvironment environment = environment.NotNull();
protected readonly IFileSystem fileSystem = fileSystem.NotNull();
protected abstract string EnvironmentVariable { get; }
public abstract string? SetBuildNumber(GitVersionVariables variables);
public abstract string[] SetOutputVariables(string name, string? value);
public virtual bool CanApplyToCurrentContext() => !this.environment.GetEnvironmentVariable(EnvironmentVariable).IsNullOrEmpty();
public virtual string? GetCurrentBranch(bool usingDynamicRepos) => null;
public virtual string? GetCurrentTag() => null;
public virtual bool IsDefault => false;
public virtual bool PreventFetch() => true;
public virtual bool ShouldCleanUpRemotes() => false;
public virtual void WriteIntegration(Action<string?> writer, GitVersionVariables variables, bool updateBuildNumber = true)
{
if (updateBuildNumber)
{
writer($"Set Build Number for '{GetType().Name}'.");
writer(SetBuildNumber(variables));
}
writer($"Set Output Variables for '{GetType().Name}'.");
foreach (var buildParameter in SetOutputVariables(variables))
{
writer(buildParameter);
}
}
protected IEnumerable<string> SetOutputVariables(GitVersionVariables variables)
{
var output = new List<string>();
foreach (var (key, value) in variables)
{
output.AddRange(SetOutputVariables(key, value));
}
return output;
}
}