forked from microsoft/winget-pkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRTest.ps1
60 lines (48 loc) · 2.33 KB
/
PRTest.ps1
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
# This script does a checkout of a Pull Request using the GitHub CLI, and then runs it using SandboxTest.ps1.
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'This script is not intended to have any outputs piped')]
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
)
$PullRequest = $PullRequest.TrimStart('#')
$ErrorActionPreference = 'Stop'
$repositoryRoot = 'https://github.com/microsoft/winget-pkgs/'
$rootDirectory = ((Resolve-Path (git rev-parse --show-toplevel)).ToString() + '\')
if (-Not (Get-Command 'gh' -ErrorAction 'SilentlyContinue')) {
Write-Host "The GitHub CLI is not installed. Install it via 'winget install GitHub.cli' and come back here!" -ForegroundColor Red
return
}
if (-Not (Get-Command 'git' -ErrorAction 'SilentlyContinue')) {
Write-Host "Git is not installed. Install it via 'winget install Git.Git' and come back here!" -ForegroundColor Red
return
}
gh pr checkout $PullRequest $(if (!$KeepBranch) { '--detach' }) -f | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "There was an error checking out the PR. Make sure you're logged into GitHub via 'gh auth login' and come back here!" -ForegroundColor Red
return
}
$manifest = (git diff --name-only HEAD~1..HEAD)
if ($manifest.GetType().Name -eq 'Object[]') {
$path = (Get-Item (Resolve-Path ($rootDirectory + $manifest[0]))).Directory
} else {
$path = (Get-Item (Resolve-Path ($rootDirectory + $manifest))).Directory
}
$sandboxTestPath = (Resolve-Path ($PSScriptRoot.ToString() + '\SandboxTest.ps1')).ToString()
$params = @{
Manifest = $path
SkipManifestValidation = $true
Prerelease = $Prerelease
EnableExperimentalFeatures = $EnableExperimentalFeatures
WinGetVersion = $WinGetVersion
}
& $sandboxTestPath @params
if ($Review) {
Write-Host "Opening $PullRequest in browser..." -ForegroundColor Green
Start-Process ($repositoryRoot + 'pull/' + $PullRequest + '/files')
}