UpdateDependencies.ps1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env pwsh -c
  2. <#
  3. .PARAMETER BuildXml
  4. The URL or file path to a build.xml file that defines package versions to be used
  5. #>
  6. [CmdletBinding()]
  7. param(
  8. [Parameter(Mandatory = $true)]
  9. $BuildXml,
  10. [switch]$NoCommit,
  11. [string]$GithubUpstreamBranch,
  12. [string]$GithubEmail,
  13. [string]$GithubUsername,
  14. [string]$GithubToken
  15. )
  16. $ErrorActionPreference = 'Stop'
  17. Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1"
  18. Set-StrictMode -Version 1
  19. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  20. if (-not $NoCommit) {
  21. Set-GitHubInfo $GithubToken $GithubUsername $GithubEmail
  22. }
  23. $depsPath = Resolve-Path "$PSScriptRoot/../build/dependencies.props"
  24. [xml] $dependencies = LoadXml $depsPath
  25. if ($BuildXml -like 'http*') {
  26. $url = $BuildXml
  27. New-Item -Type Directory "$PSScriptRoot/../obj/" -ErrorAction Ignore
  28. $BuildXml = "$PSScriptRoot/../obj/build.xml"
  29. Write-Verbose "Downloading from $url to $BuildXml"
  30. Invoke-WebRequest -OutFile $BuildXml $url
  31. }
  32. [xml] $remoteDeps = LoadXml $BuildXml
  33. $variables = @{}
  34. foreach ($package in $remoteDeps.SelectNodes('//Package')) {
  35. $packageId = $package.Id
  36. $packageVersion = $package.Version
  37. $varName = PackageIdVarName $packageId
  38. Write-Verbose "Found {id: $packageId, version: $packageVersion, varName: $varName }"
  39. if ($variables[$varName]) {
  40. if ($variables[$varName].Where( {$_ -eq $packageVersion}, 'First').Count -eq 0) {
  41. $variables[$varName] += $packageVersion
  42. }
  43. }
  44. else {
  45. $variables[$varName] = @($packageVersion)
  46. }
  47. }
  48. $currentBranch = Invoke-Block { & git rev-parse --abbrev-ref HEAD }
  49. $destinationBranch = "dotnetbot/UpdateDeps"
  50. Invoke-Block { & git checkout -tb $destinationBranch "origin/$GithubUpstreamBranch" }
  51. try {
  52. $updatedVars = UpdateVersions $variables $dependencies $depsPath
  53. if (-not $NoCommit) {
  54. $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath
  55. if ($body) {
  56. CreatePR "aspnet" $GithubUsername $GithubUpstreamBranch $destinationBranch $body $GithubToken
  57. }
  58. }
  59. }
  60. finally {
  61. Invoke-Block { & git checkout $currentBranch }
  62. }