Get 'PSVersion' and 'GitCommitId' from the 'ProductVersion' attribute of assembly (#4863)
This commit is contained in:
parent
f83e238082
commit
6e77537181
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -43,9 +43,6 @@ dotnet-uninstall-debian-packages.sh
|
|||
*.pkg
|
||||
*.nupkg
|
||||
|
||||
# ignore the version file as it is generated at build time
|
||||
powershell.version
|
||||
|
||||
# ignore the telemetry semaphore file
|
||||
DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
<PSCoreAdditionalCommits>$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[2].Value)</PSCoreAdditionalCommits>
|
||||
<PSCoreCommitSHA>$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[3].Value)</PSCoreCommitSHA>
|
||||
|
||||
<!--
|
||||
Caution! 'PSVersion' and 'GitCommitId' from 'PSVersionInfo.cs' depend on the format of this version string.
|
||||
-->
|
||||
<PSCoreFormattedVersion Condition = "'$(ReleaseTag)' != '' or '$(PSCoreAdditionalCommits)' == '0'">$(PSCoreBuildVersion) SHA: $(PSCoreCommitSHA)</PSCoreFormattedVersion>
|
||||
<PSCoreFormattedVersion Condition = "'$(PSCoreFormattedVersion)' == ''">$(PSCoreBuildVersion) Commits: $(PSCoreAdditionalCommits) SHA: $(PSCoreCommitSHA)</PSCoreFormattedVersion>
|
||||
|
||||
|
|
|
@ -393,14 +393,6 @@ function Start-PSBuild {
|
|||
}
|
||||
}
|
||||
|
||||
# save git commit id to file for PowerShell to include in PSVersionTable
|
||||
$gitCommitId = $ReleaseTag
|
||||
if (-not $gitCommitId) {
|
||||
# if ReleaseTag is not specified, use 'git describe' to get the commit id
|
||||
$gitCommitId = Get-PSCommitId -WarningAction SilentlyContinue
|
||||
}
|
||||
$gitCommitId > "$psscriptroot/powershell.version"
|
||||
|
||||
# create the telemetry flag file
|
||||
$null = new-item -force -type file "$psscriptroot/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace System.Management.Automation
|
|||
private static Version s_psV4Version = new Version(4, 0);
|
||||
private static Version s_psV5Version = new Version(5, 0);
|
||||
private static Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
|
||||
private static SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, "beta");
|
||||
private static SemanticVersion s_psV6Version;
|
||||
|
||||
/// <summary>
|
||||
/// A constant to track current PowerShell Edition
|
||||
|
@ -57,9 +57,38 @@ namespace System.Management.Automation
|
|||
{
|
||||
s_psVersionTable = new PSVersionHashTable(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
string assemblyPath = typeof(PSVersionInfo).Assembly.Location;
|
||||
string productVersion = FileVersionInfo.GetVersionInfo(assemblyPath).ProductVersion;
|
||||
|
||||
// Get 'GitCommitId' and 'PSVersion' from the 'productVersion' assembly attribute.
|
||||
//
|
||||
// The strings can be one of the following format examples:
|
||||
// when powershell is built from a commit:
|
||||
// productVersion = '6.0.0-beta.7 Commits: 29 SHA: 52c6b...' convert to GitCommitId = 'v6.0.0-beta.7-29-g52c6b...'
|
||||
// PSVersion = '6.0.0-beta.7'
|
||||
// when powershell is built from a release tag:
|
||||
// productVersion = '6.0.0-beta.7 SHA: f1ec9...' convert to GitCommitId = 'v6.0.0-beta.7'
|
||||
// PSVersion = '6.0.0-beta.7'
|
||||
// when powershell is built from a release tag for RTM:
|
||||
// productVersion = '6.0.0 SHA: f1ec9...' convert to GitCommitId = 'v6.0.0'
|
||||
// PSVersion = '6.0.0'
|
||||
string rawGitCommitId;
|
||||
string mainVersion = productVersion.Substring(0, productVersion.IndexOf(' '));
|
||||
|
||||
if (productVersion.Contains(" Commits: "))
|
||||
{
|
||||
rawGitCommitId = "v" + productVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g");
|
||||
}
|
||||
else
|
||||
{
|
||||
rawGitCommitId = "v" + mainVersion;
|
||||
}
|
||||
|
||||
s_psV6Version = new SemanticVersion(mainVersion);
|
||||
|
||||
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psV6Version;
|
||||
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
|
||||
s_psVersionTable[PSGitCommitIdName] = GetCommitInfo();
|
||||
s_psVersionTable[PSGitCommitIdName] = rawGitCommitId;
|
||||
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version };
|
||||
s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
|
||||
s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
|
||||
|
@ -81,20 +110,6 @@ namespace System.Management.Automation
|
|||
return result;
|
||||
}
|
||||
|
||||
// Get the commit id from the powershell.version file. If the powershell.version file doesn't exist, use the string "N/A"
|
||||
internal static string GetCommitInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
string assemblyPath = IO.Path.GetDirectoryName(typeof(PSVersionInfo).GetTypeInfo().Assembly.Location);
|
||||
return (IO.File.ReadAllLines(IO.Path.Combine(assemblyPath, "powershell.version"))[0]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.Message;
|
||||
}
|
||||
}
|
||||
|
||||
#region Private helper methods
|
||||
|
||||
// Gets the current WSMan stack version from the registry.
|
||||
|
@ -826,4 +841,4 @@ namespace System.Management.Automation
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ function Register-PSSessionConfiguration
|
|||
$pluginWsmanRunAsUserPath = [System.IO.Path]::Combine(""WSMan:\localhost\Plugin"", ""$pluginName"", ""RunAsUser"")
|
||||
set-item -WarningAction SilentlyContinue $pluginWsmanRunAsUserPath $runAsCredential -confirm:$false
|
||||
}} catch {{
|
||||
|
||||
|
||||
remove-item (Join-Path WSMan:\localhost\Plugin ""$pluginName"") -recurse -force
|
||||
write-error $_
|
||||
# Do not add anymore clean up code after Write-Error, because if EA=Stop is set by user
|
||||
|
@ -1561,10 +1561,9 @@ else
|
|||
internal static string GetWinrmPluginShellName()
|
||||
{
|
||||
// PowerShell Core uses a versioned directory to hold the plugin
|
||||
Hashtable versionTable = PSVersionInfo.GetPSVersionTable();
|
||||
// TODO: This should be PSVersionInfo.PSVersionName once we get
|
||||
// closer to release. Right now it doesn't support alpha versions.
|
||||
return System.String.Concat("PowerShell.", (string)versionTable["GitCommitId"]);
|
||||
return System.String.Concat("PowerShell.", PSVersionInfo.GitCommitId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1574,10 +1573,9 @@ else
|
|||
internal static string GetWinrmPluginDllPath()
|
||||
{
|
||||
// PowerShell Core uses its versioned directory instead of system32
|
||||
Hashtable versionTable = PSVersionInfo.GetPSVersionTable();
|
||||
// TODO: This should be PSVersionInfo.PSVersionName once we get
|
||||
// closer to release. Right now it doesn't support alpha versions.
|
||||
string pluginDllDirectory = System.IO.Path.Combine("%windir%\\system32\\PowerShell", (string)versionTable["GitCommitId"]);
|
||||
string pluginDllDirectory = System.IO.Path.Combine("%windir%\\system32\\PowerShell", PSVersionInfo.GitCommitId);
|
||||
return System.IO.Path.Combine(pluginDllDirectory, RemotingConstants.PSPluginDLLName);
|
||||
}
|
||||
|
||||
|
@ -2555,7 +2553,7 @@ function Unregister-PSSessionConfiguration
|
|||
return
|
||||
}}
|
||||
}}
|
||||
|
||||
|
||||
$shellsFound++
|
||||
|
||||
$shouldProcessTargetString = $targetTemplate -f $_.Name
|
||||
|
@ -2779,12 +2777,12 @@ function ExtractPluginProperties([string]$pluginDir, $objectToWriteTo)
|
|||
}}
|
||||
|
||||
Get-Details $pluginDir $h
|
||||
|
||||
|
||||
# Workflow is not supported in PowerShell Core. Attempting to load the
|
||||
# assembly results in a FileNotFoundException.
|
||||
if (![System.Management.Automation.Platform]::IsCoreCLR -AND
|
||||
$h[""AssemblyName""] -eq ""Microsoft.PowerShell.Workflow.ServiceCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"") {{
|
||||
|
||||
|
||||
$serviceCore = [Reflection.Assembly]::Load(""Microsoft.Powershell.Workflow.ServiceCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"")
|
||||
|
||||
if ($null -ne $serviceCore) {{
|
||||
|
@ -4967,7 +4965,7 @@ param(
|
|||
}}
|
||||
}}
|
||||
}}
|
||||
|
||||
|
||||
# remove the 'network deny all' tag
|
||||
Get-PSSessionConfiguration -Force:$Force | ForEach-Object {{
|
||||
$sddl = $null
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
|
||||
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
|
||||
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -1,4 +1,27 @@
|
|||
Describe "PSVersionTable" -Tags "CI" {
|
||||
|
||||
BeforeAll {
|
||||
$sma = Get-Item (Join-Path $PSHome "System.Management.Automation.dll")
|
||||
$formattedVersion = $sma.VersionInfo.ProductVersion
|
||||
|
||||
$mainVersionPattern = "(\d+\.\d+\.\d+)(-.+)?"
|
||||
$fullVersionPattern = "^v(\d+\.\d+\.\d+)-(.+)-(\d+)-g(.+)$"
|
||||
|
||||
$expectedPSVersion = ($formattedVersion -split " ")[0]
|
||||
$expectedVersionPattern = "^$mainVersionPattern$"
|
||||
|
||||
if ($formattedVersion.Contains(" Commits: "))
|
||||
{
|
||||
$rawGitCommitId = "v" + $formattedVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g")
|
||||
$expectedGitCommitIdPattern = $fullVersionPattern
|
||||
$unexpectectGitCommitIdPattern = "qwerty"
|
||||
} else {
|
||||
$rawGitCommitId = "v" + ($formattedVersion -split " SHA: ")[0]
|
||||
$expectedGitCommitIdPattern = "^v$mainVersionPattern$"
|
||||
$unexpectectGitCommitIdPattern = $fullVersionPattern
|
||||
}
|
||||
}
|
||||
|
||||
It "Should have version table entries" {
|
||||
$PSVersionTable.Count | Should Be 9
|
||||
}
|
||||
|
@ -15,20 +38,31 @@ Describe "PSVersionTable" -Tags "CI" {
|
|||
$PSVersionTable.ContainsKey("OS") | Should Be True
|
||||
|
||||
}
|
||||
It "GitCommitId property should not contain an error" {
|
||||
$PSVersionTable.GitCommitId | Should not match "powershell.version"
|
||||
|
||||
It "PSVersion property" {
|
||||
$PSVersionTable.PSVersion | Should BeOfType "System.Management.Automation.SemanticVersion"
|
||||
$PSVersionTable.PSVersion | Should BeExactly $expectedPSVersion
|
||||
$PSVersionTable.PSVersion | Should Match $expectedVersionPattern
|
||||
$PSVersionTable.PSVersion.Major | Should Be 6
|
||||
}
|
||||
|
||||
It "GitCommitId property" {
|
||||
$PSVersionTable.GitCommitId | Should BeOfType "System.String"
|
||||
$PSVersionTable.GitCommitId | Should Match $expectedGitCommitIdPattern
|
||||
$PSVersionTable.GitCommitId | Should Not Match $unexpectectGitCommitIdPattern
|
||||
$PSVersionTable.GitCommitId | Should BeExactly $rawGitCommitId
|
||||
}
|
||||
|
||||
It "Should have the correct platform info" {
|
||||
$platform = [String][System.Environment]::OSVersion.Platform
|
||||
[String]$PSVersionTable["Platform"] | Should Be $platform
|
||||
[String]$PSVersionTable["Platform"] | Should Be $platform
|
||||
}
|
||||
|
||||
It "Should have the correct OS info" {
|
||||
if ($IsCoreCLR)
|
||||
{
|
||||
$OSDescription = [String][System.Runtime.InteropServices.RuntimeInformation]::OSDescription
|
||||
[String]$PSVersionTable["OS"] | Should Be $OSDescription
|
||||
[String]$PSVersionTable["OS"] | Should Be $OSDescription
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue