-
Notifications
You must be signed in to change notification settings - Fork 7.6k
$PSVersionTable.GitCommitId based on generated constant #3690
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
0c8b5c6
to
5dabec4
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.
Maybe in another PR, or this one if you prefer, but it would be nice to also include the commit hash in the version info similar to what the clr does:
@ C:\Program Files\PowerShell\6.0.0-alpha.18
#293 PS> (dir .\System.Collections.dll).VersionInfo.ProductVersion
4.6.24705.01. Commit Hash: 4d1af962ca0fede10beb01d197367c2f90e92c97
build.psm1
Outdated
@@ -158,7 +158,30 @@ function Start-PSBuild { | |||
} | |||
|
|||
# save Git description to file for PowerShell to include in PSVersionTable | |||
git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60 > "$psscriptroot/powershell.version" | |||
$powershellVersion = git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60 | |||
$powershellVersion > "$PSScriptRoot/powershell.version" |
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 should stop generating this 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.
I use the file in a test. Can we leave the file in repo but exclude it from release and publish?
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 see that file being used in any tests. i do see the string powershell.version
in a test, but it sort of looks like a broken test to me.
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, it is a broken test and I added a fix in the PR.
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. It might be fine if you generated the file alongside other test artifacts, but I would not create it in $PSHome
.
@lzybkr Please clarify - currently |
I'm always a fan of better formatting. I suggest reading the documentation on Note that the |
We would parse the long formatted "git describe" and output in the desired form, ex.: |
Sounds good, though I would omit |
@lzybkr I see #2671 Should we fix the script here? If yes how can we fix this? Can we use there /cc @mirichmo |
I added commit to fix #3739 |
@iSazonov thanks for fixing this. The hard-coded
Some of those files are not updated in this PR. I think all appearances of |
This is the third conflict over the past 24 hours in build.psm1 😄 - I'll resolve tomorrow. I use I'm afraid that I won't be able to fix build.sh - can I delegate this anybody? |
@@ -18,7 +18,9 @@ Describe "PSVersionTable" -Tags "CI" { | |||
|
|||
} | |||
It "GitCommitId property should not contain an error" { | |||
$PSVersionTable.GitCommitId | Should not match "powershell.version" | |||
$powershellVersionFile = Join-Path -Path $PSScriptRoot -ChildPath "assets/powershell.version" |
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 sure if this test is really useful. The content contained in powershell.version
is guaranteed (by the build script) to be the same as in PSVersionInfo.generated.cs
. The only possible failure I can see for this test is that we are running tests outside of where powershell was being built and thus powershell.vesrion
is not available.
I believe it's more useful to check if both GitCommitId
and PSVersion
are nonempty and GitCommitId
starts with PSVersion
, or something like 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 tried to do the test with direct checking. It seems indirect validation will catch a bug too.
Fixed.
build.psm1
Outdated
# temporary hack to resolve the version issue | ||
"v6.0.0-beta.1" > "$psscriptroot/powershell.version" | ||
$null = New-Item -Path "$PSScriptRoot\src\System.Management.Automation" -Name "gen" -ItemType Directory -ErrorAction SilentlyContinue | ||
Set-Content -Path "$PSScriptRoot\src\System.Management.Automation\gen\PSVersionInfo.generated.cs" -Value $template |
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 section should be moved to a separate function (better to make the function invisible from outside the module, but not required) so that Start-PSBuild
won't keep expanding its size 😄
And also, move the call to that function after we check/do ResGen, so that the System.Management.Automation\gen
folder is guaranteed to exist and the New-Item
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.
Fixed.
@iSazonov Sorry that I have to change As for I'm not sure how many people are using build.sh honestly, and not really sure if this worth the effort. |
appveyor temporaryly failed - I restart. |
I only fix but don't test 'Install-PowerShellRemoting.ps1'. |
This is exactly what we use. Used to use GitVersion but now we're doing our own computation of build metadata:
And we do use git to get the SHA1, branch, etc. This is the function we use: function GetGitBuildMetadata([string]$SemVer, [string]$Revision) {
$timestamp = Get-Date -Format yyyyMMddTHHmm
$sha1 = git rev-parse --verify HEAD
$branch = git rev-parse --abbrev-ref HEAD
if (!$branch -or ($branch -eq 'HEAD')) {
if ($env:BUILD_SOURCEBRANCH) {
$branch = $env:BUILD_SOURCEBRANCH.Trim().Replace("refs/heads/", "").Replace("refs/","")
}
else {
$branch = 'unknown'
}
}
$prereleaseTag = if ($branch -notmatch 'master|release') { '-prerelease' } else { '' }
$metadata = "${SemVer}${prereleaseTag}+${Revision}.Branch.${branch}.Sha.${sha1}.Built.${timestamp}"
$metadata
} |
Closed the PR by accident 🤕 |
@daxian-dbw GetVersion isn't still ported 😕 GitTools/GitVersion#1175 |
@daxian-dbw I don't believe that tampering with version attributes of a file by itself is a security concern, since are many other ways of file tampering for malicious purposes. The way to guard against file tampering is with application white listing (and black listing for deprecated versions) where approved file versions are validated through file signing or catalog signing. |
I took the next step. Now all projects have common properties and assemblies get version from Start-PSBuild. |
This PR is getting too complex, and I think we'd better break it down.
We need to draw to a conclusion first to know what work items would be. Then we break down the work items so that they can be addressed in multiple PRs, instead of one PR with too many changes. I vote for NO.3 proposal. @lzybkr @iSazonov please share your opinions. |
In brief I agree with NO.3 Perhaps we should create a Meta Issue to split the work on small pieces:
|
Generate C# file with a constant containing current version GitCommitId. Correct test for GitCommitId.
+ Format GitCommitId version string
Fix Install-PowerShellRemoting.ps1 Fix test Fix build.psm1
if ($($matchVersion[1]) -ne "0") { | ||
$Global:formattedVersion += " Additional commits: $($matchVersion[2])" | ||
} | ||
$Global:formattedVersion += " Commit Hash: $($matchVersion[3])" |
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.
@JamesWTruher the telemetry you're receiving is from @iSazonov running a build of PowerShell with this (not yet committed to master) change.
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 new version string format breaks our telemetry. I'm not really sure that the additional data provides more benefit. Is is possible to go back to the original format?
@@ -150,6 +150,42 @@ function Start-PSBuild { | |||
Stop-Process -Verbose | |||
} | |||
|
|||
# Generate version constant for $PSVersionTable |
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 change in formatting breaks our telemetry
The PR shouldn't be merged - it is only for tracking multiple changes. We split the PR on some light-weight PRs. @lzybkr @daxian-dbw Could you please comment? How can we resolve the conflict with telemetry? |
The work is covered b #4863. So close this PR. |
Resolve #3676
Fix #3739
Generate C# file with a constant containing current version GitCommitId.
Correct a test for GitCommitId.