UpdateRepos.ps1 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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]$GitAuthorName = $null,
  28. [string]$GitAuthorEmail = $null,
  29. [string[]]$GitCommitArgs = @()
  30. )
  31. $ErrorActionPreference = 'Stop'
  32. Set-StrictMode -Version 2
  33. Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force
  34. $RepoRoot = Resolve-Path "$PSScriptRoot\.."
  35. $ModuleDirectory = Join-Path $RepoRoot "modules"
  36. $gitConfigArgs = @()
  37. if ($GitAuthorName) {
  38. $gitConfigArgs += '-c',"user.name=$GitAuthorName"
  39. }
  40. if ($GitAuthorEmail) {
  41. $gitConfigArgs += '-c',"user.email=$GitAuthorEmail"
  42. }
  43. Push-Location $ModuleDirectory
  44. try {
  45. # Init all submodules
  46. Invoke-Block { & git submodule update --init }
  47. $update_errors = @()
  48. $submodules = Get-Submodules $RepoRoot
  49. $updated_submodules = @()
  50. foreach($submodule in $submodules)
  51. {
  52. Push-Location $submodule.path
  53. try {
  54. $depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props"
  55. if (!Test-Path $depsFile)
  56. {
  57. Write-Warning "No build\dependencies.props file exists for $($submodule.module). "
  58. continue
  59. }
  60. # Move to latest commit on tracked branch
  61. Invoke-Block { & git checkout --quiet $submodule.branch }
  62. Invoke-Block { & .\run.ps1 -Update upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile }
  63. Invoke-Block { & git add $depsFile }
  64. Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
  65. $sshUrl = "[email protected]:aspnet/$($submodule.module)"
  66. Invoke-Block { & git remote set-url --push origin $sshUrl }
  67. $updated_submodules += $submodule
  68. }
  69. catch
  70. {
  71. $update_errors += $_
  72. }
  73. finally {
  74. Pop-Location
  75. }
  76. }
  77. if ($update_errors.Count -gt 0 )
  78. {
  79. throw 'Failed to update'
  80. }
  81. if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Push the changes to these repos?'))))
  82. {
  83. $push_errors = @()
  84. foreach($submodule in $updated_submodules)
  85. {
  86. Push-Location $submodule.path
  87. try {
  88. Invoke-Block { & git @gitConfigArgs push origin $submodule.branch}
  89. }
  90. catch
  91. {
  92. $push_errors += $_
  93. }
  94. finally {
  95. Pop-Location
  96. }
  97. }
  98. if ($push_errors.Count -gt 0 )
  99. {
  100. throw 'Failed to push'
  101. }
  102. }
  103. }
  104. finally {
  105. Pop-Location
  106. }