Use token instead of ssh

This commit is contained in:
Ryan Brandenburg 2018-04-11 14:56:49 -07:00
parent e8b19889eb
commit f3e599649b
3 changed files with 83 additions and 31 deletions

View File

@ -7,6 +7,8 @@
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
$BuildXml, $BuildXml,
[switch]
$NoCommit,
[string[]]$ConfigVars = @() [string[]]$ConfigVars = @()
) )
@ -15,6 +17,14 @@ Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1"
Set-StrictMode -Version 1 Set-StrictMode -Version 1
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [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" $depsPath = Resolve-Path "$PSScriptRoot/../build/dependencies.props"
[xml] $dependencies = LoadXml $depsPath [xml] $dependencies = LoadXml $depsPath
@ -46,5 +56,15 @@ foreach ($package in $remoteDeps.SelectNodes('//Package')) {
} }
} }
$updatedVars = UpdateVersions $variables $dependencies $updatedVars = UpdateVersions $variables $dependencies $depsPath
CommitUpdatedVersions $updatedVars $dependencies $depsPath
if (-not $NoCommit) {
$body = CommitUpdatedVersions $updatedVars $dependencies $depsPath
$destinationBranch = "dotnetbot/UpdateDeps"
$baseBranch = $ConfigVars["GithubUpstreamBranch"]
if ($body) {
CreatePR $baseBranch $destinationBranch $body $GitHubPassword
}
}

View File

@ -1,6 +1,10 @@
[CmdletBinding()] [CmdletBinding()]
param() param(
[string]$GitHubEmail,
[string]$GitHubUsername,
[string]$GitHubPassword
)
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1" Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1"
@ -24,6 +28,8 @@ Invoke-WebRequest -OutFile $localCoreSetupVersions -Uri $coreSetupVersions
$msNetCoreAppPackageVersion = $null $msNetCoreAppPackageVersion = $null
$msNetCoreAppPackageName = "Microsoft.NETCore.App" $msNetCoreAppPackageName = "Microsoft.NETCore.App"
Set-GitHubInfo $GitHubPassword $GitHubUsername $GitHubEmail
$variables = @{} $variables = @{}
foreach ($line in Get-Content $localCoreSetupVersions) { foreach ($line in Get-Content $localCoreSetupVersions) {
@ -96,5 +102,21 @@ $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
$updatedVars = UpdateVersions $variables $dependencies $depsPath $remote = "origin"
CommitUpdatedVersions $updatedVars $dependencies $depsPath $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 }
}

View File

@ -115,12 +115,16 @@ function PackageIdVarName([string]$packageId) {
function Ensure-Hub() { function Ensure-Hub() {
$tmpDir = "$PSScriptRoot\tmp" $tmpDir = "$PSScriptRoot\tmp"
$zipDir = "$tmpDir\Hub\" $zipDir = "$tmpDir\Hub"
$hubLocation = "$zipDir\bin\hub.exe" $hubLocation = "$zipDir\bin\hub.exe"
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
}
Invoke-WebRequest -OutFile $zipLocation -Uri $source Invoke-WebRequest -OutFile $zipLocation -Uri $source
Expand-Archive -Path $zipLocation -DestinationPath $zipDir -Force Expand-Archive -Path $zipLocation -DestinationPath $zipDir -Force
@ -132,39 +136,45 @@ function Ensure-Hub() {
return $hubLocation 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 $count = $updatedVars.Count
if ($count -gt 0) { if ($count -gt 0) {
$hubLocation = Ensure-Hub & git add build\dependencies.props
$destinationBranch = "rybrande/UpgradeDepsTest" $subject = "Updating external dependencies"
$currentBranch = & git rev-parse --abbrev-ref HEAD
$remote = "origin" # Have to pipe null so that the output from this doesn't end up as part of the return value
$baseBranch = "dev" $null = Invoke-Block { & git commit -m $subject }
Invoke-Block { & git checkout -tb $destinationBranch "$remote/$baseBranch" } $body = "$subject`n`n"
try
{
& git add build\dependencies.props
$subject = "Updating external dependencies" $body += "New versions:`n"
& git commit -m $subject
$body = "$subject`n`n" foreach ($var in $updatedVars.GetEnumerator()) {
$body += " $($var.Name)`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
} }
return $body
} }
} }