-
Notifications
You must be signed in to change notification settings - Fork 5
Windows: Install Win 10 SDK, clearer name, no Node.js setup #144
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
Changes from 12 commits
a066096
ac494f5
cb3e3ff
51b682b
2a3539b
d707ff5
a7e8550
8dfadff
b3cbf3f
abf5498
2d93f61
41262e8
5bb49fb
c84c8ca
2656bfa
4561513
ab6f9b2
97bc1ca
09b60ef
18cf230
356fe9b
854d69d
984ea7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| # Stop script execution when a non-terminating error occurs | ||||||
| $ErrorActionPreference = "Stop" | ||||||
|
|
||||||
| Write-Host "--- :windows: Installing Windows 10 SDK and Visual Studio Build Tools" | ||||||
|
|
||||||
| $windowsSDKVersionFile = ".windows-10-sdk-version" | ||||||
AliSoftware marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| if (-not (Test-Path $windowsSDKVersionFile)) { | ||||||
| Write-Output "[!] No Windows 10 SDK version file found at $windowsSDKVersionFile." | ||||||
| exit 1 | ||||||
| } | ||||||
|
|
||||||
| $windows10SDKVersion = Get-Content $windowsSDKVersionFile | ||||||
|
||||||
| $windows10SDKVersion = Get-Content $windowsSDKVersionFile | |
| $windows10SDKVersion = (Get-Content -TotalCount 1 $windowsSDKVersionFile).Trim() |
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.
Spent more time than I care to admit on this but got a bunch of tests for the version parsing
I'll clean up tomorrow #153
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.
Is there an easy way to check if $windows10SDKVersion is valid (i.e. an existing version, as opposed to if someone tried to use latest or none or whatever invalid text in the version file) and detect it early?
In particular, I'm wondering if the vs_buildtools.exe would fail with an explicit and clear error if that -add … argument we pass to it was invalid (i.e. if it didn't find the component), allowing us to print a specific error message in that case (like "Check the value you set in $windowsSDKVersionFile"), as opposed to the installer happily continuing with the installation of all the other default components—without complaining about this one not existing in the options—and us only finding out the component was not installed after the fact, thanks to your test on lines 42–51… (and even in that case, would it help to provide in the error messages a more explicit suggestion to check the syntax/version used in the version 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'm wondering if the
vs_buildtools.exewould fail with an explicit and clear error
I've done a few experiments in my VM. It fails silently, with exit code 1.
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'll duplicated what I wrote in #153 (comment)
This all makes me wonder whether we might be better off using a default SDK version in the installer, and only falling back to the version file and/or a parameter if the user provides one. After all, I implemented the version file because other tools use it and because the app I was working on had a check for the SDK being installed and so I wanted a single source of truth. But I'd argue now that our tooling takes care of the installing, that check is redundant: the build script should trust the SDK is available.
I think the conversation should continue there, given that's the PR that is editing the script.
I also like the idea of having a list of valid numbers to pick from, given it's published at https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2022 but I think that would be a good additional option, while we should still default to installing the latest valid version for the user ourselves.
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 if we end up implementing the behavior of defaulting to install the latest valid version, we could allow latest to be a special valid content for .windows-10-sdk-version, that way if the file is not present it won't install the SDK at all, but if it's present with latest it will install the latest (and if it's present with a specific version it will deterministically install that specific version, acting as a lockfile) 🤔
That way the implicit auto-install from prepare_windows_host_for_app_distibution if file is present would still work for that default-version fallback… 🤔
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Stop script execution when a non-terminating error occurs | ||
mokagio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| Write-Host "--- :windows: Setting up Windows for app distribution" | ||
|
|
||
| Write-Host "Current working directory: $PWD" | ||
|
|
||
| Write-Host "Enable long path behavior" | ||
| # See https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation | ||
| Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 | ||
|
|
||
| # Disable Windows Defender before starting – otherwise our performance is terrible | ||
| Write-Host "Disable Windows Defender..." | ||
| $avPreference = @( | ||
AliSoftware marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @{DisableArchiveScanning = $true} | ||
| @{DisableAutoExclusions = $true} | ||
| @{DisableBehaviorMonitoring = $true} | ||
| @{DisableBlockAtFirstSeen = $true} | ||
| @{DisableCatchupFullScan = $true} | ||
| @{DisableCatchupQuickScan = $true} | ||
| @{DisableIntrusionPreventionSystem = $true} | ||
| @{DisableIOAVProtection = $true} | ||
| @{DisablePrivacyMode = $true} | ||
| @{DisableScanningNetworkFiles = $true} | ||
| @{DisableScriptScanning = $true} | ||
| @{MAPSReporting = 0} | ||
| @{PUAProtection = 0} | ||
| @{SignatureDisableUpdateOnStartupWithoutEngine = $true} | ||
| @{SubmitSamplesConsent = 2} | ||
| @{ScanAvgCPULoadFactor = 5; ExclusionPath = @("D:\", "C:\")} | ||
| @{DisableRealtimeMonitoring = $true} | ||
| @{ScanScheduleDay = 8} | ||
| ) | ||
|
|
||
| $avPreference += @( | ||
| @{EnableControlledFolderAccess = "Disable"} | ||
| @{EnableNetworkProtection = "Disabled"} | ||
| ) | ||
|
|
||
| $avPreference | Foreach-Object { | ||
| $avParams = $_ | ||
| Set-MpPreference @avParams | ||
| } | ||
|
|
||
| # https://github.com/actions/runner-images/issues/4277 | ||
| # https://docs.microsoft.com/en-us/microsoft-365/security/defender-endpoint/microsoft-defender-antivirus-compatibility?view=o365-worldwide | ||
| $atpRegPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows Advanced Threat Protection' | ||
| if (Test-Path $atpRegPath) { | ||
| Write-Host "Set Microsoft Defender Antivirus to passive mode" | ||
| Set-ItemProperty -Path $atpRegPath -Name 'ForceDefenderPassiveMode' -Value '1' -Type 'DWORD' | ||
| } | ||
|
|
||
| # From https://stackoverflow.com/a/46760714 | ||
| Write-Host "--- :windows: Setting up Package Manager" | ||
| $env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." | ||
| Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | ||
|
|
||
| # This should avoid issues with symlinks not being supported in Windows. | ||
| # | ||
| # See how this build failed | ||
| # https://buildkite.com/automattic/beeper-desktop/builds/2895#01919738-7c6e-4b82-8d1d-1c1800481740 | ||
| Write-Host "--- :windows: :linux: Enable developer mode to use symlinks" | ||
|
|
||
| $developerMode = Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux | ||
|
|
||
| if ($developerMode.State -eq 'Enabled') { | ||
| Write-Host "Developer Mode is already enabled." | ||
| } else { | ||
| Write-Host "Enabling Developer Mode..." | ||
| try { | ||
| Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart | ||
| } catch { | ||
| Write-Host "Failed to enable Developer Mode. Continuing without it..." | ||
| } | ||
| } | ||
|
|
||
| Write-Host "--- :lock_with_ink_pen: Download Code Signing Certificate" | ||
| $certificateBinPath = "certificate.bin" | ||
| $EncodedText = aws secretsmanager get-secret-value --secret-id windows-code-signing-certificate ` | ||
| | jq -r '.SecretString' ` | ||
| | Out-File $certificateBinPath | ||
| $certificatePfxPath = "certificate.pfx" | ||
| certutil -decode $certificateBinPath $certificatePfxPath | ||
| Write-Host "Code signing certificate downloaded at: $((Get-Item $certificatePfxPath).FullName)" | ||
|
|
||
| Write-Host "--- :windows: Checking whether to install Windows 10 SDK..." | ||
|
|
||
| # When using Electron Forge and electron2appx, building Appx requires the Windows 10 SDK | ||
| # | ||
| # See https://github.com/hermit99/electron-windows-store/tree/v2.1.2?tab=readme-ov-file#usage | ||
|
|
||
| $windowsSDKVersionFile = ".windows-10-sdk-version" | ||
| if (Test-Path $windowsSDKVersionFile) { | ||
| Write-Host "Found $windowsSDKVersionFile file, installing Windows 10 SDK..." | ||
| & "$PSScriptRoot\install_windows_10_sdk.ps1" | ||
| If ($LastExitCode -ne 0) { Exit $LastExitCode } | ||
| } else { | ||
| Write-Host "No $windowsSDKVersionFile file found, skipping Windows 10 SDK installation." | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,134 +1,10 @@ | ||
| # Stop script execution when a non-terminating error occurs | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) { | ||
| Write-Host "--- :bug: Running as Administrator" | ||
| } else { | ||
| Write-Host "--- :bug: Running as not Administrator" | ||
| $principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | ||
| $roles = $principal.Identity.Groups | ForEach-Object { | ||
| $_.Translate([Security.Principal.NTAccount]).Value | ||
| } | ||
| Write-Host "Your roles are:" | ||
| $roles | ForEach-Object { Write-Host " - $_" } | ||
| } | ||
| $newScript = "prepare_windows_host_for_app_distribution.ps1" | ||
|
|
||
| Write-Host "--- :windows: Setting up Windows for Node and Electron builds" | ||
| Write-Host "+++ :warning: This command is deprecated" | ||
| Write-Host "Please use $newScript instead" | ||
| Write-Host "Now calling $newScript..." | ||
AliSoftware marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Write-Host "Enable long path behavior" | ||
| # See https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation | ||
| Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 | ||
|
|
||
| # Disable Windows Defender before starting – otherwise our performance is terrible | ||
| Write-Host "Disable Windows Defender..." | ||
| $avPreference = @( | ||
| @{DisableArchiveScanning = $true} | ||
| @{DisableAutoExclusions = $true} | ||
| @{DisableBehaviorMonitoring = $true} | ||
| @{DisableBlockAtFirstSeen = $true} | ||
| @{DisableCatchupFullScan = $true} | ||
| @{DisableCatchupQuickScan = $true} | ||
| @{DisableIntrusionPreventionSystem = $true} | ||
| @{DisableIOAVProtection = $true} | ||
| @{DisablePrivacyMode = $true} | ||
| @{DisableScanningNetworkFiles = $true} | ||
| @{DisableScriptScanning = $true} | ||
| @{MAPSReporting = 0} | ||
| @{PUAProtection = 0} | ||
| @{SignatureDisableUpdateOnStartupWithoutEngine = $true} | ||
| @{SubmitSamplesConsent = 2} | ||
| @{ScanAvgCPULoadFactor = 5; ExclusionPath = @("D:\", "C:\")} | ||
| @{DisableRealtimeMonitoring = $true} | ||
| @{ScanScheduleDay = 8} | ||
| ) | ||
|
|
||
| $avPreference += @( | ||
| @{EnableControlledFolderAccess = "Disable"} | ||
| @{EnableNetworkProtection = "Disabled"} | ||
| ) | ||
|
|
||
| $avPreference | Foreach-Object { | ||
| $avParams = $_ | ||
| Set-MpPreference @avParams | ||
| } | ||
|
|
||
| # https://github.com/actions/runner-images/issues/4277 | ||
| # https://docs.microsoft.com/en-us/microsoft-365/security/defender-endpoint/microsoft-defender-antivirus-compatibility?view=o365-worldwide | ||
| $atpRegPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows Advanced Threat Protection' | ||
| if (Test-Path $atpRegPath) { | ||
| Write-Host "Set Microsoft Defender Antivirus to passive mode" | ||
| Set-ItemProperty -Path $atpRegPath -Name 'ForceDefenderPassiveMode' -Value '1' -Type 'DWORD' | ||
| } | ||
|
|
||
| Write-Host "--- :lock_with_ink_pen: Downloading Code Signing Certificate" | ||
| $EncodedText = aws secretsmanager get-secret-value --secret-id windows-code-signing-certificate | jq -r '.SecretString' | Out-File 'certificate.bin' | ||
| certutil -decode certificate.bin certificate.pfx | ||
| If ($LastExitCode -ne 0) { Exit $LastExitCode } | ||
|
|
||
| # From https://stackoverflow.com/a/46760714 | ||
| Write-Host "--- :windows: Setting up Package Manager" | ||
| $env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." | ||
| Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | ||
|
|
||
| # This should avoid issues with symlinks not being supported in Windows. | ||
| # | ||
| # See how this build failed | ||
| # https://buildkite.com/automattic/beeper-desktop/builds/2895#01919738-7c6e-4b82-8d1d-1c1800481740 | ||
| Write-Host "--- :windows: :linux: Enable developer mode to use symlinks" | ||
|
|
||
| $developerMode = Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux | ||
|
|
||
| if ($developerMode.State -eq 'Enabled') { | ||
| Write-Host "Developer Mode is already enabled." | ||
| } else { | ||
| Write-Host "Enabling Developer Mode..." | ||
| try { | ||
| Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart | ||
| } catch { | ||
| Write-Host "Failed to enable Developer Mode. Continuing without it..." | ||
| } | ||
| } | ||
|
|
||
| Write-Host "--- :node: Installing NVM" | ||
| choco install nvm.portable -y | ||
| If ($LastExitCode -ne 0) { Exit $LastExitCode } | ||
|
|
||
| Write-Host "--- :hammer: Custom PATH refresh post NVM installation to avoid losing previous PATH changes" | ||
| Write-Host "PATH before refreshenv is $env:PATH" | ||
| # It looks like out of the box, calling refreshenv at this point erases various PATH modifications made by the rest of our automation. | ||
| # | ||
| # See https://buildkite.com/automattic/beeper-desktop/builds/2893#01919717-d0d0-441d-a85d-0fe3223467d2/195 | ||
| # | ||
| # To avoid the issue, we save the PATH pre-refreshenv and then manually add all the components that were removed. | ||
| $originalPath = "$env:PATH" | ||
| refreshenv | ||
| $mergedPath = "$env:PATH;$originalPath" -split ";" | Select-Object -Unique -Skip 1 | ||
| $env:PATH = ($mergedPath -join ";") | ||
| Write-Host "PATH after refreshenv is $env:PATH" | ||
|
|
||
| $nvmRCPath = '.nvmrc' | ||
| if (-not (Test-Path $nvmRCPath)) { | ||
| Write-Host "No .nvmrc found. Skipping Node set up." | ||
| Exit 0 | ||
| } | ||
|
|
||
| Write-Host "--- :node: Installing Node" | ||
| $nvmVersion=(Get-Content -Path $nvmRCPath -Total 1) | ||
| Write-Host "Switching to nvm version defined in .nvmrc: $nvmVersion" | ||
|
|
||
| nvm install $nvmVersion | ||
| nvm use $nvmVersion | ||
| If ($LastExitCode -ne 0) { Exit $LastExitCode } | ||
|
|
||
| Write-Host "--- :hammer: Custom PATH refresh post NVM installation to avoid losing previous PATH changes" | ||
| Write-Host "PATH before refreshenv is $env:PATH" | ||
| # It looks like out of the box, calling refreshenv at this point erases various PATH modifications made by the rest of our automation. | ||
| # | ||
| # See https://buildkite.com/automattic/beeper-desktop/builds/2893#01919717-d0d0-441d-a85d-0fe3223467d2/195 | ||
| # | ||
| # To avoid the issue, we save the PATH pre-refreshenv and then manually add all the components that were removed. | ||
| $originalPath = "$env:PATH" | ||
| refreshenv | ||
| $mergedPath = "$env:PATH;$originalPath" -split ";" | Select-Object -Unique -Skip 1 | ||
| $env:PATH = ($mergedPath -join ";") | ||
| Write-Host "PATH after refreshenv is $env:PATH" | ||
| & "$PSScriptRoot\$newScript" | ||




Uh oh!
There was an error while loading. Please reload this page.