From 6dabe4ef5fa80d5a565705edeb6a0dcb98b30f80 Mon Sep 17 00:00:00 2001 From: Matt <138825652+middlemose@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:51:36 -0700 Subject: Improve version info, vsix installation, and update building locally readme --- Build-SampleSet.ps1 | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'Build-SampleSet.ps1') diff --git a/Build-SampleSet.ps1 b/Build-SampleSet.ps1 index 2197b967..5be14dcf 100644 --- a/Build-SampleSet.ps1 +++ b/Build-SampleSet.ps1 @@ -10,16 +10,13 @@ param( $root = Get-Location -# launch developer powershell (if necessary) +# launch developer powershell (if necessary to prevent multiple developer sessions) if (-not $env:VSCMD_VER) { Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") cd $root } -# source environment variables -. .\Env-Vars.ps1 - $ThrottleFactor = 5 $LogicalProcessors = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors @@ -56,26 +53,30 @@ finally { } # -# Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'. Only used to determine build number. +# Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'. # Determine build number (used for exclusions based on build number). Five digits. Say, '22621'. # $build_environment="" $build_number=0 +$nuget_package_version=0 # # In Github we build using Nuget only and source version from repo .\Env-Vars.ps1. # if ($env:GITHUB_REPOSITORY) { $build_environment="GitHub" - $build_number=$env:SAMPLES_BUILD_NUMBER + $nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value + $build_number=$nuget_package_version.split('.')[2] } # # WDK NuGet will require presence of a folder 'packages'. The version is sourced from repo .\Env-Vars.ps1. # -# Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named .\packages. +# Hack: If user has hydrated nuget packages, then use those. That will be indicated by presence of a folder named '.\packages'. +# Further, we need to test that the directory has been hydrated using '.\packages\*'. # -elseif(Test-Path(".\packages")) { +elseif(Test-Path(".\packages\*")) { $build_environment=("NuGet") - $build_number=$env:SAMPLES_BUILD_NUMBER + $nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value + $build_number=$nuget_package_version.split('.')[2] } # # EWDK sets environment variable BuildLab. For example 'ni_release_svc_prod1.22621.2428'. @@ -164,6 +165,10 @@ $jresult = @{ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count Write-Output ("Build Environment: " + $build_environment) +if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { + Write-Output ("Nuget Package Version: " + $nuget_package_version) +} +Write-Output ("WDK VSIX Version: " + ($env:SAMPLES_VSIX_VERSION) ? $env:SAMPLES_VSIX_VERSION : (ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name).split('=')[1]) Write-Output ("Build Number: " + $build_number) Write-Output ("Samples: " + $sampleSet.Count) Write-Output ("Configurations: " + $Configurations.Count + " (" + $Configurations + ")") -- cgit v1.3.1 From 2e07f1b58a93eb36c616192045db654cf043a670 Mon Sep 17 00:00:00 2001 From: Matt <138825652+middlemose@users.noreply.github.com> Date: Tue, 25 Jun 2024 12:50:00 -0700 Subject: Fix printing vsix version --- Build-SampleSet.ps1 | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'Build-SampleSet.ps1') diff --git a/Build-SampleSet.ps1 b/Build-SampleSet.ps1 index 5be14dcf..2fccfdb8 100644 --- a/Build-SampleSet.ps1 +++ b/Build-SampleSet.ps1 @@ -164,12 +164,23 @@ $jresult = @{ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count -Write-Output ("Build Environment: " + $build_environment) -if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { - Write-Output ("Nuget Package Version: " + $nuget_package_version) +# Find vsix version either from env variabel or from packages +$vsix_version = $env:SAMPLES_VSIX_VERSION +if (-not $vsix_version) { + $vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name + if ($vsix_version) { + $vsix_version = $vsix_version.split('=')[1] + } + else { + Write-Error "No version for the WDK VSIX could be found. The WDK VSIX is not installed." + exit 1 + } } -Write-Output ("WDK VSIX Version: " + ($env:SAMPLES_VSIX_VERSION) ? $env:SAMPLES_VSIX_VERSION : (ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name).split('=')[1]) + +Write-Output ("Build Environment: " + $build_environment) Write-Output ("Build Number: " + $build_number) +if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { Write-Output ("Nuget Package Version: " + $nuget_package_version) } +Write-Output ("WDK VSIX Version: " + $vsix_version) Write-Output ("Samples: " + $sampleSet.Count) Write-Output ("Configurations: " + $Configurations.Count + " (" + $Configurations + ")") Write-Output ("Platforms: " + $Platforms.Count + " (" + $Platforms + ")") -- cgit v1.3.1 From f9eb04d34edd823873e491a7da6e6ed7a064e823 Mon Sep 17 00:00:00 2001 From: Matt <138825652+middlemose@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:17:05 -0700 Subject: Refactored vsix install and cleaned up build sampleset --- .github/scripts/Install-Vsix.ps1 | 94 +++++++++++-------------------------- .github/workflows/Code-Scanning.yml | 2 +- .github/workflows/ci-pr.yml | 2 +- .github/workflows/ci.yml | 2 +- Build-SampleSet.ps1 | 33 +++++++------ 5 files changed, 49 insertions(+), 84 deletions(-) (limited to 'Build-SampleSet.ps1') diff --git a/.github/scripts/Install-Vsix.ps1 b/.github/scripts/Install-Vsix.ps1 index 8579b36b..50ef088b 100644 --- a/.github/scripts/Install-Vsix.ps1 +++ b/.github/scripts/Install-Vsix.ps1 @@ -1,76 +1,38 @@ <# .SYNOPSIS -Checks WDK vsix version and downloads and installs as necessary. +Download and install the latest WDK VSIX. #> -[CmdletBinding()] -param( - [bool]$optimize = $false -) - -$root = Get-Location - -# launch developer powershell -Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll") -Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*") -cd $root - -# Automatically resolve the latest amd64 VSIX +# set uri by resolving amd64 vsix $uri = "https://marketplace.visualstudio.com$((Invoke-WebRequest -Uri "https://marketplace.visualstudio.com/items?itemName=DriverDeveloperKits-WDK.WDKVsix").Links | Where-Object outerHTML -like '*(amd64)*' | select -expand href)" -# Set local version variable -$version = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($uri).Value - -# Set github environment variable for vsix version -"SAMPLES_VSIX_VERSION=$version" | Out-File -FilePath "$env:GITHUB_ENV" -Append - -function PrintWdkVsix { - "WDK Vsix Version: $(ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name)" +# set download version +$uri_version = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($uri).Value + +# set msbuild path +$msbuild_path = (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") + +# download vsix, expand, and store the downloaded version extracted from the extension manifest +"Downloading WDK VSIX version: $uri_version..." +Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip +"Expanding WDK VSIX archive..." +Expand-Archive ".\wdk.zip" .\ +"Extracting version from manifest..." +$downloaded_version = ([xml](Get-Content .\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version +"Downloaded WDK VSIX version: $downloaded_version" + +# copy msbuild files, extension manifest, and check installed version from the extension manifest +"Copying WDK extension files to build path..." +cp (".\`$MSBuild\*", ".\extension.vsixmanifest") "$msbuild_path" -Recurse -Force +"Extracting version from copied manifest..." +$installed_version = ([xml](Get-Content ${msbuild_path}\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version +"Installed WDK VSIX Version: $installed_version" +if (-not ("$downloaded_version" -eq "$installed_version")) { + "WDK VSIX installation failed due to version mismatch" + exit 1 } -function TestWdkVsix { - Test-Path "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=$version" -} - -# NOTE: The '$optimize' code path examines the '.vsixmanifest' when downloaded and then examines it again (in the 'MSBuild' directory) once -# the necessary extension files are copied. -if ($optimize) { - $msbuild_path = (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\MSBuild\") - "---> Downloading vsix version: $version" - Invoke-WebRequest -Uri "$uri" -OutFile wdk.zip - Expand-Archive ".\wdk.zip" .\ - "Downloaded VSIX Version: $(([xml](Get-Content .\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)" - "<--- Download complete" - "---> Configuring build environment..." - cp ".\`$MSBuild\*" "$msbuild_path" -Recurse -Force - cp ".\extension.vsixmanifest" "$msbuild_path" - "Installed VSIX Version: $(([xml](Get-Content ${msbuild_path}\extension.vsixmanifest)).PackageManifest.Metadata.Identity.Version)" - "<--- Configuration complete" -} -else { - "Getting installed WDK vsix..." - PrintWdkVsix - "Checking the WDK.vsix version installed..." - if (-not (TestWdkVsix)) { - "The correct WDK vsix is not installed." - "Will attempt to download and install now..." - Invoke-WebRequest -Uri "$uri" -OutFile wdk.vsix - "Finished downloading." - "Starting install process. This will take some time to complete..." - Start-Process vsixinstaller -ArgumentList "/f /q /sp .\wdk.vsix" -wait - "The install process has finished." - "Checking the WDK.vsix version installed..." - if (TestWdkVsix) { - PrintWdkVsix - "The WDK vsix version is OK" - } - else { - "The WDK vsix install FAILED" - Write-Host "`u{274C} wdk vsix install had an issue" - Write-Error "the wdk vsix cannot be installed at this time" - exit 1 - } - } -} +# set github environment variable for vsix version +"SAMPLES_VSIX_VERSION=$installed_version" | Out-File -FilePath "$env:GITHUB_ENV" -Append diff --git a/.github/workflows/Code-Scanning.yml b/.github/workflows/Code-Scanning.yml index 32bb5a65..cd0d8abf 100644 --- a/.github/workflows/Code-Scanning.yml +++ b/.github/workflows/Code-Scanning.yml @@ -38,7 +38,7 @@ jobs: submodules: 'recursive' - name: Install WDK VSIX - run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + run: .\.github\scripts\Install-Vsix.ps1 - name: Install Nuget Packages run: nuget restore .\packages.config -PackagesDirectory .\packages\ diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index a179127a..c04f4adb 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -23,7 +23,7 @@ jobs: submodules: 'recursive' - name: Install WDK VSIX - run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + run: .\.github\scripts\Install-Vsix.ps1 - name: Install Nuget Packages run: nuget restore .\packages.config -PackagesDirectory .\packages\ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13563aa8..c35a81ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: submodules: 'recursive' - name: Install WDK VSIX - run: .\.github\scripts\Install-Vsix.ps1 -optimize:$true + run: .\.github\scripts\Install-Vsix.ps1 - name: Install Nuget Packages run: nuget restore .\packages.config -PackagesDirectory .\packages\ diff --git a/Build-SampleSet.ps1 b/Build-SampleSet.ps1 index 2fccfdb8..adae8bb0 100644 --- a/Build-SampleSet.ps1 +++ b/Build-SampleSet.ps1 @@ -55,17 +55,21 @@ finally { # # Determine build environment: 'GitHub', 'NuGet', 'EWDK', or 'WDK'. # Determine build number (used for exclusions based on build number). Five digits. Say, '22621'. +# Determine NuGet package version (if applicable). +# Determine WDK vsix version. # $build_environment="" $build_number=0 $nuget_package_version=0 +$vsix_version="" # -# In Github we build using Nuget only and source version from repo .\Env-Vars.ps1. +# In Github we build using NuGet and get the version from packages and vsix version from env var set from the install vsix step. # if ($env:GITHUB_REPOSITORY) { $build_environment="GitHub" $nuget_package_version=([regex]'(?<=x64\.)(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches((Get-Childitem .\packages\*WDK.x64* -Name)).Value $build_number=$nuget_package_version.split('.')[2] + $vsix_version = $env:SAMPLES_VSIX_VERSION } # # WDK NuGet will require presence of a folder 'packages'. The version is sourced from repo .\Env-Vars.ps1. @@ -102,7 +106,19 @@ else { Write-Error "Could not determine build environment." exit 1 } - +# +# Get the vsix version from packages if not set +if (-not $vsix_version) { + $vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name + if ($vsix_version) { + $vsix_version = $vsix_version.split('=')[1] + } + else { + Write-Error "No version of the WDK VSIX could be found. The WDK VSIX is not installed." + exit 1 + } +} +# # # InfVerif_AdditionalOptions # @@ -164,19 +180,6 @@ $jresult = @{ $SolutionsTotal = $sampleSet.Count * $Configurations.Count * $Platforms.Count -# Find vsix version either from env variabel or from packages -$vsix_version = $env:SAMPLES_VSIX_VERSION -if (-not $vsix_version) { - $vsix_version = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name - if ($vsix_version) { - $vsix_version = $vsix_version.split('=')[1] - } - else { - Write-Error "No version for the WDK VSIX could be found. The WDK VSIX is not installed." - exit 1 - } -} - Write-Output ("Build Environment: " + $build_environment) Write-Output ("Build Number: " + $build_number) if (($build_environment -eq "GitHub") -or ($build_environment -eq "NuGet")) { Write-Output ("Nuget Package Version: " + $nuget_package_version) } -- cgit v1.3.1