-
Notifications
You must be signed in to change notification settings - Fork 6
Add PowerShell command to setup Windows environment #100
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
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5b9e637
Add script to set up Windows host for Node development
mokagio 34682d3
Ignore PowerShell scripts in test for executable property
mokagio 03f2525
Address RuboCop violation
mokagio cbaa1fd
Update ShellCheck command to exclude PowerShell files
mokagio ead0b64
Log more information in `hooks/environment`
mokagio 12528d3
Print CI header upon running `add_ssh_key_to_agent`
mokagio eec8d92
Make `hooks/environment` properly set `PATH` in Windows
mokagio c8d375f
Remove OS-specific handling of paths in `hooks/environment`
mokagio 8009582
Add debug `PATH` print statement in Windows PS1
mokagio bf824fb
Fix typo
mokagio f4654bf
Add `$PATH` retaining workaround to `refreshenv` call
mokagio c431864
Try to set dev mode for Windows machines
mokagio 151a397
Use `CurrentUser` instead of `LocalMachine`
mokagio 95c3be2
Try different approach for developer mode
mokagio be308db
Debug print user roles in Windows
mokagio 416c04a
Implement conditional behavior for tar in Windows
mokagio ec9374e
Remove --no-symlinks
mokagio 690f664
Restore using the same `tar` across platforms in `restore_cache`
mokagio 3e08260
Run `nvm` setup at the end of the prepare Win host script
mokagio b5c57e7
If now `.nvmrc` found, skip Node set up
mokagio ee9ff8f
Fix early exit check for `.nvmrc` in Windows
mokagio c2ff6c6
Do not open roles group
mokagio 647299c
Make `prepare_windows_host_for_node.ps1` executable
mokagio 4990c22
Merge remote-tracking branch 'origin/trunk' into mokagio/windows-utils
mokagio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# 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 " - $_" } | ||
} | ||
|
||
Write-Host "--- :windows: Setting up Windows for Node and Electorn builds" | ||
|
||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,14 @@ | |
# it seems that running `[ -x ]` under `bats` in Docker on a Mac returns invalid results, and this was more reliable. | ||
# | ||
# See: https://github.com/Automattic/a8c-ci-toolkit-buildkite-plugin/pull/42 | ||
context 'All Commands Should Be Executable' do | ||
Dir.children('bin').map { |f| File.new(File.join('bin', f)) }.each do |file| | ||
it file.path do | ||
expect(file.stat.executable?).to be true | ||
context 'All Unix Commands Should Be Executable' do | ||
Dir | ||
.children('bin') | ||
# Ignore Windows PowerShell scripts | ||
.reject { |f| f.end_with?('.ps1') } | ||
Comment on lines
-14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
.map { |f| File.new(File.join('bin', f)) }.each do |file| | ||
it file.path do | ||
expect(file.stat.executable?).to be true | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wonder if there's a
shellcheck
equivalent for PowerShell btw… though probably only a thing to look at when we'll start tacking #101 more officially/broadly?)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.
Found this… in case we want to look into it at some point