-
Notifications
You must be signed in to change notification settings - Fork 7k
Expand file tree
/
Copy pathPRTest.ps1
More file actions
75 lines (65 loc) · 3.33 KB
/
PRTest.ps1
File metadata and controls
75 lines (65 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# This script does a checkout of a Pull Request using the GitHub CLI, and then runs it using SandboxTest.ps1.
Param(
[Parameter(Position = 0, HelpMessage = 'The Pull Request to checkout.', Mandatory = $true)]
[String] $PullRequest,
[Parameter(HelpMessage = "Open the Pull Request's review page in the default browser")]
[Switch] $Review = $false,
[Switch] $KeepBranch = $false,
[Switch] $Prerelease = $false,
[Switch] $EnableExperimentalFeatures = $false,
[string] $WinGetVersion = $null,
[string] $WinGetOptions,
[scriptblock] $Script = $null,
[string] $MapFolder = $pwd,
[switch] $Clean
)
# Virtual Terminal
filter Initialize-VirtualTerminalSequence {
# https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
if ($script:vtSupported) {
return "$([char]0x001B)[${_}m"
}
}
# Flags
Write-Debug 'Checking for supported features'
$script:vtSupported = (Get-Host).UI.SupportsVirtualTerminal
$script:GitIsPresent = Get-Command 'git' -ErrorAction SilentlyContinue
$script:GhIsPresent = Get-Command 'gh' -ErrorAction SilentlyContinue
$script:SandboxIsPresent = Get-Command 'WindowsSandbox' -ErrorAction SilentlyContinue
Write-Debug 'Initializing Virtual Terminal Sequences'
$script:vtDefault = 0 | Initialize-VirtualTerminalSequence
$script:vtForegroundGreen = 32 | Initialize-VirtualTerminalSequence
Write-Debug 'Creating internal state'
$PullRequest = $PullRequest.TrimStart('#')
$ErrorActionPreference = 'Stop'
$repositoryRoot = 'https://github.com/microsoft/winget-pkgs/'
$rootDirectory = ((Resolve-Path (git rev-parse --show-toplevel)).ToString() + '\')
Write-Verbose 'Ensuring Dependencies are Present'
if (!$script:GhIsPresent) { Write-Error "The GitHub CLI is not installed. Install it via 'winget install GitHub.cli' and come back here!" -ErrorAction Stop }
if (!$script:GitIsPresent) { Write-Error "Git is not installed. Install it via 'winget install Git.Git' and come back here!" -ErrorAction Stop }
if (!$script:SandboxIsPresent) { Write-Error 'Windows Sandbox is not enabled. Enable it and come back here!' -ErrorAction Stop }
Write-Verbose 'Checking out PR'
gh pr checkout $PullRequest $(if (!$KeepBranch) { '--detach' }) -f -R $repositoryRoot | Out-Null
if ($LASTEXITCODE -ne 0) { Write-Error "There was an error checking out the PR. Make sure you're logged into GitHub via 'gh auth login' and come back here!" -ErrorAction Stop }
Write-Verbose 'Parsing changed files'
$manifest = @(gh pr diff $PullRequest --name-only)
$path = (Get-Item (Resolve-Path ($rootDirectory + $manifest[0]))).Directory
Write-Verbose 'Passing execution to SandboxTest.ps1'
$sandboxTestPath = (Resolve-Path ($PSScriptRoot.ToString() + '\SandboxTest.ps1')).ToString()
$params = @{
Manifest = $path
SkipManifestValidation = $true
Prerelease = $Prerelease
EnableExperimentalFeatures = $EnableExperimentalFeatures
WinGetVersion = $WinGetVersion
WinGetOptions = $WinGetOptions
Script = $Script
MapFolder = $MapFolder
Clean = $Clean
}
& $sandboxTestPath @params
if ($Review) {
Write-Information "${script:vtForegroundGreen}" -InformationAction 'Continue'
& gh pr diff --web $PullRequest
Write-Information "${script:vtDefault}" -InformationAction 'Continue'
}