forked from pauldotknopf/dotnet-buildary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitVersion.cs
71 lines (55 loc) · 2.27 KB
/
GitVersion.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Runtime.InteropServices.ComTypes;
using Newtonsoft.Json;
using static Build.Buildary.File;
using static Build.Buildary.Path;
namespace Build.Buildary
{
public class GitVersion
{
public static GitVersionResult GetGitVersion(string directory)
{
string output;
// If there exists a version.json in the directory, then gitversion was run by some other means.
output = FileExists(CombinePath(directory, "version.json"))
? ReadFile(CombinePath(directory, "version.json"))
: Shell.ReadShell($"cd {directory} && dotnet gitversion");
dynamic json = JsonConvert.DeserializeObject(output);
var result = new GitVersionResult
{
Version = json.MajorMinorPatch,
VersionMajor = json.Major,
VersionMinor = json.Minor,
VersionPatch = json.Patch,
PreReleaseLabel = json.PreReleaseLabel,
PreReleaseTag = json.PreReleaseTag,
PreReleaseNumber = json.PreReleaseNumber,
AssemblySemVer = json.AssemblySemVer,
InformationalVersion = json.InformationalVersion,
CommitDate = json.CommitDate
};
if(!string.IsNullOrEmpty(result.PreReleaseTag))
{
result.FullVersion = $"{result.Version}-{result.PreReleaseTag}";
}
else
{
result.FullVersion = result.Version;
}
return result;
}
public class GitVersionResult
{
public string Version { get; set; }
public int VersionMajor { get; set; }
public int VersionMinor { get; set; }
public int VersionPatch { get; set; }
public string PreReleaseLabel { get; set; }
public string PreReleaseTag { get; set; }
public string PreReleaseNumber { get; set; }
public string FullVersion { get; set; }
public string AssemblySemVer { get; set; }
public string InformationalVersion { get; set; }
public string CommitDate { get; set; }
}
}
}