Browse Source

Update UpdateDeps script

Ryan Brandenburg 8 years ago
parent
commit
eaefd0be14
2 changed files with 21 additions and 14 deletions
  1. 20 13
      scripts/UpdateDependencies.ps1
  2. 1 1
      scripts/common.psm1

+ 20 - 13
scripts/UpdateDependencies.ps1

@@ -9,7 +9,10 @@ param(
     $BuildXml,
     [switch]
     $NoCommit,
-    [string[]]$ConfigVars = @()
+    [string]$GithubUpstreamBranch,
+    [string]$GithubEmail,
+    [string]$GithubUsername,
+    [string]$GithubToken
 )
 
 $ErrorActionPreference = 'Stop'
@@ -18,11 +21,7 @@ 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
+    Set-GitHubInfo $GithubToken $GithubUsername $GithubEmail
 }
 
 $depsPath = Resolve-Path "$PSScriptRoot/../build/dependencies.props"
@@ -56,15 +55,23 @@ foreach ($package in $remoteDeps.SelectNodes('//Package')) {
     }
 }
 
-$updatedVars = UpdateVersions $variables $dependencies $depsPath
 
-if (-not $NoCommit) {
-    $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath
-    $destinationBranch = "dotnetbot/UpdateDeps"
+$currentBranch = Invoke-Block { & git rev-parse --abbrev-ref HEAD }
+
+$destinationBranch = "dotnetbot/UpdateDeps"
+Invoke-Block { & git checkout -tb $destinationBranch "origin/$GithubUpstreamBranch" }
 
-    $baseBranch = $ConfigVars["GithubUpstreamBranch"]
+try {
+    $updatedVars = UpdateVersions $variables $dependencies $depsPath
 
-    if ($body) {
-        CreatePR $baseBranch $destinationBranch $body $GitHubPassword
+    if (-not $NoCommit) {
+        $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath
+
+        if ($body) {
+            CreatePR $GithubUpstreamBranch $destinationBranch $body $GithubToken
+        }
     }
 }
+finally {
+    Invoke-Block { & git checkout $currentBranch }
+}

+ 1 - 1
scripts/common.psm1

@@ -205,7 +205,7 @@ function UpdateVersions([hashtable]$variables, [xml]$dependencies, [string]$deps
     }
 
     if ($updatedVars.Count -gt 0) {
-        Write-Host -f Cyan "Updating $count version variables in $depsPath"
+        Write-Host -f Cyan "Updating version variables in $depsPath"
         SaveXml $dependencies $depsPath
     }
     else {