UpdateDependencies.ps1 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. if (-not $NoCommit) {
  49. $currentBranch = Invoke-Block { & git rev-parse --abbrev-ref HEAD }
  50. $destinationBranch = "dotnetbot/UpdateDeps"
  51. Invoke-Block { & git checkout -tb $destinationBranch "origin/$GithubUpstreamBranch" }
  52. }
  53. try {
  54. $updatedVars = UpdateVersions $variables $dependencies $depsPath
  55. if ($NoCommit) {
  56. exit 0
  57. }
  58. $body = CommitUpdatedVersions $updatedVars $dependencies $depsPath
  59. if ($body) {
  60. CreatePR "aspnet" $GithubUsername $GithubUpstreamBranch $destinationBranch $body $GithubToken
  61. }
  62. }
  63. finally {
  64. if (-not $NoCommit) {
  65. Invoke-Block { & git checkout $currentBranch }
  66. }
  67. }