UpdateRepos.ps1 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. $koreBuildLock = "korebuild-lock.txt"
  66. $universeKoreBuildLock = (Join-Path $RepoRoot $koreBuildLock)
  67. $submoduleKoreBuildLock = (Join-Path $submodule.path $koreBuildLock)
  68. Copy-Item $universeKoreBuildLock $submoduleKoreBuildLock -Force
  69. Write-Verbose "About to update dependencies.props for $($submodule.module)"
  70. & .\run.ps1 upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile
  71. Invoke-Block { & git @gitConfigArgs add $depsFile $koreBuildLock }
  72. Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
  73. $sshUrl = "[email protected]:aspnet/$($submodule.module)"
  74. Invoke-Block { & git remote set-url --push origin $sshUrl }
  75. $updated_submodules += $submodule
  76. }
  77. catch {
  78. Write-Warning "Error in $($submodule.module)"
  79. $update_errors += @{
  80. Repo = $submodule.module
  81. Message = $_
  82. }
  83. }
  84. finally {
  85. Pop-Location
  86. }
  87. }
  88. if ($update_errors.Count -gt 0 ) {
  89. foreach ($update_error in $update_errors) {
  90. if ($update_error -eq $null) {
  91. Write-Error "Error was null."
  92. }
  93. else {
  94. Write-Error "$update_error.Repo error: $update_error.Message"
  95. }
  96. }
  97. throw 'Failed to update'
  98. }
  99. else {
  100. Write-Verbose "All updates successful!"
  101. }
  102. $shortMessage = "Pushing updates to repos."
  103. if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Push the changes to these repos?')))) {
  104. $push_errors = @()
  105. foreach ($submodule in $updated_submodules) {
  106. Push-Location $submodule.path
  107. try {
  108. Invoke-Block { & git @gitConfigArgs push origin HEAD:$submodule.branch}
  109. }
  110. catch {
  111. $push_errors += $_
  112. }
  113. finally {
  114. Pop-Location
  115. }
  116. }
  117. if ($push_errors.Count -gt 0 ) {
  118. throw 'Failed to push'
  119. }
  120. }
  121. }
  122. finally {
  123. Pop-Location
  124. }