Skip to content

Log build info #772

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

Merged
merged 5 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ $script:IsCIBuild = $env:APPVEYOR -ne $null
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
$script:TargetFrameworksParam = "/p:TargetFrameworks=\`"$(if (!$script:IsUnix) { "net451;" })netstandard1.6\`""
$script:SaveModuleSupportsAllowPrerelease = (Get-Command Save-Module).Parameters.ContainsKey("AllowPrerelease")
$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Host", "BuildInfo", "BuildInfo.cs")

if ($PSVersionTable.PSEdition -ne "Core") {
Add-Type -Assembly System.IO.Compression.FileSystem
Expand Down Expand Up @@ -142,6 +143,51 @@ task TestPowerShellApi -If { !$script:IsUnix } {
exec { & $script:dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
}

task CreateBuildInfo -Before Build {
$buildVersion = "<development-build>"
$buildOrigin = "<development>"

# Set build info fields on build platforms
if ($env:APPVEYOR)
{
$buildVersion = $env:APPVEYOR_BUILD_VERSION
$buildOrigin = if ($env:CI) { "AppVeyor CI" } else { "AppVeyor" }
}
elseif ($env:VSTS_BUILD)
Copy link
Member

Choose a reason for hiding this comment

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

Last I checked the VSTS environment variable that's set is TF_BUILD. Do they also set VSTS_BUILD?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We define VSTS_BUILD.

But I just saw that TF_BUILD is defined as well. So probably a good opportunity to remove VSTS_BUILD.

{
$psd1Path = [System.IO.Path]::Combine($PSScriptRoot, "module", "PowerShellEditorServices", "PowerShellEditorServices.psd1")
$buildVersion = (Import-PowerShellDataFile -LiteralPath $psd1Path).Version
$buildOrigin = "VSTS"
Copy link
Member

Choose a reason for hiding this comment

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

Ehhem "Azure Pipelines" 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but felt we should keep things consistent and change it over all at once.

}

# Allow override of build info fields (except date)
if ($env:PSES_BUILD_VERSION)
{
$buildVersion = $env:PSES_BUILD_VERSION
}

if ($env:PSES_BUILD_ORIGIN)
{
$buildOrigin = $env:PSES_BUILD_ORIGIN
}

[string]$buildTime = [datetime]::Now.ToString("s", [System.Globalization.CultureInfo]::InvariantCulture)

$buildInfoContents = @"
namespace Microsoft.PowerShell.EditorServices.Host
{
public static class BuildInfo
{
public const string BuildVersion = "$buildVersion";
public const string BuildOrigin = "$buildOrigin";
public static readonly System.DateTime? BuildTime = System.DateTime.Parse("$buildTime");
}
}
"@

Set-Content -LiteralPath $script:BuildInfoPath -Value $buildInfoContents -Force
}

task Build {
exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -f netstandard1.6 }
if (!$script:IsUnix) {
Expand Down
3 changes: 3 additions & 0 deletions module/PowerShellEditorServices/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ function Set-NamedPipeMode {
}
}

LogSection "Console Encoding"
Log $OutputEncoding

# Add BundledModulesPath to $env:PSModulePath
if ($BundledModulesPath) {
$env:PSModulePath = $env:PSModulePath.TrimEnd([System.IO.Path]::PathSeparator) + [System.IO.Path]::PathSeparator + $BundledModulesPath
Expand Down
9 changes: 9 additions & 0 deletions src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Microsoft.PowerShell.EditorServices.Host
{
public static class BuildInfo
{
public const string BuildVersion = "<unset>";
public const string BuildOrigin = "<unset>";
public static readonly System.DateTime? BuildTime = null;
}
}
60 changes: 32 additions & 28 deletions src/PowerShellEditorServices.Host/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace Microsoft.PowerShell.EditorServices.Host
{
Expand Down Expand Up @@ -140,39 +141,42 @@ public void StartLogging(string logFilePath, LogLevel logLevel)
.Build();

#if CoreCLR
FileVersionInfo fileVersionInfo =
FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location);

// TODO #278: Need the correct dependency package for this to work correctly
//string osVersionString = RuntimeInformation.OSDescription;
//string processArchitecture = RuntimeInformation.ProcessArchitecture == Architecture.X64 ? "64-bit" : "32-bit";
//string osArchitecture = RuntimeInformation.OSArchitecture == Architecture.X64 ? "64-bit" : "32-bit";
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location);
#else
FileVersionInfo fileVersionInfo =
FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location);
string osVersionString = Environment.OSVersion.VersionString;
string processArchitecture = Environment.Is64BitProcess ? "64-bit" : "32-bit";
string osArchitecture = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit";
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location);
#endif

string newLine = Environment.NewLine;

this.logger.Write(
LogLevel.Normal,
string.Format(
$"PowerShell Editor Services Host v{fileVersionInfo.FileVersion} starting (pid {Process.GetCurrentProcess().Id})..." + newLine + newLine +
" Host application details:" + newLine + newLine +
$" Name: {this.hostDetails.Name}" + newLine +
$" ProfileId: {this.hostDetails.ProfileId}" + newLine +
$" Version: {this.hostDetails.Version}" + newLine +
#if !CoreCLR
$" Arch: {processArchitecture}" + newLine + newLine +
" Operating system details:" + newLine + newLine +
$" Version: {osVersionString}" + newLine +
$" Arch: {osArchitecture}"));
#if CoreCLR
string osVersion = RuntimeInformation.OSDescription;
#else
""));
string osVersion = Environment.OSVersion.VersionString;
#endif

string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? "<unspecified>";

string logHeader = $@"
PowerShell Editor Services Host v{fileVersionInfo.FileVersion} starting (PID {Process.GetCurrentProcess().Id}

Host application details:

Name: {this.hostDetails.Name}
Version: {this.hostDetails.Version}
ProfileId: {this.hostDetails.ProfileId}
Arch: {RuntimeInformation.OSArchitecture}

Operating system details:

Version: {osVersion}
Arch: {RuntimeInformation.OSArchitecture}

Build information:

Version: {BuildInfo.BuildVersion}
Origin: {BuildInfo.BuildOrigin}
Date: {buildTime}
";

this.logger.Write(LogLevel.Normal, logHeader);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<PackageReference Include="Microsoft.PowerShell.SDK">
<Version>6.0.0-alpha13</Version>
</PackageReference>
<PackageReference Include="System.Runtime.Extensions" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
Copy link
Member

Choose a reason for hiding this comment

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

Now that we are shipping this, I think there were a couple instances where we did some ifdefs between Core and Framework (which didn't have this package). If it's easy, can you remove the ifdefs

Copy link
Member

Choose a reason for hiding this comment

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

Also don't forget to register the open source usage.

</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
Expand Down