-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-version.cake
53 lines (44 loc) · 1.63 KB
/
build-version.cake
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
public class BuildVersion
{
public GitVersion GitVersionInfo { get; private set; }
public string Milestone {get;private set;}
public string CakeVersion { get; private set; }
public static BuildVersion Calculate(ICakeContext context, BuildParameters parameters)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.Information("Calculating Semantic Version");
if (!parameters.IsLocalBuild)
{
context.GitVersion(new GitVersionSettings{
OutputType = GitVersionOutput.BuildServer
});
}
GitVersion assertedVersions = context.GitVersion(new GitVersionSettings
{
OutputType = GitVersionOutput.Json,
});
context.Information("Calculated Semantic Version: {0}", assertedVersions.LegacySemVerPadded);
var cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString();
return new BuildVersion
{
GitVersionInfo = assertedVersions,
Milestone = string.Concat("v", assertedVersions.NuGetVersion),
CakeVersion = cakeVersion
};
}
public bool IsDevelopment
{
get { return GitVersionInfo.BranchName.Equals("develop", StringComparison.CurrentCultureIgnoreCase); }
}
public bool IsBeta
{
get { return GitVersionInfo.BranchName.StartsWith("release", StringComparison.CurrentCultureIgnoreCase); }
}
public bool IsProduction
{
get { return GitVersionInfo.BranchName.Equals("master", StringComparison.CurrentCultureIgnoreCase); }
}
}