-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(testing) Add bin/sandbox.ps1 to easily test using a Windows sandbox #5349
base: develop
Are you sure you want to change the base?
Conversation
Scoop is almost a requirement for Windows Sandbox; the Windows Store (and thus winget) does not work. Managing a cache for Windows Sandbox would make the initial startup less painful; I might even install Scoop on my host machine! A couple 🥧pie in the sky☁ Windows Sandbox-specific scoop feature ideas that may already be (close to) possible:
Keep up the good work! |
@roysubs Yeah, my script is just a hack of https://github.com/microsoft/winget-pkgs/blob/HEAD/Tools/SandboxTest.ps1, so it certainly can be improved on/replaced with something better. |
Write-Host @' | ||
--> Installing Scoop, 7zip, git, innounp, dark and lessmsi | ||
'@ | ||
`$ProgressPreference = 'SilentlyContinue' |
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.
$ProgressPreference
has been fixed with ScoopInstaller/Install#42
Edit: Okay it also mutes the output of Invoke-RestMethod
😄
Do we need Just a simple $global:ProgressPreference = 'SilentlyContinue'
# $global:VerbosePreference = 'Continue'
Invoke-RestMethod get.scoop.sh | Invoke-Expression
scoop config aria2-warning-enabled false
scoop install --no-update-scoop main/7zip
scoop install --no-update-scoop main/aria2
scoop install --no-update-scoop main/mingit
# scoop install --no-update-scoop main/innounp
# scoop install --no-update-scoop main/dark
# scoop install --no-update-scoop main/lessmsi
scoop install --no-update-scoop main/pwsh
scoop bucket add extras
PowerShell Start-Process ~\scoop\apps\pwsh\current\pwsh.exe -WorkingDirectory ~ Instead of copying the cache (multiple GB) we could just mount it: <MappedFolder>
<HostFolder>$scoopCache</HostFolder>
<SandboxFolder>%USERPROFILE%\scoop\cache</SandboxFolder>
</MappedFolder> |
@r15ch13 We can certainly toss them if they are causing issues, but they both are helpful when testing apps from the NonPortable bucket.
That's a great idea. Much simpler than my hack. |
Another neat feature, add Scoop and bootstrap directory to Quick Access: $o = New-Object -ComObject Shell.Application
$o.Namespace("$env:USERPROFILE\scoop").Self.InvokeVerb("pintohome")
$o.Namespace("$env:USERPROFILE\bootstrap").Self.InvokeVerb("pintohome") |
This creates a functioning Scoop installation by mounting my local dev repo:
<Configuration>
<MappedFolders>
<MappedFolder>
<HostFolder>.\bootstrap</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\bootstrap</SandboxFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>X:\~projects\~powershell\scoop</HostFolder><!-- Change to local dev directory-->
<SandboxFolder>C:\Users\WDAGUtilityAccount\scoop\apps\scoop\current</SandboxFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
<MappedFolder>
<HostFolder>%USERPROFILE%\scoop\cache</HostFolder>
<SandboxFolder>C:\Users\WDAGUtilityAccount\scoop\cache</SandboxFolder>
<!-- <ReadOnly>true</ReadOnly> -->
</MappedFolder>
</MappedFolders>
<LogonCommand>
<Command>PowerShell Start-Process PowerShell -WindowStyle Maximized -WorkingDirectory 'C:\Users\WDAGUtilityAccount\bootstrap' -ArgumentList '-ExecutionPolicy Bypass -NoLogo -File scoop-dev.ps1'</Command>
</LogonCommand>
</Configuration>
$global:ProgressPreference = 'SilentlyContinue'
# $global:VerbosePreference = 'Continue'
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force -ErrorAction SilentlyContinue
# Pin to Quick Access
$o = New-Object -ComObject Shell.Application
$o.Namespace("$env:USERPROFILE\scoop").Self.InvokeVerb("pintohome")
$o.Namespace("$env:USERPROFILE\bootstrap").Self.InvokeVerb("pintohome")
## Short Scoop Installer
function Install-Scoop() {
$SCOOP_SHIMS_DIR = "$env:USERPROFILE\scoop\shims"
$null = New-Item -Path $SCOOP_SHIMS_DIR -ItemType Directory -ErrorAction SilentlyContinue
$ps1text = @(
"`$path = Join-Path `$PSScriptRoot `"..\apps\scoop\current\bin\scoop.ps1`"",
"if (`$MyInvocation.ExpectingInput) { `$input | & `$path $arg @args } else { & `$path $arg @args }",
"exit `$LASTEXITCODE"
)
[System.IO.File]::WriteAllLines("$SCOOP_SHIMS_DIR\scoop.ps1", $ps1text -join "`r`n")
$userEnvPath = (Get-Item -Path 'HKCU:').OpenSubKey('Environment', $true).GetValue('PATH', $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
& "$($env:SystemRoot)\System32\setx.exe" PATH `""$SCOOP_SHIMS_DIR;$userEnvPath"`" | Out-Null
$env:PATH = "$SCOOP_SHIMS_DIR;$env:PATH"
}
Install-Scoop
## Install git
scoop install --no-update-scoop https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/mingit-busybox.json
## Add buckets
git clone https://github.com/ScoopInstaller/Main "$env:USERPROFILE\scoop\buckets\main" --depth=1
git clone https://github.com/ScoopInstaller/Extras "$env:USERPROFILE\scoop\buckets\extras" --depth=1
## Install default software
scoop config aria2-warning-enabled false
scoop config debug true
scoop install --no-update-scoop main/7zip main/aria2 main/pwsh
# scoop install --no-update-scoop main/innounp main/dark main/lessmsi
## Start test shell
PowerShell Start-Process "$env:USERPROFILE\scoop\apps\pwsh\current\pwsh.exe" -WorkingDirectory ~ |
This script allows one to easily test apps inside a Windows sandbox. I recently used it to test over 20 PRs found at https://github.com/ScoopInstaller/Nonportable/pulls?q=is%3Apr+is%3Aclosed and it works great.
To speed up testing, you can cache the apps the script installs by default:
The script will then copy the files from scoop's local cache to scoop's cache in the sandbox, so scoop doesn't need to download them.
Checklist:
develop
branch.