Backport fixes to maestro-bot scripts

This commit is contained in:
Nate McMaster 2018-05-03 19:25:11 -07:00
parent 9f0c208871
commit 6ea43cb951
No known key found for this signature in database
GPG Key ID: A778D9601BD78810
3 changed files with 38 additions and 21 deletions

View File

@ -7,8 +7,7 @@
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
$BuildXml, $BuildXml,
[switch] [switch]$NoCommit,
$NoCommit,
[string]$GithubUpstreamBranch, [string]$GithubUpstreamBranch,
[string]$GithubEmail, [string]$GithubEmail,
[string]$GithubUsername, [string]$GithubUsername,
@ -68,7 +67,7 @@ try {
$body = CommitUpdatedVersions $updatedVars $dependencies $depsPath $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath
if ($body) { if ($body) {
CreatePR $GithubUpstreamBranch $destinationBranch $body $GithubToken CreatePR "aspnet" $GithubUsername $GithubUpstreamBranch $destinationBranch $body $GithubToken
} }
} }
} }

View File

@ -1,6 +1,7 @@
[CmdletBinding()] [CmdletBinding()]
param( param(
[switch]$NoCommit,
[string]$GithubEmail, [string]$GithubEmail,
[string]$GithubUsername, [string]$GithubUsername,
[string]$GithubToken [string]$GithubToken
@ -22,6 +23,9 @@ $coreFxRepo = "dotnet/corefx"
$coreSetupVersions = "$githubRaw/$versionsRepo/$versionsBranch/build-info/$coreSetupRepo/master/Latest_Packages.txt" $coreSetupVersions = "$githubRaw/$versionsRepo/$versionsBranch/build-info/$coreSetupRepo/master/Latest_Packages.txt"
$tempDir = "$PSScriptRoot/../obj" $tempDir = "$PSScriptRoot/../obj"
mkdir -Path $tempDir -ErrorAction Ignore
$localCoreSetupVersions = "$tempDir/coresetup.packages" $localCoreSetupVersions = "$tempDir/coresetup.packages"
Write-Host "Downloading $coreSetupVersions to $localCoreSetupVersions" Write-Host "Downloading $coreSetupVersions to $localCoreSetupVersions"
Invoke-WebRequest -OutFile $localCoreSetupVersions -Uri $coreSetupVersions Invoke-WebRequest -OutFile $localCoreSetupVersions -Uri $coreSetupVersions
@ -103,21 +107,28 @@ $depsPath = Resolve-Path "$PSScriptRoot/../build/dependencies.props"
Write-Host "Loading deps from $depsPath" Write-Host "Loading deps from $depsPath"
[xml] $dependencies = LoadXml $depsPath [xml] $dependencies = LoadXml $depsPath
$remote = "origin" if (-not $NoCommit) {
$baseBranch = "release/2.1" $baseBranch = "release/2.1"
Invoke-Block { & git fetch origin }
$currentBranch = Invoke-Block { & git rev-parse --abbrev-ref HEAD } $currentBranch = Invoke-Block { & git rev-parse --abbrev-ref HEAD }
$destinationBranch = "rybrande/UpgradeDepsTest" $destinationBranch = "dotnetbot/UpdateCoreFxDeps"
Invoke-Block { & git checkout -tb $destinationBranch "origin/$baseBranch" }
}
Invoke-Block { & git checkout -tb $destinationBranch "$remote/$baseBranch" }
try { try {
$updatedVars = UpdateVersions $variables $dependencies $depsPath $updatedVars = UpdateVersions $variables $dependencies $depsPath
$body = CommitUpdatedVersions $updatedVars $dependencies $depsPath if (-not $NoCommit) {
$body = CommitUpdatedVersions $updatedVars $dependencies $depsPath
if ($body) { if ($body) {
CreatePR $baseBranch $destinationBranch $body $GithubToken CreatePR "aspnet" $GithubUsername $baseBranch $destinationBranch $body $GithubToken
}
} }
} }
finally { finally {
Invoke-Block { & git checkout $currentBranch } if (-not $NoCommit) {
Invoke-Block { & git checkout $currentBranch }
}
} }

View File

@ -15,7 +15,10 @@ function Invoke-Block([scriptblock]$cmd) {
# - $?: did the powershell script block throw an error # - $?: did the powershell script block throw an error
# - $lastexitcode: did a windows command executed by the script block end in error # - $lastexitcode: did a windows command executed by the script block end in error
if ((-not $?) -or ($lastexitcode -ne 0)) { if ((-not $?) -or ($lastexitcode -ne 0)) {
Write-Warning $error[0] if(($error -ne $null))
{
Write-Warning $error[0]
}
throw "Command failed to execute: $cmd" throw "Command failed to execute: $cmd"
} }
} }
@ -121,9 +124,8 @@ function Ensure-Hub() {
if (-Not (Test-Path $hubLocation) ) { if (-Not (Test-Path $hubLocation) ) {
$source = "https://github.com/github/hub/releases/download/v2.3.0-pre9/hub-windows-amd64-2.3.0-pre9.zip" $source = "https://github.com/github/hub/releases/download/v2.3.0-pre9/hub-windows-amd64-2.3.0-pre9.zip"
$zipLocation = "$tmpDir\hub.zip" $zipLocation = "$tmpDir\hub.zip"
if(-not (Test-Path $zipLocation)) {
New-Item -ItemType directory -Path $tmpDir mkdir -Path $tmpDir -ErrorAction Ignore | Out-Null
}
Invoke-WebRequest -OutFile $zipLocation -Uri $source Invoke-WebRequest -OutFile $zipLocation -Uri $source
@ -136,11 +138,17 @@ function Ensure-Hub() {
return $hubLocation return $hubLocation
} }
function CreatePR([string]$baseBranch, [string]$destinationBranch, [string]$body, [string]$gitHubToken) { function CreatePR(
[string]$baseFork,
[string]$headFork,
[string]$baseBranch,
[string]$destinationBranch,
[string]$body,
[string]$gitHubToken) {
$hubLocation = Ensure-Hub $hubLocation = Ensure-Hub
Invoke-Block { git push -f https://$gitHubToken@github.com/aspnet/Universe.git $destinationBranch } Invoke-Block { git push -f https://$gitHubToken@github.com/$headFork/Universe.git $destinationBranch }
& $hubLocation pull-request -f -b $baseBranch -h $destinationBranch -m $body & $hubLocation pull-request -f -b "${baseFork}:$baseBranch" -h "${headFork}:$destinationBranch" -m $body
} }
function Set-GithubInfo( function Set-GithubInfo(
@ -163,8 +171,7 @@ function CommitUpdatedVersions(
$subject = "Updating external dependencies" $subject = "Updating external dependencies"
# Have to pipe null so that the output from this doesn't end up as part of the return value Invoke-Block { & git commit -m $subject } | Out-Null
$null = Invoke-Block { & git commit -m $subject }
$body = "$subject`n`n" $body = "$subject`n`n"