From cfd5bded5bda1991bfead87156f0afe2c6e8bfb1 Mon Sep 17 00:00:00 2001 From: "Jim Truher (MSFT)" Date: Wed, 18 May 2016 15:35:09 -0700 Subject: [PATCH] add functionality to PSVersionTable to include GitCommitID and update tests --- PowerShellGitHubDev.psm1 | 2 ++ src/Microsoft.PowerShell.ConsoleHost/project.json | 3 ++- .../engine/PSVersionInfo.cs | 13 +++++++++++++ test/powershell/PSVersionTable.Tests.ps1 | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/PowerShellGitHubDev.psm1 b/PowerShellGitHubDev.psm1 index 71ebbe33a0..3f606f5428 100644 --- a/PowerShellGitHubDev.psm1 +++ b/PowerShellGitHubDev.psm1 @@ -53,6 +53,8 @@ function Start-PSBuild { [string]$msbuildConfiguration = "Release" ) + git describe --dirty --abbrev=60 > "$psscriptroot/.version" + # simplify ParameterSetNames if ($PSCmdlet.ParameterSetName -eq 'FullCLR') { $FullCLR = $true diff --git a/src/Microsoft.PowerShell.ConsoleHost/project.json b/src/Microsoft.PowerShell.ConsoleHost/project.json index d4e1d0b7b6..ff14872157 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/project.json +++ b/src/Microsoft.PowerShell.ConsoleHost/project.json @@ -18,7 +18,8 @@ "content": [ "Modules", "../Modules", - "powershell.exe" + "powershell.exe", + "../../.version" ], "frameworks": { diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs index d8c8f9b2ae..4cbf61fcaa 100644 --- a/src/System.Management.Automation/engine/PSVersionInfo.cs +++ b/src/System.Management.Automation/engine/PSVersionInfo.cs @@ -63,6 +63,7 @@ namespace System.Management.Automation _psVersionTable["PSEdition"] = PSEditionValue; _psVersionTable["CLRVersion"] = Environment.Version; _psVersionTable["BuildVersion"] = GetBuildVersion(); + _psVersionTable["GitCommitId"] = GetCommitInfo(); _psVersionTable["PSCompatibleVersions"] = new Version[] { _psV1Version, _psV2Version, _psV3Version, _psV4Version, _psV5Version, _psV51Version }; _psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion); _psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion; @@ -81,6 +82,18 @@ namespace System.Management.Automation return new Version(buildVersion); } + // Get the commit id from the .version file. If the .version file doesn't exist, use the string "N/A" + static internal string GetCommitInfo() + { + try { + string assemblyPath = IO.Path.GetDirectoryName(typeof(PSVersionInfo).GetTypeInfo().Assembly.Location); + return (IO.File.ReadAllLines(IO.Path.Combine(assemblyPath,".version"))[0]); + } + catch (Exception e){ + return e.Message; + } + } + #region Private helper methods // Gets the current WSMan stack version from the registry. diff --git a/test/powershell/PSVersionTable.Tests.ps1 b/test/powershell/PSVersionTable.Tests.ps1 index f52fbb3b87..baef3db530 100644 --- a/test/powershell/PSVersionTable.Tests.ps1 +++ b/test/powershell/PSVersionTable.Tests.ps1 @@ -1,6 +1,6 @@ Describe "PSVersionTable" { It "Should have version table entries" { - $PSVersionTable.Count | Should Be 8 + $PSVersionTable.Count | Should Be 9 } It "Should have the right version table entries" { @@ -12,6 +12,7 @@ Describe "PSVersionTable" { $PSVersionTable.ContainsKey("BuildVersion") | Should Be True $PSVersionTable.ContainsKey("PSCompatibleVersions") | Should Be True $PSVersionTable.ContainsKey("PSRemotingProtocolVersion") | Should Be True + $PSVersionTable.ContainsKey("GitCommitId") | Should Be True }