Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Sep 19, 2017

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.

@iSazonov iSazonov requested a review from daxian-dbw September 19, 2017 09:18
@iSazonov iSazonov force-pushed the GitCommitId branch 2 times, most recently from 52c6bfe to b87c639 Compare September 19, 2017 13:33
@iSazonov iSazonov changed the title Get '$PSVersionTable.PSVersion' and '$PSVersionTable.GitCommitId' from ProductVersion attribute Get '$PSVersionTable.PSVersion' from ProductVersion attribute Sep 19, 2017
@daxian-dbw
Copy link
Member

Thanks @iSazonov! Can we close #3690 now?

Copy link
Member

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.InformationalVersion

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetTypeInfo() can be removed.

Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

@daxian-dbw daxian-dbw Sep 19, 2017

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.

Copy link
Collaborator Author

@iSazonov iSazonov Sep 20, 2017

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".

@iSazonov
Copy link
Collaborator Author

I rebuilt GitCommitId from formatted one. It looks not very good solution 😕
Currently $PSVersionTable show formatted GitCommitId and internally we use a rebuilt GitCommitId (raw).
We can use raw GitCommitId in $PSVersionTable but it seems we want user friendly formatted GitCommitId there.
Or maybe refactor and add explicitly FormattedGitCommitId and RawGitCommitId (or GitCommitIdFormatted and GitCommitIdRaw) in $PSVersionTable?

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

Copy link
Member

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...'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

build.psm1 Outdated
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetTypeInfo() can be removed.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

@iSazonov iSazonov Sep 22, 2017

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.

Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clarify.

  1. I see v6.0.0-beta.7 in 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.

  1. "6.0.0-beta.7 SHA: d2fe36f".Replace(" Commits: ", "-").Replace(" SHA: ", "-g")
    Return: v6.0.0-beta.7-gd2fe36fb4137c2a7d6dbc0df22245d14256f3a74
    -- the code works as expected.

Copy link
Member

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.

Copy link
Member

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

Copy link
Collaborator

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

Copy link
Collaborator

@JamesWTruher JamesWTruher Sep 26, 2017

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

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).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. When it's building from a release tag, $PSVersionTable.GitCommitId will be like v6.0.0-beta.7 and this match operation will fail.
  2. It's better to use ... | Should Match ...

BeforeAll {
$powershellProcess=Get-Process -id $pid
$rootPath = Split-Path -Path $powershellProcess.path -Parent
$sma = Get-Item (Join-Path $rootPath "System.Management.Automation.dll")
Copy link
Member

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?

Copy link
Collaborator Author

@iSazonov iSazonov Sep 28, 2017

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.

Copy link
Member

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.

Copy link
Collaborator Author

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
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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

@daxian-dbw
Copy link
Member

@iSazonov Thanks for the update. It's almost there :)

@iSazonov
Copy link
Collaborator Author

@daxian-dbw The history is 4 months long - sorry that sometimes I lost the essence of the changes.

@daxian-dbw
Copy link
Member

@iSazonov finally we get it ready 😄 Thanks!

@iSazonov
Copy link
Collaborator Author

@daxian-dbw Thank you for review and your patience!

@daxian-dbw daxian-dbw merged commit 6e77537 into PowerShell:master Sep 28, 2017
@iSazonov iSazonov deleted the GitCommitId branch September 28, 2017 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants