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(
[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
}
}

View File

@ -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 }
}

View File

@ -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
}
}