diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-28 07:23:51 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-12-28 07:23:51 -0800 |
commit | 66a722ac805f822dbfb4f5d1b76b315b426b9e26 (patch) | |
tree | 045321a0ceb819844c5a331474bb08ec0ecb5e4a /src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs | |
parent | 6050732e725c68b83c35c873ff8808dff1c406e1 (diff) | |
download | DotNetOpenAuth-66a722ac805f822dbfb4f5d1b76b315b426b9e26.zip DotNetOpenAuth-66a722ac805f822dbfb4f5d1b76b315b426b9e26.tar.gz DotNetOpenAuth-66a722ac805f822dbfb4f5d1b76b315b426b9e26.tar.bz2 |
Builds now include the git commit ID in the PE file header so we have a definite record of where a build came from.
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs')
-rw-r--r-- | src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs b/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs index e40eb78..f046738 100644 --- a/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs +++ b/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs @@ -16,16 +16,29 @@ namespace DotNetOpenAuth.BuildTasks { public string Version { get; private set; } /// <summary> + /// Gets the Git revision control commit id for HEAD (the current source code version). + /// </summary> + [Output] + public string GitCommitId { get; private set; } + + /// <summary> /// The file that contains the version base (Major.Minor.Build) to use. /// </summary> [Required] public string VersionFile { get; set; } + /// <summary> + /// Gets or sets the parent directory of the .git directory. + /// </summary> + public string GitRepoRoot { get; set; } + public override bool Execute() { try { Version typedVersion = ReadVersionFromFile(); typedVersion = new Version(typedVersion.Major, typedVersion.Minor, typedVersion.Build, CalculateJDate(DateTime.Now)); Version = typedVersion.ToString(); + + this.GitCommitId = GetGitHeadCommitId(); } catch (ArgumentOutOfRangeException ex) { Log.LogErrorFromException(ex); return false; @@ -34,6 +47,27 @@ namespace DotNetOpenAuth.BuildTasks { return true; } + private string GetGitHeadCommitId() { + if (string.IsNullOrEmpty(this.GitRepoRoot)) { + return string.Empty; + } + + string headContent = string.Empty; + try { + headContent = File.ReadAllText(Path.Combine(this.GitRepoRoot, @".git/HEAD")).Trim(); + if (headContent.StartsWith("ref:", StringComparison.Ordinal)) { + string refName = headContent.Substring(5).Trim(); + headContent = File.ReadAllText(Path.Combine(this.GitRepoRoot, @".git/" + refName)).Trim(); + } + } catch (FileNotFoundException) { } + + if (string.IsNullOrEmpty(headContent)) { + Log.LogWarning("Unable to determine the git HEAD commit ID to use for informational version number."); + } + + return headContent.Trim(); + } + private Version ReadVersionFromFile() { string[] lines = File.ReadAllLines(VersionFile); string versionLine = lines[0]; |