diff --git a/scripts/UpdateDependencies.ps1 b/scripts/UpdateDependencies.ps1 index 1c09a9982b..fa733f24bb 100755 --- a/scripts/UpdateDependencies.ps1 +++ b/scripts/UpdateDependencies.ps1 @@ -7,6 +7,8 @@ param( [Parameter(Mandatory = $true)] $BuildXml, + [switch] + $NoCommit, [string[]]$ConfigVars = @() ) @@ -15,6 +17,14 @@ Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1" Set-StrictMode -Version 1 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +if (-not $NoCommit) { + $GitHubEmail = $ConfigVars["GithubEmail"] + $GitHubUsername = $ConfigVars["GithubUsername"] + $GitHubPassword = $ConfigVars["GithubToken"] + + Set-GitHubInfo $GitHubPassword $GitHubUsername $GitHubEmail +} + $depsPath = Resolve-Path "$PSScriptRoot/../build/dependencies.props" [xml] $dependencies = LoadXml $depsPath @@ -46,5 +56,15 @@ foreach ($package in $remoteDeps.SelectNodes('//Package')) { } } -$updatedVars = UpdateVersions $variables $dependencies -CommitUpdatedVersions $updatedVars $dependencies $depsPath +$updatedVars = UpdateVersions $variables $dependencies $depsPath + +if (-not $NoCommit) { + $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath + $destinationBranch = "dotnetbot/UpdateDeps" + + $baseBranch = $ConfigVars["GithubUpstreamBranch"] + + if ($body) { + CreatePR $baseBranch $destinationBranch $body $GitHubPassword + } +} diff --git a/scripts/UpdateDependenciesCoreFx.ps1 b/scripts/UpdateDependenciesCoreFx.ps1 index 762583ddd8..1256092da2 100644 --- a/scripts/UpdateDependenciesCoreFx.ps1 +++ b/scripts/UpdateDependenciesCoreFx.ps1 @@ -1,6 +1,10 @@ [CmdletBinding()] -param() +param( + [string]$GitHubEmail, + [string]$GitHubUsername, + [string]$GitHubPassword +) $ErrorActionPreference = 'Stop' Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1" @@ -24,6 +28,8 @@ Invoke-WebRequest -OutFile $localCoreSetupVersions -Uri $coreSetupVersions $msNetCoreAppPackageVersion = $null $msNetCoreAppPackageName = "Microsoft.NETCore.App" +Set-GitHubInfo $GitHubPassword $GitHubUsername $GitHubEmail + $variables = @{} foreach ($line in Get-Content $localCoreSetupVersions) { @@ -96,5 +102,21 @@ $depsPath = Resolve-Path "$PSScriptRoot/../build/dependencies.props" Write-Host "Loading deps from $depsPath" [xml] $dependencies = LoadXml $depsPath -$updatedVars = UpdateVersions $variables $dependencies $depsPath -CommitUpdatedVersions $updatedVars $dependencies $depsPath +$remote = "origin" +$baseBranch = "dev" + +$currentBranch = Invoke-Block { & git rev-parse --abbrev-ref HEAD } +$destinationBranch = "rybrande/UpgradeDepsTest" + +Invoke-Block { & git checkout -tb $destinationBranch "$remote/$baseBranch" } +try { + $updatedVars = UpdateVersions $variables $dependencies $depsPath + $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath + + if ($body) { + CreatePR $baseBranch $destinationBranch $body $GitHubPassword + } +} +finally { + Invoke-Block { & git checkout $currentBranch } +} diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 4272ccb7a5..b621d48193 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -115,12 +115,16 @@ function PackageIdVarName([string]$packageId) { function Ensure-Hub() { $tmpDir = "$PSScriptRoot\tmp" - $zipDir = "$tmpDir\Hub\" + $zipDir = "$tmpDir\Hub" $hubLocation = "$zipDir\bin\hub.exe" 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" $zipLocation = "$tmpDir\hub.zip" + if(-not (Test-Path $zipLocation)) { + New-Item -ItemType directory -Path $tmpDir + } + Invoke-WebRequest -OutFile $zipLocation -Uri $source Expand-Archive -Path $zipLocation -DestinationPath $zipDir -Force @@ -132,39 +136,45 @@ function Ensure-Hub() { return $hubLocation } -function CommitUpdatedVersions([hashtable]$updatedVars, [xml]$dependencies, [string]$depsPath) { +function CreatePR([string]$baseBranch, [string]$destinationBranch, [string]$body, [string]$gitHubToken) { + $hubLocation = Ensure-Hub + + Invoke-Block { git push -f https://$gitHubToken@github.com/aspnet/Universe.git $destinationBranch } + & $hubLocation pull-request -f -b $baseBranch -h $destinationBranch -m $body +} + +function Set-GithubInfo( + [string]$GitHubPassword, + [string]$GitHubUser, + [string]$GitHubEmail) +{ + $Env:GITHUB_TOKEN = $GitHubPassword + $Env:GITHUB_USER = $GitHubUser + $Env:GITHUB_EMAIL = $GitHubEmail +} +function CommitUpdatedVersions( + [hashtable]$updatedVars, + [xml]$dependencies, + [string]$depsPath) +{ $count = $updatedVars.Count if ($count -gt 0) { - $hubLocation = Ensure-Hub + & git add build\dependencies.props - $destinationBranch = "rybrande/UpgradeDepsTest" - $currentBranch = & git rev-parse --abbrev-ref HEAD + $subject = "Updating external dependencies" - $remote = "origin" - $baseBranch = "dev" + # Have to pipe null so that the output from this doesn't end up as part of the return value + $null = Invoke-Block { & git commit -m $subject } - Invoke-Block { & git checkout -tb $destinationBranch "$remote/$baseBranch" } - try - { - & git add build\dependencies.props + $body = "$subject`n`n" - $subject = "Updating external dependencies" - & git commit -m $subject + $body += "New versions:`n" - $body = "$subject`n`n" - - $body += "New versions:`n" - - foreach ($var in $updatedVars.GetEnumerator()) { - $body += " $($var.Name)`n" - } - Invoke-Block { & git push -f origin $destinationBranch } - - Invoke-Block { & $hubLocation pull-request -b $baseBranch -h $destinationBranch -m $body } - } - finally{ - & git checkout $currentBranch + foreach ($var in $updatedVars.GetEnumerator()) { + $body += " $($var.Name)`n" } + + return $body } }