Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,35 @@ jobs:
Remove-Item -LiteralPath $probePath -Force -ErrorAction SilentlyContinue
}

# Windows PowerShell 5.1 does not populate $PSScriptRoot while the param
# block is evaluated, so a default value that uses it fails whenever the
# script is started with `powershell.exe -File`. The repository's Windows
# scripts are started that way by the converge task.
- name: Validate that no param default uses $PSScriptRoot
shell: pwsh
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

$files = Get-ChildItem -Path . -Recurse -Filter '*.ps1' |
Where-Object { $_.FullName -notmatch '[\\/]\.git[\\/]' }
foreach ($file in $files) {
$errors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$null, [ref]$errors)
if (-not $ast -or -not $ast.ParamBlock) { continue }
foreach ($parameter in $ast.ParamBlock.Parameters) {
if (-not $parameter.DefaultValue) { continue }
$uses = $parameter.DefaultValue.FindAll({
param($node)
$node -is [System.Management.Automation.Language.VariableExpressionAst] -and
$node.VariablePath.UserPath -eq 'PSScriptRoot'
}, $true)
if ($uses.Count -gt 0) {
throw "$($file.FullName): the param default of `$$($parameter.Name.VariablePath.UserPath) uses `$PSScriptRoot, which Windows PowerShell 5.1 does not populate while the param block is evaluated."
}
}
}

- name: Validate Notion MSIX boundary
shell: pwsh
run: |
Expand Down
13 changes: 12 additions & 1 deletion platforms/windows-11/install-apps.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
[CmdletBinding()]
param(
[string]$InventoryPath = (Join-Path $PSScriptRoot 'apps.psd1')
[string]$InventoryPath = ''
)

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

# Windows PowerShell 5.1 does not populate $PSScriptRoot while the param block
# is evaluated, so a default value that uses it fails there with
# "Split-Path: cannot bind argument to parameter 'Path' because it is an empty
# string" when the script is started with `powershell.exe -File`. The inventory
# path is resolved after the param block instead, which works with both
# invocation styles. An explicit -InventoryPath still wins
# (rebuildup/pc-setup#293).
if (-not $InventoryPath) {
$InventoryPath = Join-Path $PSScriptRoot 'apps.psd1'
}

if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
throw 'winget is required to install Windows desktop applications.'
}
Expand Down
11 changes: 10 additions & 1 deletion platforms/windows-11/setup-tailscale.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
[CmdletBinding()]
param(
[switch]$Injected,
[string]$ConfigPath = (Join-Path $PSScriptRoot 'tailscale.psd1')
[string]$ConfigPath = ''
)

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

# Windows PowerShell 5.1 does not populate $PSScriptRoot while the param block
# is evaluated, so a default value that uses it fails there when the script is
# started with `powershell.exe -File`. The config path is resolved after the
# param block instead. An explicit -ConfigPath still wins
# (rebuildup/pc-setup#293).
if (-not $ConfigPath) {
$ConfigPath = Join-Path $PSScriptRoot 'tailscale.psd1'
}

function Resolve-Application {
param(
[Parameter(Mandatory)][string]$Name,
Expand Down