From 5aa96839a892457fe3720c0fd69e86d8821aa0b8 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov <47745270+al-cheb@users.noreply.github.com> Date: Fri, 27 Aug 2021 09:38:18 +0300 Subject: [PATCH] [Windows] win: add validation InstalledSoftware.md and testResults.xml files (#3960) * win: add validation InstalledSoftware.md file --- .../win/scripts/ImageHelpers/InstallHelpers.ps1 | 2 +- images/win/scripts/ImageHelpers/TestsHelpers.ps1 | 4 ++++ .../SoftwareReport/SoftwareReport.Android.psm1 | 2 +- .../SoftwareReport/SoftwareReport.Tools.psm1 | 3 +-- .../SoftwareReport.WebServers.psm1 | 4 ++-- images/win/scripts/Tests/Nginx.Tests.ps1 | 2 +- images/win/windows2016.json | 12 ++++++++++++ images/win/windows2019.json | 16 ++++++++++++++-- images/win/windows2022.json | 16 ++++++++++++++-- 9 files changed, 50 insertions(+), 11 deletions(-) diff --git a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 index 30f08c97..ececdce8 100644 --- a/images/win/scripts/ImageHelpers/InstallHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/InstallHelpers.ps1 @@ -439,7 +439,7 @@ function Get-AndroidPackages { [string]$AndroidSDKManagerPath ) - return (& $AndroidSDKManagerPath --list --verbose).Trim() | Foreach-Object { $_.Split()[0] } | Where-Object {$_} + return (cmd /c "$AndroidSDKManagerPath --list --verbose 2>&1").Trim() | Foreach-Object { $_.Split()[0] } | Where-Object {$_} } function Get-AndroidPackagesByName { diff --git a/images/win/scripts/ImageHelpers/TestsHelpers.ps1 b/images/win/scripts/ImageHelpers/TestsHelpers.ps1 index 9cbfb1ba..fcc9a619 100644 --- a/images/win/scripts/ImageHelpers/TestsHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/TestsHelpers.ps1 @@ -53,6 +53,10 @@ function Invoke-PesterTests { if ($TestName) { $configuration.Filter.FullName = $TestName } + if ($TestFile -eq "*") { + $configuration.TestResult.Enabled = $true + $configuration.TestResult.OutputPath = "C:\image\Tests\testResults.xml" + } # Update environment variables without reboot Update-Environment diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Android.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Android.psm1 index 8953d337..08db5030 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Android.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Android.psm1 @@ -21,7 +21,7 @@ function Get-AndroidSDKManagerPath { function Get-AndroidInstalledPackages { $androidSDKManagerPath = Get-AndroidSDKManagerPath - $androidSDKManagerList = & $androidSDKManagerPath --list_installed + $androidSDKManagerList = cmd /c "$androidSDKManagerPath --list_installed 2>&1" return $androidSDKManagerList } diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 index a9ccfb8e..3c465142 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.Tools.psm1 @@ -271,8 +271,7 @@ function Get-VisualCPPComponents { } function Get-DacFxVersion { - cd "C:\Program Files\Microsoft SQL Server\150\DAC\bin\" - $dacfxversion = (./sqlpackage.exe /version) + $dacfxversion = & "$env:ProgramFiles\Microsoft SQL Server\150\DAC\bin\sqlpackage.exe" /version return "DacFx $dacfxversion" } diff --git a/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 b/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 index 2d09c87e..17f1f989 100644 --- a/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 +++ b/images/win/scripts/SoftwareReport/SoftwareReport.WebServers.psm1 @@ -13,8 +13,8 @@ function Get-ApacheVersion { } function Get-NginxVersion { - $nginxBinPath = Join-Path (Get-NginxPath) "\nginx" - (. $nginxBinPath -v 2>&1 | Select-String -Pattern "nginx/") -match "nginx/(?\d+\.\d+\.\d+)" | Out-Null + $nginxBinPath = Join-Path (Get-NginxPath) "nginx" + (cmd /c "$nginxBinPath -v 2>&1") -match "nginx/(?\d+\.\d+\.\d+)" | Out-Null return $Matches.Version } diff --git a/images/win/scripts/Tests/Nginx.Tests.ps1 b/images/win/scripts/Tests/Nginx.Tests.ps1 index e1e7b6f6..8c6e7ec0 100644 --- a/images/win/scripts/Tests/Nginx.Tests.ps1 +++ b/images/win/scripts/Tests/Nginx.Tests.ps1 @@ -1,7 +1,7 @@ Describe "Nginx" { Context "Path" { It "Nginx" { - $nginxPath = Join-Path (Join-Path "C:\tools\" (Get-Item C:\tools\nginx*).Name) "\nginx" + $nginxPath = Join-Path (Join-Path "C:\tools\" (Get-Item C:\tools\nginx*).Name) "nginx" "$nginxPath -v" | Should -ReturnZeroExitCode } } diff --git a/images/win/windows2016.json b/images/win/windows2016.json index 8237c40b..8f05537c 100644 --- a/images/win/windows2016.json +++ b/images/win/windows2016.json @@ -264,6 +264,12 @@ "{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1" ] }, + { + "type": "powershell", + "inline": [ + "if (-not (Test-Path {{user `image_folder`}}\\Tests\\testResults.xml)) { throw '{{user `image_folder`}}\\Tests\\testResults.xml not found' }" + ] + }, { "type": "powershell", "inline": [ @@ -273,6 +279,12 @@ "IMAGE_VERSION={{user `image_version`}}" ] }, + { + "type": "powershell", + "inline": [ + "if (-not (Test-Path C:\\InstalledSoftware.md)) { throw 'C:\\InstalledSoftware.md not found' }" + ] + }, { "type": "file", "source": "C:\\InstalledSoftware.md", diff --git a/images/win/windows2019.json b/images/win/windows2019.json index cc85b75d..8ffa122f 100644 --- a/images/win/windows2019.json +++ b/images/win/windows2019.json @@ -239,8 +239,7 @@ "{{ template_dir }}/scripts/Installers/Install-GoogleCloudSDK.ps1", "{{ template_dir }}/scripts/Installers/Install-CodeQLBundle.ps1", "{{ template_dir }}/scripts/Installers/Install-BizTalkBuildComponent.ps1", - "{{ template_dir }}/scripts/Installers/Disable-JITDebugger.ps1", - "{{ template_dir }}/scripts/Installers/Run-NGen.ps1" + "{{ template_dir }}/scripts/Installers/Disable-JITDebugger.ps1" ] }, { @@ -265,6 +264,12 @@ "{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1" ] }, + { + "type": "powershell", + "inline": [ + "if (-not (Test-Path {{user `image_folder`}}\\Tests\\testResults.xml)) { throw '{{user `image_folder`}}\\Tests\\testResults.xml not found' }" + ] + }, { "type": "powershell", "inline": [ @@ -274,6 +279,12 @@ "IMAGE_VERSION={{user `image_version`}}" ] }, + { + "type": "powershell", + "inline": [ + "if (-not (Test-Path C:\\InstalledSoftware.md)) { throw 'C:\\InstalledSoftware.md not found' }" + ] + }, { "type": "file", "source": "C:\\InstalledSoftware.md", @@ -283,6 +294,7 @@ { "type": "powershell", "scripts": [ + "{{ template_dir }}/scripts/Installers/Run-NGen.ps1", "{{ template_dir }}/scripts/Installers/Finalize-VM.ps1" ] }, diff --git a/images/win/windows2022.json b/images/win/windows2022.json index a0ad7b76..4d39b73e 100644 --- a/images/win/windows2022.json +++ b/images/win/windows2022.json @@ -222,8 +222,7 @@ "{{ template_dir }}/scripts/Installers/Install-RootCA.ps1", "{{ template_dir }}/scripts/Installers/Install-MongoDB.ps1", "{{ template_dir }}/scripts/Installers/Install-CodeQLBundle.ps1", - "{{ template_dir }}/scripts/Installers/Disable-JITDebugger.ps1", - "{{ template_dir }}/scripts/Installers/Run-NGen.ps1" + "{{ template_dir }}/scripts/Installers/Disable-JITDebugger.ps1" ] }, { @@ -248,6 +247,12 @@ "{{ template_dir }}/scripts/Tests/RunAll-Tests.ps1" ] }, + { + "type": "powershell", + "inline": [ + "if (-not (Test-Path {{user `image_folder`}}\\Tests\\testResults.xml)) { throw '{{user `image_folder`}}\\Tests\\testResults.xml not found' }" + ] + }, { "type": "powershell", "inline": [ @@ -257,6 +262,12 @@ "IMAGE_VERSION={{user `image_version`}}" ] }, + { + "type": "powershell", + "inline": [ + "if (-not (Test-Path C:\\InstalledSoftware.md)) { throw 'C:\\InstalledSoftware.md not found' }" + ] + }, { "type": "file", "source": "C:\\InstalledSoftware.md", @@ -266,6 +277,7 @@ { "type": "powershell", "scripts": [ + "{{ template_dir }}/scripts/Installers/Run-NGen.ps1", "{{ template_dir }}/scripts/Installers/Finalize-VM.ps1" ] },