add functionality to PSVersionTable to include GitCommitID and update tests

This commit is contained in:
Jim Truher (MSFT)
2016-05-18 15:35:09 -07:00
parent e0149a10e4
commit cfd5bded5b
4 changed files with 19 additions and 2 deletions
+2
View File
@@ -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
@@ -18,7 +18,8 @@
"content": [
"Modules",
"../Modules",
"powershell.exe"
"powershell.exe",
"../../.version"
],
"frameworks": {
@@ -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.
+2 -1
View File
@@ -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
}