UpdateRepos.ps1 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 NoPush
  12. Make commits without pusing.
  13. .PARAMETER GitAuthorName
  14. The author name to use in the commit message. (Optional)
  15. .PARAMETER GitAuthorEmail
  16. The author email to use in the commit message. (Optional)
  17. .PARAMETER Force
  18. Specified this to push commits without prompting.
  19. .PARAMETER GitCommitArgs
  20. Any remaining arguments are passed as arguments to 'git commit' actions in each repo.
  21. #>
  22. [cmdletbinding(SupportsShouldProcess = $true)]
  23. param(
  24. [Parameter(Mandatory = $true)]
  25. [string]$Source,
  26. [Parameter(Mandatory = $true)]
  27. [string]$LineupID,
  28. [Parameter(Mandatory = $true)]
  29. [string]$LineupVersion,
  30. [switch]$NoPush,
  31. [string]$GitAuthorName = $null,
  32. [string]$GitAuthorEmail = $null,
  33. [switch]$Force,
  34. [string[]]$GitCommitArgs = @()
  35. )
  36. $ErrorActionPreference = 'Stop'
  37. Set-StrictMode -Version 2
  38. Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force
  39. $RepoRoot = Resolve-Path "$PSScriptRoot\.."
  40. $ModuleDirectory = Join-Path $RepoRoot "modules"
  41. $gitConfigArgs = @()
  42. if ($GitAuthorName) {
  43. $gitConfigArgs += '-c', "user.name=$GitAuthorName"
  44. }
  45. if ($GitAuthorEmail) {
  46. $gitConfigArgs += '-c', "user.email=$GitAuthorEmail"
  47. }
  48. Push-Location $ModuleDirectory
  49. try {
  50. # Init all submodules
  51. Write-Verbose "Updating submodules..."
  52. Invoke-Block { & git submodule update --init } | Out-Null
  53. Write-Verbose "Submodules updated."
  54. $update_errors = @()
  55. $submodules = Get-Submodules $RepoRoot
  56. $updated_submodules = @()
  57. foreach ($submodule in $submodules) {
  58. Push-Location $submodule.path
  59. try {
  60. $depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props"
  61. if (!(Test-Path $depsFile)) {
  62. Write-Warning "No build\dependencies.props file exists for $($submodule.module)."
  63. continue
  64. }
  65. Write-Verbose "About to update dependencies.props for $($submodule.module)"
  66. & .\run.ps1 -Update upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile
  67. Invoke-Block { & git @gitConfigArgs add $depsFile "korebuild-lock.txt" }
  68. Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
  69. $sshUrl = "[email protected]:aspnet/$($submodule.module)"
  70. Invoke-Block { & git remote set-url --push origin $sshUrl }
  71. $updated_submodules += $submodule
  72. }
  73. catch {
  74. Write-Warning "Error in $($submodule.module)"
  75. $update_errors += @{
  76. Repo = $submodule.module
  77. Message = $_
  78. }
  79. }
  80. finally {
  81. Pop-Location
  82. }
  83. }
  84. if ($update_errors.Count -gt 0 ) {
  85. foreach ($update_error in $update_errors) {
  86. if ($update_error -eq $null) {
  87. Write-Error "Error was null."
  88. }
  89. else {
  90. Write-Error "$update_error.Repo error: $update_error.Message"
  91. }
  92. }
  93. throw 'Failed to update'
  94. }
  95. else {
  96. Write-Verbose "All updates successful!"
  97. }
  98. $shortMessage = "Pushing updates to repos."
  99. if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Push the changes to these repos?')))) {
  100. $push_errors = @()
  101. foreach ($submodule in $updated_submodules) {
  102. Push-Location $submodule.path
  103. try {
  104. Invoke-Block { & git @gitConfigArgs push origin HEAD:$submodule.branch}
  105. }
  106. catch {
  107. $push_errors += $_
  108. }
  109. finally {
  110. Pop-Location
  111. }
  112. }
  113. if ($push_errors.Count -gt 0 ) {
  114. throw 'Failed to push'
  115. }
  116. }
  117. }
  118. finally {
  119. Pop-Location
  120. }