|
| 1 | +# Stop script execution when a non-terminating error occurs |
| 2 | +$ErrorActionPreference = "Stop" |
| 3 | + |
| 4 | +if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) { |
| 5 | + Write-Host "--- :bug: Running as Administrator" |
| 6 | +} else { |
| 7 | + Write-Host "--- :bug: Running as not Administrator" |
| 8 | + $principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) |
| 9 | + $roles = $principal.Identity.Groups | ForEach-Object { |
| 10 | + $_.Translate([Security.Principal.NTAccount]).Value |
| 11 | + } |
| 12 | + Write-Host "Your roles are:" |
| 13 | + $roles | ForEach-Object { Write-Host " - $_" } |
| 14 | +} |
| 15 | + |
| 16 | +Write-Host "--- :windows: Setting up Windows for Node and Electorn builds" |
| 17 | + |
| 18 | +Write-Host "Enable long path behavior" |
| 19 | +# See https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#maximum-path-length-limitation |
| 20 | +Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 |
| 21 | + |
| 22 | +# Disable Windows Defender before starting – otherwise our performance is terrible |
| 23 | +Write-Host "Disable Windows Defender..." |
| 24 | +$avPreference = @( |
| 25 | + @{DisableArchiveScanning = $true} |
| 26 | + @{DisableAutoExclusions = $true} |
| 27 | + @{DisableBehaviorMonitoring = $true} |
| 28 | + @{DisableBlockAtFirstSeen = $true} |
| 29 | + @{DisableCatchupFullScan = $true} |
| 30 | + @{DisableCatchupQuickScan = $true} |
| 31 | + @{DisableIntrusionPreventionSystem = $true} |
| 32 | + @{DisableIOAVProtection = $true} |
| 33 | + @{DisablePrivacyMode = $true} |
| 34 | + @{DisableScanningNetworkFiles = $true} |
| 35 | + @{DisableScriptScanning = $true} |
| 36 | + @{MAPSReporting = 0} |
| 37 | + @{PUAProtection = 0} |
| 38 | + @{SignatureDisableUpdateOnStartupWithoutEngine = $true} |
| 39 | + @{SubmitSamplesConsent = 2} |
| 40 | + @{ScanAvgCPULoadFactor = 5; ExclusionPath = @("D:\", "C:\")} |
| 41 | + @{DisableRealtimeMonitoring = $true} |
| 42 | + @{ScanScheduleDay = 8} |
| 43 | +) |
| 44 | + |
| 45 | +$avPreference += @( |
| 46 | + @{EnableControlledFolderAccess = "Disable"} |
| 47 | + @{EnableNetworkProtection = "Disabled"} |
| 48 | +) |
| 49 | + |
| 50 | +$avPreference | Foreach-Object { |
| 51 | + $avParams = $_ |
| 52 | + Set-MpPreference @avParams |
| 53 | +} |
| 54 | + |
| 55 | +# https://github.com/actions/runner-images/issues/4277 |
| 56 | +# https://docs.microsoft.com/en-us/microsoft-365/security/defender-endpoint/microsoft-defender-antivirus-compatibility?view=o365-worldwide |
| 57 | +$atpRegPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows Advanced Threat Protection' |
| 58 | +if (Test-Path $atpRegPath) { |
| 59 | + Write-Host "Set Microsoft Defender Antivirus to passive mode" |
| 60 | + Set-ItemProperty -Path $atpRegPath -Name 'ForceDefenderPassiveMode' -Value '1' -Type 'DWORD' |
| 61 | +} |
| 62 | + |
| 63 | +Write-Host "--- :lock_with_ink_pen: Downloading Code Signing Certificate" |
| 64 | +$EncodedText = aws secretsmanager get-secret-value --secret-id windows-code-signing-certificate | jq -r '.SecretString' | Out-File 'certificate.bin' |
| 65 | +certutil -decode certificate.bin certificate.pfx |
| 66 | +If ($LastExitCode -ne 0) { Exit $LastExitCode } |
| 67 | + |
| 68 | +# From https://stackoverflow.com/a/46760714 |
| 69 | +Write-Host "--- :windows: Setting up Package Manager" |
| 70 | +$env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." |
| 71 | +Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" |
| 72 | + |
| 73 | +# This should avoid issues with symlinks not being supported in Windows. |
| 74 | +# |
| 75 | +# See how this build failed |
| 76 | +# https://buildkite.com/automattic/beeper-desktop/builds/2895#01919738-7c6e-4b82-8d1d-1c1800481740 |
| 77 | +Write-Host "--- :windows: :linux: Enable developer mode to use symlinks" |
| 78 | + |
| 79 | +$developerMode = Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux |
| 80 | + |
| 81 | +if ($developerMode.State -eq 'Enabled') { |
| 82 | + Write-Host "Developer Mode is already enabled." |
| 83 | +} else { |
| 84 | + Write-Host "Enabling Developer Mode..." |
| 85 | + try { |
| 86 | + Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart |
| 87 | + } catch { |
| 88 | + Write-Host "Failed to enable Developer Mode. Continuing without it..." |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +Write-Host "--- :node: Installing NVM" |
| 93 | +choco install nvm.portable -y |
| 94 | +If ($LastExitCode -ne 0) { Exit $LastExitCode } |
| 95 | + |
| 96 | +Write-Host "--- :hammer: Custom PATH refresh post NVM installation to avoid losing previous PATH changes" |
| 97 | +Write-Host "PATH before refreshenv is $env:PATH" |
| 98 | +# It looks like out of the box, calling refreshenv at this point erases various PATH modifications made by the rest of our automation. |
| 99 | +# |
| 100 | +# See https://buildkite.com/automattic/beeper-desktop/builds/2893#01919717-d0d0-441d-a85d-0fe3223467d2/195 |
| 101 | +# |
| 102 | +# To avoid the issue, we save the PATH pre-refreshenv and then manually add all the components that were removed. |
| 103 | +$originalPath = "$env:PATH" |
| 104 | +refreshenv |
| 105 | +$mergedPath = "$env:PATH;$originalPath" -split ";" | Select-Object -Unique -Skip 1 |
| 106 | +$env:PATH = ($mergedPath -join ";") |
| 107 | +Write-Host "PATH after refreshenv is $env:PATH" |
| 108 | + |
| 109 | +$nvmRCPath = '.nvmrc' |
| 110 | +if (-not (Test-Path $nvmRCPath)) { |
| 111 | + Write-Host "No .nvmrc found. Skipping Node set up." |
| 112 | + Exit 0 |
| 113 | +} |
| 114 | + |
| 115 | +Write-Host "--- :node: Installing Node" |
| 116 | +$nvmVersion=(Get-Content -Path $nvmRCPath -Total 1) |
| 117 | +Write-Host "Switching to nvm version defined in .nvmrc: $nvmVersion" |
| 118 | + |
| 119 | +nvm install $nvmVersion |
| 120 | +nvm use $nvmVersion |
| 121 | +If ($LastExitCode -ne 0) { Exit $LastExitCode } |
| 122 | + |
| 123 | +Write-Host "--- :hammer: Custom PATH refresh post NVM installation to avoid losing previous PATH changes" |
| 124 | +Write-Host "PATH before refreshenv is $env:PATH" |
| 125 | +# It looks like out of the box, calling refreshenv at this point erases various PATH modifications made by the rest of our automation. |
| 126 | +# |
| 127 | +# See https://buildkite.com/automattic/beeper-desktop/builds/2893#01919717-d0d0-441d-a85d-0fe3223467d2/195 |
| 128 | +# |
| 129 | +# To avoid the issue, we save the PATH pre-refreshenv and then manually add all the components that were removed. |
| 130 | +$originalPath = "$env:PATH" |
| 131 | +refreshenv |
| 132 | +$mergedPath = "$env:PATH;$originalPath" -split ";" | Select-Object -Unique -Skip 1 |
| 133 | +$env:PATH = ($mergedPath -join ";") |
| 134 | +Write-Host "PATH after refreshenv is $env:PATH" |
0 commit comments