UpdateRepos.ps1 4.0 KB

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