PRTest.ps1 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # This script does a checkout of a Pull Request using the GitHub CLI, and then runs it using SandboxTest.ps1.
  2. Param(
  3. [Parameter(Position = 0, HelpMessage = "The Pull Request to checkout.", Mandatory=$true)]
  4. [String] $PullRequest,
  5. [Parameter(HelpMessage = "Open the Pull Request's review page in the default browser")]
  6. [Switch] $Review = $false,
  7. [Switch] $KeepBranch = $false,
  8. [Switch] $Prerelease = $false,
  9. [Switch] $EnableExperimentalFeatures = $false
  10. )
  11. $PullRequest = $PullRequest.TrimStart('#')
  12. $ErrorActionPreference = "Stop"
  13. $repositoryRoot = "https://github.com/microsoft/winget-pkgs/"
  14. $rootDirectory = ((Resolve-Path (git rev-parse --show-toplevel)).ToString() + "\")
  15. if (-Not (Get-Command "gh" -ErrorAction "SilentlyContinue")) {
  16. Write-Host "The GitHub CLI is not installed. Install it via 'winget install gh' and come back here!" -ForegroundColor Red
  17. return
  18. }
  19. if (-Not (Get-Command "git" -ErrorAction "SilentlyContinue")) {
  20. Write-Host "Git is not installed. Install it via 'winget install git' and come back here!" -ForegroundColor Red
  21. return
  22. }
  23. gh pr checkout $PullRequest $(if (!$KeepBranch){'--detach'}) -f | Out-Null
  24. if($LASTEXITCODE -ne 0) {
  25. 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
  26. return
  27. }
  28. $manifest = (git diff --name-only HEAD~1..HEAD)
  29. if ($manifest.GetType().Name -eq "Object[]") {
  30. $path = (Get-Item (Resolve-Path ($rootDirectory + $manifest[0]))).Directory
  31. }
  32. else {
  33. $path = (Get-Item (Resolve-Path ($rootDirectory + $manifest))).Directory
  34. }
  35. $sandboxTestPath = (Resolve-Path ($PSScriptRoot.ToString() + "\SandboxTest.ps1")).ToString()
  36. $params = @{
  37. Manifest = $path
  38. SkipManifestValidation = $true
  39. Prerelease = $Prerelease
  40. EnableExperimentalFeatures = $EnableExperimentalFeatures
  41. }
  42. & $sandboxTestPath @params
  43. if ($Review) {
  44. Write-Host "Opening $PullRequest in browser..." -ForegroundColor Green
  45. Start-Process ($repositoryRoot + "pull/" + $PullRequest + "/files")
  46. }