-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Get '$PSVersionTable.PSVersion' from ProductVersion attribute #4863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
52c6bfe to
b87c639
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think GetTypeInfo() is not necessary now.
Another way to get the information version string is:
var infoVersion = typeof(PSVersionInfo).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), inherit: false)
infoVersion.InformationalVersionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetTypeInfo() can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resulting s_psV6Version will look like this: 6.0.0-beta.7 SHA: d2fe36fb4137c2a7d6dbc0df22245d14256f3a74.
I don't think the SHA or Commit info should be put in $PSVersionTable.PSVersion. I'm fine we change it from 6.0.0-beta to 6.0.0-beta.7 though. How about split the information version string to get the 6.0.0-beta.7 part and create the SemanticVersion object with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could try to put the information in another attribute (not ProductVersion) to exclude parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that could be an option if we can find a suitable attribute to store this info.
Splitting the information version string is fine by me too. And plus, we need to split that string anyway to reconstruct the value for GitCommitId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't found a suitable attribute - we are limited by MSBuild's AL task.
Make parsing.
It seems it slightly changes the GitCommitId format for telemetry - we removed final "-dirty".
77e4304 to
0ad4d3d
Compare
|
I rebuilt GitCommitId from formatted one. It looks not very good solution 😕 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't change the existing entries in $PSVersionTable. We should reconstruct the GitCommitId in the exact same format as before. The s_rawGitCommitId shouldn't be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a g before the SHA value when got from git describe:
v6.0.0-beta.7-30-gf1ec922fd93cf833f32d98fcf337a51f2919b6cf
And also, when Commit: is not present, it indicates the build was from a release tag, so SHA shouldn't be put in the GitCommitId in that case, for example, it would be v6.0.0-beta.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't use the formatted string from the attribute directly. CommitId should be in the exact same format as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format could also be 6.0.0-beta.7 SHA: 52c6bfe1eae24dbaa1a162bffb3754ba3fdc1f4c without the Commit count. It's better to mention that too.
How about:
// Get ProductVersion of the assembly. The product version string can be one of the following format examples:
// when powershell is built from a commit -- '6.0.0-beta.7 Commits: 29 SHA: 52c6b...'
// when powershell is built from a release tag -- '6.0.0-beta.7 SHA: f1ec9...'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
PowerShell.Common.props
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to be more specific about what depends on this formatted version string here. How about
Caution! PSVersion and GitCommitId from PSVersionInfo.cs depend on the format of this version string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
build.psm1
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove powershell.version from .gitignore as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetTypeInfo() can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments about the two formats of the product version strings. For example:
// Get ProductVersion of the assembly. The product version string can be one of the following format examples:
// when powershell is built from a commit -- '6.0.0-beta.7 Commits: 29 SHA: 52c6b...'
// when powershell is built from a release tag -- '6.0.0-beta.7 SHA: f1ec9...'
// Convert to '6.0.0-beta.7-29-g52c6bfe1eae24dbaa1a162bffb3754ba3fdc1f4c'.
This is not accurate. When building from a release tag, it should be converted to v6.0.0-beta.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry - I lost the commit.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work when it's built from a release tag. When Commits: is not present, SHA shouldn't be included in the reconstructed GitCommitId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clarify. It seems works as expected:
> "6.0.0-beta.7".Replace(" Commits: ", "-").Replace(" SHA: ", "-g")
6.0.0-beta.7
If it is ok I'd remove rawGitCommitId variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileVersionInfo.ProductVersion will never just be 6.0.0-beta.7. In case of building with a release tag, it will be like this (for beta.7):
PS> $s.VersionInfo.ProductVersion
6.0.0-beta.7 SHA: d2fe36fb4137c2a7d6dbc0df22245d14256f3a74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clarify.
- I see
v6.0.0-beta.7in Beta.7 distributive powershell.version file. In Build.psm1 I see the pattern for ReleaseTag "^v\d+.\d+.\d+(-\w+.\d+)?$". If I run PowerShell I see:
PowerShell v6.0.0-beta.7
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Program Files\PowerShell\6.0.0-beta.7>
-- no SHA have we.
- "6.0.0-beta.7 SHA: d2fe36f".Replace(" Commits: ", "-").Replace(" SHA: ", "-g")
Return: v6.0.0-beta.7-gd2fe36fb4137c2a7d6dbc0df22245d14256f3a74
-- the code works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the $PSVersionTable for beta.7. Note that GitCommitId is v6.0.0-beta.7.
PS:1> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.7
OS Microsoft Windows 10.0.15063
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
The ProductVersion of System.Management.Automation.dll is
PS:6> $s = Get-Item C:\Arena\pscore\System.Management.Automation.dll
PS:7> $s.VersionInfo.ProductVersion
6.0.0-beta.7 SHA: d2fe36fb4137c2a7d6dbc0df22245d14256f3a74
And thus based on your code, GitCommitId will become:
PS> "v" + $s.VersionInfo.ProductVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g")
v6.0.0-beta.7-gd2fe36fb4137c2a7d6dbc0df22245d14256f3a74
and it's obviously not v6.0.0-beta.7.
When building from a release tag, the GitCommitId should be exactly the same as of today when using powershell.version file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the final version should just be v6.0.0. PSVersion="6.0.0-beta.N" is correct. Soon we should have 6.0.0-ReleaseCandidate and if needed, 6.0.0-ReleaseCandidate.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of completely removing the GitCommitId field. I don't mind if it has another name, but it's very useful for our telemetry and understanding how the product is being used and in what way.
I see the GitCommitId and PSVersion being somewhat related, where GitCommitId is the most specific way to refer to the version of powershell being invoked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daxian-dbw
Changing PSVersion to be a proper representation of any possible semantic version shouldn't break our telemetry. IIRC our telemetry is based on the GitCommitID (@SteveL-MSFT will know for sure). In any event, If it (our telemetry) doesn't support semantic versions, I would argue that we need to address that, as we should handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @SteveL-MSFT and @JamesWTruher, appreciate your inputs.
@iSazonov Then let's go with PSVersion= "6.0.0-beta.n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe our telemetry is using GitCommitID and not PSVersion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileVersionInfo.ProductVersion is used 3 times here, so I suggest to hold the value in a local variable instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems versionTable is not used anymore. This line can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
I see TODO comment - currently we can detect that we use 'Release Tag' and automate the name selection. Make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand the intention of this comment. Maybe we should open an issue to track it (fix or remove).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
- When it's building from a release tag,
$PSVersionTable.GitCommitIdwill be likev6.0.0-beta.7and this match operation will fail. - It's better to use
... | Should Match ...
5eaa425 to
35fdb4a
Compare
This reverts commit 8e4b02c00c298e26fc6cac8015a543fb080dc89b.
This reverts commit d3d93f1197d8b00747b2ae654456666cae06836e.
This reverts commit 089e22b9146c89ee9430dcf21594e80c865f3eaf.
35fdb4a to
ad92e3c
Compare
| BeforeAll { | ||
| $powershellProcess=Get-Process -id $pid | ||
| $rootPath = Split-Path -Path $powershellProcess.path -Parent | ||
| $sma = Get-Item (Join-Path $rootPath "System.Management.Automation.dll") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use Join-Path $PSHome System.Management.Automation.dll?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Join-Path returns string. We need FileInfo to get VersionInfo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, I meant using that to replace the existing Join-Path ... so you don't need the get-process and split-path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 Clear.
| It "GitCommitId property" { | ||
| $PSVersionTable.GitCommitId | Should BeOfType "System.String" | ||
| $PSVersionTable.GitCommitId | Should Match $expectedGitCommitIdPattern | ||
| $PSVersionTable.GitCommitId | Should Not Match $unexpectectGitCommitIdPattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This not match test case is not necessary IMO since you are doing a BeExactly comparison below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do two checks - 1. for string values (line below). 2. for regex patterns (this line).
I split regex patterns to check GitCommitId and ReleaseTag cases and keep the patterns simple. The double "Should" is needed because ReleaseTag pattern can pass GitCommitId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the point. It's to guarantee that the reconstructed rawGitCommitId to be in the expected regx pattern. #Close
|
@iSazonov Thanks for the update. It's almost there :) |
|
@daxian-dbw The history is 4 months long - sorry that sometimes I lost the essence of the changes. |
|
@iSazonov finally we get it ready 😄 Thanks! |
|
@daxian-dbw Thank you for review and your patience! |
Resolve #3739.
Resolve #3676.
Fix
Get a formatted product version from ProductVersion attribute.
Assign PSVersionInfo.PSVersion from a formatted product version as '6.0.0-Beta.7'
Assign PSVersionInfo.GitCommitId from a formatted product version as 'v6.0.0-beta.7-37-g0afa5250a...'
Remove dependence on 'powershell.version'.
Improve tests.