UpdateRepos.ps1 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/usr/bin/env pwsh
  2. <#
  3. .SYNOPSIS
  4. Updates each repo Universe builds to new dependencies.props.
  5. .PARAMETER Source
  6. The NuGet package source to find the lineup on.
  7. .PARAMETER LineupID
  8. The ID of the Lineup to determine which versions to use.
  9. .PARAMETER LineupVersion
  10. The version of the Lineup to be used.
  11. .PARAMETER GitAuthorName
  12. The author name to use in the commit message. (Optional)
  13. .PARAMETER GitAuthorEmail
  14. The author email to use in the commit message. (Optional)
  15. .PARAMETER NoPush
  16. Make commits without pusing.
  17. #>
  18. [cmdletbinding(SupportsShouldProcess = $true)]
  19. param(
  20. [Parameter(Mandatory=$true)]
  21. [string]$Source,
  22. [Parameter(Mandatory=$true)]
  23. [string]$LineupID,
  24. [Parameter(Mandatory=$true)]
  25. [string]$LineupVersion,
  26. [switch]$NoPush,
  27. [string[]]$GitCommitArgs = @()
  28. )
  29. $ErrorActionPreference = 'Stop'
  30. Set-StrictMode -Version 2
  31. Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force
  32. $RepoRoot = Resolve-Path "$PSScriptRoot\.."
  33. $ModuleDirectory = Join-Path $RepoRoot "modules"
  34. $gitConfigArgs = @()
  35. if ($GitAuthorName) {
  36. $gitConfigArgs += '-c',"user.name=$GitAuthorName"
  37. }
  38. if ($GitAuthorEmail) {
  39. $gitConfigArgs += '-c',"user.email=$GitAuthorEmail"
  40. }
  41. Push-Location $ModuleDirectory
  42. try {
  43. # Init all submodules
  44. Invoke-Block { & git submodule update --init }
  45. $update_errors = @()
  46. $submodules = Get-Submodules $RepoRoot
  47. $updated_submodules = @()
  48. foreach($submodule in $submodules)
  49. {
  50. Push-Location $submodule.path
  51. try {
  52. $depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props"
  53. if (!Test-Path $depsFile)
  54. {
  55. Write-Warning "No build\dependencies.props file exists for $($submodule.module). "
  56. continue
  57. }
  58. # Move to latest commit on tracked branch
  59. Invoke-Block { & git checkout --quiet $submodule.branch }
  60. Invoke-Block { & .\run.ps1 -Update upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile }
  61. Invoke-Block { & git add $depsFile }
  62. Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
  63. $sshUrl = "[email protected]:aspnet/$($submodule.module)"
  64. Invoke-Block { & git remote set-url --push origin $sshUrl }
  65. $updated_submodules += $submodule
  66. }
  67. catch
  68. {
  69. $update_errors += $_
  70. }
  71. finally {
  72. Pop-Location
  73. }
  74. }
  75. if ($update_errors.Count -gt 0 )
  76. {
  77. throw 'Failed to update'
  78. }
  79. if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Push the changes to these repos?'))))
  80. {
  81. $push_errors = @()
  82. foreach($submodule in $updated_submodules)
  83. {
  84. Push-Location $submodule.path
  85. try {
  86. Invoke-Block { & git @gitConfigArgs push origin $submodule.branch}
  87. }
  88. catch
  89. {
  90. $push_errors += $_
  91. }
  92. finally {
  93. Pop-Location
  94. }
  95. }
  96. if ($push_errors.Count -gt 0 )
  97. {
  98. throw 'Failed to push'
  99. }
  100. }
  101. }
  102. finally {
  103. Pop-Location
  104. }